Disable ormolu for hakyll DSL-y code; only bring in a stylesheet if we have one

main
Robert Pearce 2020-11-02 12:28:23 -05:00
parent 9244c2e20f
commit 8cec937b86
No known key found for this signature in database
GPG Key ID: 07A0E482E5616C9B
9 changed files with 70 additions and 56 deletions

View File

@ -8,9 +8,8 @@
1. Click the "Use this template" button and create your repository 1. Click the "Use this template" button and create your repository
1. Renaming 1. Renaming
1. Rename all instances of `hakyll-nix-template` and `my-site` with a name for 1. Rename all instances of `hakyll-nix-template` with the name of your project
your project 1. Rename `generator/hakyll-nix-template.cabal` to reflect your project name
1. Rename `generator/my-site.cabal` to reflect your project name
1. Cachix 1. Cachix
1. Create a cachix cache for your project on https://app.cachix.org 1. Create a cachix cache for your project on https://app.cachix.org
1. Follow the cachix instructions to generate a signing keypair 1. Follow the cachix instructions to generate a signing keypair
@ -23,9 +22,9 @@
1. To start an environment for running hakyll commands like `hakyll-site watch` 1. To start an environment for running hakyll commands like `hakyll-site watch`
(the dev server) and `hakyll-site build`: `cd generator && nix-shell`. You'll (the dev server) and `hakyll-site build`: `cd generator && nix-shell`. You'll
then have access to the `hakyll-site` executable defined in then have access to the `hakyll-site` executable defined in
`generator/my-site.cabal`. While you can do `nix-shell` in the root and then `generator/hakyll-nix-template.cabal`. While you can do `nix-shell` in the
`cd generator && hakyll-site watch`, you get some more tools if you root and then `cd generator && hakyll-site watch`, you get some more tools if
`nix-shell` from within the `generator/` folder. you `nix-shell` from within the `generator/` folder.
1. Once you're satisfied, create a branch, push your project up there, and check 1. Once you're satisfied, create a branch, push your project up there, and check
that the GitHub Actions successfully build. If so, you're good to merge your that the GitHub Actions successfully build. If so, you're good to merge your
project with your main branch. project with your main branch.

View File

