From 8cec937b86968e74dca621d75b7255da8e601aad Mon Sep 17 00:00:00 2001 From: Robert Pearce Date: Mon, 2 Nov 2020 12:28:23 -0500 Subject: [PATCH] Disable ormolu for hakyll DSL-y code; only bring in a stylesheet if we have one --- README.md | 11 +++-- default.nix | 40 +++++++++---------- generator/default.nix | 2 +- ...y-site.cabal => hakyll-nix-template.cabal} | 2 +- generator/hpkgs.nix | 15 +++---- generator/shell.nix | 28 ++++++------- generator/src/Main.hs | 13 +++++- nix/sources.json | 12 +++--- src/templates/default.html | 3 ++ 9 files changed, 70 insertions(+), 56 deletions(-) rename generator/{my-site.cabal => hakyll-nix-template.cabal} (92%) diff --git a/README.md b/README.md index 1145b41..4145ed0 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,8 @@ 1. Click the "Use this template" button and create your repository 1. Renaming - 1. Rename all instances of `hakyll-nix-template` and `my-site` with a name for - your project - 1. Rename `generator/my-site.cabal` to reflect your project name + 1. Rename all instances of `hakyll-nix-template` with the name of your project + 1. Rename `generator/hakyll-nix-template.cabal` to reflect your project name 1. Cachix 1. Create a cachix cache for your project on https://app.cachix.org 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` (the dev server) and `hakyll-site build`: `cd generator && nix-shell`. You'll 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 - `cd generator && hakyll-site watch`, you get some more tools if you - `nix-shell` from within the `generator/` folder. + `generator/hakyll-nix-template.cabal`. While you can do `nix-shell` in the + root and then `cd generator && hakyll-site watch`, you get some more tools if + you `nix-shell` from within the `generator/` folder. 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 project with your main branch. diff --git a/default.nix b/default.nix index dda5d72..3ffa4ca 100644 --- a/default.nix +++ b/default.nix @@ -1,26 +1,26 @@ let - cfg = import ./nix/default.nix {}; + cfg = import ./nix/default.nix { }; in { pkgs ? cfg.pkgs }: - pkgs.stdenv.mkDerivation { - name = "my-site"; - buildInputs = [ - cfg.generator - ]; - src = cfg.src; +pkgs.stdenv.mkDerivation { + name = "hakyll-nix-template"; + buildInputs = [ + cfg.generator + ]; + src = cfg.src; - # https://github.com/jaspervdj/hakyll/issues/614 - # https://github.com/NixOS/nix/issues/318#issuecomment-52986702 - # 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"; - LANG = "en_US.UTF-8"; + # https://github.com/jaspervdj/hakyll/issues/614 + # https://github.com/NixOS/nix/issues/318#issuecomment-52986702 + # 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"; + LANG = "en_US.UTF-8"; - buildPhase = '' - hakyll-site build - ''; - installPhase = '' - mkdir -p "$out/dist" - cp -r ../dist/* "$out/dist" - ''; - } + buildPhase = '' + hakyll-site build + ''; + installPhase = '' + mkdir -p "$out/dist" + cp -r ../dist/* "$out/dist" + ''; +} diff --git a/generator/default.nix b/generator/default.nix index f61076f..b5449a4 100644 --- a/generator/default.nix +++ b/generator/default.nix @@ -1,3 +1,3 @@ { pkgs }: -(pkgs.callPackage ./hpkgs.nix {}).my-site +(pkgs.callPackage ./hpkgs.nix { }).hakyll-nix-template diff --git a/generator/my-site.cabal b/generator/hakyll-nix-template.cabal similarity index 92% rename from generator/my-site.cabal rename to generator/hakyll-nix-template.cabal index 43710d2..fbb6db5 100644 --- a/generator/my-site.cabal +++ b/generator/hakyll-nix-template.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 -name: my-site +name: hakyll-nix-template version: 0.1.0.0 build-type: Simple license: BSD-3-Clause diff --git a/generator/hpkgs.nix b/generator/hpkgs.nix index ee1f778..002e4ca 100644 --- a/generator/hpkgs.nix +++ b/generator/hpkgs.nix @@ -1,7 +1,6 @@ { compiler ? "ghc884" , pkgs }: - let inherit (pkgs.lib.trivial) flip pipe; inherit (pkgs.haskell.lib) appendPatch appendConfigureFlags dontCheck; @@ -18,13 +17,15 @@ let (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 - hslua = dontCheck (hpNew.callHackage "hslua" "1.0.3.2" {}); - 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" {}); + # when hakyll is marked as broken in nixpkgs + # because of version issues, fix them here: + + hslua = dontCheck (hpNew.callHackage "hslua" "1.0.3.2" { }); + 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 diff --git a/generator/shell.nix b/generator/shell.nix index 4c8c288..8ae2168 100644 --- a/generator/shell.nix +++ b/generator/shell.nix @@ -1,21 +1,21 @@ let - cfg = import ../nix/default.nix {}; + cfg = import ../nix/default.nix { }; hp = cfg.haskellPackages; in {}: - hp.shellFor { - packages = p: [ - p.my-site - ]; +hp.shellFor { + packages = p: [ + p.hakyll-nix-template + ]; - buildInputs = with hp; [ - cabal-install - ghcid - hlint - hp.my-site - ormolu - ]; + buildInputs = with hp; [ + cabal-install + ghcid + hlint + hp.hakyll-nix-template + ormolu + ]; - withHoogle = true; - } + withHoogle = true; +} diff --git a/generator/src/Main.hs b/generator/src/Main.hs index e58d472..d72da72 100644 --- a/generator/src/Main.hs +++ b/generator/src/Main.hs @@ -40,6 +40,8 @@ config = -- BUILD +{- ORMOLU_DISABLE -} + main :: IO () main = hakyllWith config $ do forM_ @@ -57,6 +59,7 @@ main = hakyllWith config $ do match "css/*" $ do route idRoute compile compressCssCompiler + match "posts/*" $ do let ctx = constField "type" "article" <> postCtx route $ metadataRoute titleRoute @@ -65,6 +68,7 @@ main = hakyllWith config $ do >>= loadAndApplyTemplate "templates/post.html" ctx >>= saveSnapshot "content" >>= loadAndApplyTemplate "templates/default.html" ctx + match "index.html" $ do route idRoute compile $ do @@ -77,7 +81,10 @@ main = hakyllWith config $ do getResourceBody >>= applyAsTemplate indexCtx >>= loadAndApplyTemplate "templates/default.html" indexCtx - match "templates/*" $ compile templateBodyCompiler + + match "templates/*" $ + compile templateBodyCompiler + create ["sitemap.xml"] $ do route idRoute compile $ do @@ -89,13 +96,17 @@ main = hakyllWith config $ do <> listField "pages" postCtx (return pages) makeItem ("" :: String) >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx + create ["rss.xml"] $ do route idRoute compile (feedCompiler renderRss) + create ["atom.xml"] $ do route idRoute compile (feedCompiler renderAtom) +{- ORMOLU_ENABLE -} + -- CONTEXT feedCtx :: Context String diff --git a/nix/sources.json b/nix/sources.json index 85e87d6..0ec4488 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "9d35b9e4837ab88517210b1701127612c260eccf", - "sha256": "0q50xhnm8g2yfyakrh0nly4swyygxpi0a8cb9gp65wcakcgvzvdh", + "rev": "20c899271f288d33114760bc298838575fc6c7f9", + "sha256": "07zswk6dhlydihl9g6skmy52grjvqpra8r98f2dmbgwzc1yhjhxq", "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///archive/.tar.gz" }, "nixpkgs": { @@ -29,10 +29,10 @@ "homepage": "", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "efdbd6d28f7f44db3d9f8cf0e0b4cb9db0d259e1", - "sha256": "1qngfbp1bqn52ipf992vrj4vp1cvvcv2yvzp0fs9yawqjxzk4j5m", + "rev": "117579f3cfe4c0abeff70631fa31261d5ea99cfd", + "sha256": "1bjvadx76rlf54b43agfx1w35wqpagzihdv2yy0jsrk1glxc15ax", "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///archive/.tar.gz" } } diff --git a/src/templates/default.html b/src/templates/default.html index 0fea8c3..414b9d9 100644 --- a/src/templates/default.html +++ b/src/templates/default.html @@ -39,7 +39,10 @@ + + $if(stylesheet)$ + $endif$ $body$