Set up posts again

This commit is contained in:
Mats Rauhala 2021-01-25 20:35:41 +02:00
parent 7e290bee2f
commit 7056ca822c
7 changed files with 31 additions and 10 deletions

View File

@ -16,6 +16,8 @@
<nav>
<!-- Git logo from https://git-scm.com/downloads/logos -->
<!-- Logo by Jason Long -->
<a href="/">Home</a>
<a href="/posts.html">Posts</a>
<a href="https://git.rauhala.info"><img src="/images/git_16.png" alt="git" /></a>
<a href="/contact.html">Contact</a>
</nav>

View File

@ -1,3 +0,0 @@
A list of small and big guides.
$partial("templates/post-list.html")$

View File

@ -1,7 +1,7 @@
<ul>
$for(posts)$
<li>
<a href="$url$">$title$</a> - $modified$
<a href="$url$">$title$</a> - $date$
</li>
$endfor$
</ul>

View File

@ -1,9 +1,6 @@
<article>
<section class="header">
Posted on $date$, modified on $modified$
$if(author)$
by $author$
$endif$
Posted on $date$
</section>
<section>
$body$

View File

@ -32,16 +32,40 @@ main = hakyllWith defaultConfiguration{ignoreFile = ignore} $ do
route idRoute
compile compressCssCompiler
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
match (fromList ["index.markdown", "contact.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
create ["posts.html"] $ do
route idRoute
compile $ do
let postsContext =
listField "posts" postContext posts
<> constField "title" "Posts"
<> defaultContext
posts = recentFirst =<< loadAll "posts/*"
makeItem ""
>>= loadAndApplyTemplate "templates/post-list.html" postsContext
>>= loadAndApplyTemplate "templates/default.html" postsContext
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
where
postContext :: Context String
postContext = dateField "date" "%B %e, %Y" <> defaultContext
ignore :: FilePath -> Bool
ignore path = any ($ takeFileName path)
[ ("." `isPrefixOf`)
, ("#" `isPrefixOf`)

View File

@ -1,10 +1,10 @@
{ mkDerivation, base, hakyll, stdenv, time }:
{ mkDerivation, base, filepath, hakyll, stdenv, time }:
mkDerivation {
pname = "site";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base hakyll time ];
executableHaskellDepends = [ base filepath hakyll time ];
license = stdenv.lib.licenses.bsd3;
}

View File

@ -13,5 +13,6 @@ executable site
build-depends: base == 4.*
, hakyll >= 4.10
, time
, filepath
ghc-options: -threaded
default-language: Haskell2010