@ -1,26 +1,26 @@
let let
cfg = import ./nix/default.nix {}; cfg = import ./nix/default.nix { };
in in
{ pkgs ? cfg.pkgs }: { pkgs ? cfg.pkgs }:
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "my-site"; name = "hakyll-nix-template";
buildInputs = [ buildInputs = [
cfg.generator cfg.generator
]; ];
src = cfg.src; src = cfg.src;
# https://github.com/jaspervdj/hakyll/issues/614 # https://github.com/jaspervdj/hakyll/issues/614
# https://github.com/NixOS/nix/issues/318#issuecomment-52986702 # https://github.com/NixOS/nix/issues/318#issuecomment-52986702
# https://github.com/MaxDaten/brutal-recipes/blob/source/default.nix#L24 # https://github.com/MaxDaten/brutal-recipes/blob/source/default.nix#L24
LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.buildPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive"; LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.buildPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8"; LANG = "en_US.UTF-8";
buildPhase = '' buildPhase = ''
hakyll-site build hakyll-site build
''; '';
installPhase = '' installPhase = ''
mkdir -p "$out/dist" mkdir -p "$out/dist"
cp -r ../dist/* "$out/dist" cp -r ../dist/* "$out/dist"
''; '';
} }

View File

@ -1,3 +1,3 @@
{ pkgs }: { pkgs }:
(pkgs.callPackage ./hpkgs.nix {}).my-site (pkgs.callPackage ./hpkgs.nix { }).hakyll-nix-template

View File

@ -1,6 +1,6 @@
cabal-version: 2.4 cabal-version: 2.4
name: my-site name: hakyll-nix-template
version: 0.1.0.0 version: 0.1.0.0
build-type: Simple build-type: Simple
license: BSD-3-Clause license: BSD-3-Clause

View File

@ -1,7 +1,6 @@
{ compiler ? "ghc884" { compiler ? "ghc884"
, pkgs , pkgs
}: }:
let let
inherit (pkgs.lib.trivial) flip pipe; inherit (pkgs.lib.trivial) flip pipe;
inherit (pkgs.haskell.lib) appendPatch appendConfigureFlags dontCheck; inherit (pkgs.haskell.lib) appendPatch appendConfigureFlags dontCheck;
@ -18,13 +17,15 @@ let
(flip appendConfigureFlags hakyllFlags) (flip appendConfigureFlags hakyllFlags)
]; ];
my-site = hpNew.callCabal2nix "my-site" ./. {}; hakyll-nix-template = hpNew.callCabal2nix "hakyll-nix-template" ./. { };
# because hakyll is marked as broken in nixpkgs # when hakyll is marked as broken in nixpkgs
hslua = dontCheck (hpNew.callHackage "hslua" "1.0.3.2" {}); # because of version issues, fix them here:
jira-wiki-markup = dontCheck (hpNew.callHackage "jira-wiki-markup" "1.1.4" {});
pandoc = dontCheck (hpNew.callHackage "pandoc" "2.9.2.1" {}); hslua = dontCheck (hpNew.callHackage "hslua" "1.0.3.2" { });
pandoc-types = dontCheck (hpNew.callHackage "pandoc-types" "1.20" {}); jira-wiki-markup = dontCheck (hpNew.callHackage "jira-wiki-markup" "1.1.4" { });
pandoc = dontCheck (hpNew.callHackage "pandoc" "2.9.2.1" { });
pandoc-types = dontCheck (hpNew.callHackage "pandoc-types" "1.20" { });
}; };
}; };
in in

View File

@ -1,21 +1,21 @@
let let
cfg = import ../nix/default.nix {}; cfg = import ../nix/default.nix { };
hp = cfg.haskellPackages; hp = cfg.haskellPackages;
in in
{}: {}:
hp.shellFor { hp.shellFor {
packages = p: [ packages = p: [
p.my-site p.hakyll-nix-template
]; ];
buildInputs = with hp; [ buildInputs = with hp; [
cabal-install cabal-install
ghcid ghcid
hlint hlint
hp.my-site hp.hakyll-nix-template
ormolu ormolu
]; ];
withHoogle = true; withHoogle = true;
} }

View File

@ -40,6 +40,8 @@ config =
-- BUILD -- BUILD
{- ORMOLU_DISABLE -}
main :: IO () main :: IO ()
main = hakyllWith config $ do main = hakyllWith config $ do
forM_ forM_
@ -57,6 +59,7 @@ main = hakyllWith config $ do
match "css/*" $ do match "css/*" $ do
route idRoute route idRoute
compile compressCssCompiler compile compressCssCompiler
match "posts/*" $ do match "posts/*" $ do
let ctx = constField "type" "article" <> postCtx let ctx = constField "type" "article" <> postCtx
route $ metadataRoute titleRoute route $ metadataRoute titleRoute
@ -65,6 +68,7 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/post.html" ctx >>= loadAndApplyTemplate "templates/post.html" ctx
>>= saveSnapshot "content" >>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" ctx >>= loadAndApplyTemplate "templates/default.html" ctx
match "index.html" $ do match "index.html" $ do
route idRoute route idRoute
compile $ do compile $ do
@ -77,7 +81,10 @@ main = hakyllWith config $ do
getResourceBody getResourceBody
>>= applyAsTemplate indexCtx >>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx >>= loadAndApplyTemplate "templates/default.html" indexCtx
match "templates/*" $ compile templateBodyCompiler
match "templates/*" $
compile templateBodyCompiler
create ["sitemap.xml"] $ do create ["sitemap.xml"] $ do
route idRoute route idRoute
compile $ do compile $ do
@ -89,13 +96,17 @@ main = hakyllWith config $ do
<> listField "pages" postCtx (return pages) <> listField "pages" postCtx (return pages)
makeItem ("" :: String) makeItem ("" :: String)
>>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx
create ["rss.xml"] $ do create ["rss.xml"] $ do
route idRoute route idRoute
compile (feedCompiler renderRss) compile (feedCompiler renderRss)
create ["atom.xml"] $ do create ["atom.xml"] $ do
route idRoute route idRoute
compile (feedCompiler renderAtom) compile (feedCompiler renderAtom)
{- ORMOLU_ENABLE -}
-- CONTEXT -- CONTEXT
feedCtx :: Context String feedCtx :: Context String

View File

@ -5,10 +5,10 @@
"homepage": "https://github.com/nmattia/niv", "homepage": "https://github.com/nmattia/niv",
"owner": "nmattia", "owner": "nmattia",
"repo": "niv", "repo": "niv",
"rev": "9d35b9e4837ab88517210b1701127612c260eccf", "rev": "20c899271f288d33114760bc298838575fc6c7f9",
"sha256": "0q50xhnm8g2yfyakrh0nly4swyygxpi0a8cb9gp65wcakcgvzvdh", "sha256": "07zswk6dhlydihl9g6skmy52grjvqpra8r98f2dmbgwzc1yhjhxq",
"type": "tarball", "type": "tarball",
"url": "https://github.com/nmattia/niv/archive/9d35b9e4837ab88517210b1701127612c260eccf.tar.gz", "url": "https://github.com/nmattia/niv/archive/20c899271f288d33114760bc298838575fc6c7f9.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"nixpkgs": { "nixpkgs": {
@ -29,10 +29,10 @@
"homepage": "", "homepage": "",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "efdbd6d28f7f44db3d9f8cf0e0b4cb9db0d259e1", "rev": "117579f3cfe4c0abeff70631fa31261d5ea99cfd",
"sha256": "1qngfbp1bqn52ipf992vrj4vp1cvvcv2yvzp0fs9yawqjxzk4j5m", "sha256": "1bjvadx76rlf54b43agfx1w35wqpagzihdv2yy0jsrk1glxc15ax",
"type": "tarball", "type": "tarball",
"url": "https://github.com/cachix/pre-commit-hooks.nix/archive/efdbd6d28f7f44db3d9f8cf0e0b4cb9db0d259e1.tar.gz", "url": "https://github.com/cachix/pre-commit-hooks.nix/archive/117579f3cfe4c0abeff70631fa31261d5ea99cfd.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
} }
} }

View File

@ -39,7 +39,10 @@
<link rel="shortcut icon" href="/favicon.ico"> <link rel="shortcut icon" href="/favicon.ico">
<link rel="canonical" href="$root$$url$"> <link rel="canonical" href="$root$$url$">
<link rel="stylesheet" href="./css/default.css" />
$if(stylesheet)$
<link rel="stylesheet" href="./css/$stylesheet$.css" /> <link rel="stylesheet" href="./css/$stylesheet$.css" />
$endif$
</head> </head>
<body> <body>
$body$ $body$