From 1a08821a024cd09b361937b32d0498f21583d7e5 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 24 Jan 2020 13:15:34 -0300 Subject: Add pastebins.html listing page --- default.nix | 6 +----- hakyll/Main.hs | 27 ++++++++++++++++++++++++--- site/pastebins.html | 5 +++++ site/templates/pastebin-list.html | 7 +++++++ site/templates/pastebin.html | 8 ++++++++ site/templates/post.html | 3 --- 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 site/pastebins.html create mode 100644 site/templates/pastebin-list.html create mode 100644 site/templates/pastebin.html diff --git a/default.nix b/default.nix index 4ff2220..414e233 100644 --- a/default.nix +++ b/default.nix @@ -65,15 +65,11 @@ in rec { docs = utils.baseTask.overrideAttrs (baseAttrs: { name = "${baseAttrs.name}-docs"; src = ./site; - buildInputs = [ websiteBuilder pkgs.pandoc ]; + buildInputs = [ websiteBuilder ]; buildPhase = '' export LOCALE_ARCHIVE="${pkgs.glibcLocales}/lib/locale/locale-archive"; export LANG=en_US.UTF-8 - - ls pastebin/*.org | awk -F. '{print $1}' | xargs -I{} pandoc -o {}.html {}.org --standalone - build-site build - mkdir $out cp -r _site/* $out ''; diff --git a/hakyll/Main.hs b/hakyll/Main.hs index 6d27c66..139b607 100644 --- a/hakyll/Main.hs +++ b/hakyll/Main.hs @@ -20,13 +20,18 @@ main = hakyll $ do match "fonts/*" $ do route idRoute compile copyFileCompiler - match "pastebin/*.html" $ do - route idRoute - compile copyFileCompiler match "root/*" $ do route $ dropPrefix "root/" compile copyFileCompiler + match "pastebin/*" $ do + route $ setExtension "html" + compile $ pandocCompiler + >>= loadAndApplyTemplate "templates/pastebin.html" pastebinCtx + >>= saveSnapshot "content" + >>= loadAndApplyTemplate "templates/default.html" pastebinCtx + >>= relativizeUrls + match "posts/*" $ do route $ setExtension "html" `composeRoutes` dropPrefix "posts/" @@ -44,6 +49,19 @@ main = hakyll $ do >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls + match "pastebins.html" $ do + route idRoute + compile $ do + pastebins <- recentFirst =<< loadAll "pastebin/*" + let pastebinCtx = + listField "pastebins" pastebinCtx (return pastebins) `mappend` + defaultContext + + getResourceBody + >>= applyAsTemplate pastebinCtx + >>= loadAndApplyTemplate "templates/default.html" pastebinCtx + >>= relativizeUrls + match "index.html" $ do route idRoute compile $ do @@ -96,6 +114,9 @@ postCtx = dateField "date" "%B %e, %Y" `mappend` defaultContext +pastebinCtx :: Context String +pastebinCtx = postCtx + feedCtx :: Context String feedCtx = bodyField "description" `mappend` diff --git a/site/pastebins.html b/site/pastebins.html new file mode 100644 index 0000000..0afa928 --- /dev/null +++ b/site/pastebins.html @@ -0,0 +1,5 @@ +--- +title: Pastebins listing +--- + +$partial("templates/pastebin-list.html")$ diff --git a/site/templates/pastebin-list.html b/site/templates/pastebin-list.html new file mode 100644 index 0000000..4c98c80 --- /dev/null +++ b/site/templates/pastebin-list.html @@ -0,0 +1,7 @@ + diff --git a/site/templates/pastebin.html b/site/templates/pastebin.html new file mode 100644 index 0000000..7aa2775 --- /dev/null +++ b/site/templates/pastebin.html @@ -0,0 +1,8 @@ +
+
+ Posted on $date$ +
+
+ $body$ +
+
diff --git a/site/templates/post.html b/site/templates/post.html index 428ebff..7aa2775 100644 --- a/site/templates/post.html +++ b/site/templates/post.html @@ -1,9 +1,6 @@
Posted on $date$ - $if(author)$ - by $author$ - $endif$
$body$ -- cgit v1.2.3