rauhala.info/site.hs

72 lines
2.3 KiB
Haskell
Raw Normal View History

2018-09-20 20:58:27 +03:00
{-# LANGUAGE OverloadedStrings #-}
2019-03-27 21:39:43 +02:00
import Data.List (sortOn)
import Data.Time (defaultTimeLocale, formatTime)
2018-09-20 20:58:27 +03:00
import Hakyll
--------------------------------------------------------------------------------
main :: IO ()
2018-09-20 23:15:22 +03:00
main = hakyllWith defaultConfiguration{ deployCommand = "ipfs add -Q -r _site" } $do
2018-09-20 20:58:27 +03:00
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "resources/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
2018-09-20 22:23:57 +03:00
match "js/*" $ do
route idRoute
compile compressCssCompiler
2018-09-20 22:54:59 +03:00
match (fromList ["index.markdown", "contact.markdown"]) $ do
2018-09-20 20:58:27 +03:00
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
2019-03-27 21:39:43 +02:00
match "posts/*" $ do
2018-09-20 21:57:49 +03:00
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
2018-09-20 20:58:27 +03:00
2019-03-27 21:39:43 +02:00
create ["posts.html"] $ do
2018-09-20 21:57:49 +03:00
route idRoute
compile $ do
2019-03-27 21:39:43 +02:00
posts <- modFirst =<< loadAll "posts/*"
2018-09-20 21:57:49 +03:00
let archiveCtx =
2019-03-27 21:39:43 +02:00
listField "posts" postCtx (return posts) <>
constField "title" "Posts" <>
2018-09-20 21:57:49 +03:00
defaultContext
makeItem ""
2018-09-20 22:01:03 +03:00
>>= loadAndApplyTemplate "templates/guides.html" archiveCtx
2018-09-20 21:57:49 +03:00
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
2018-09-20 20:58:27 +03:00
match "templates/*" $ compile templateBodyCompiler
2018-09-20 21:57:49 +03:00
modFirst :: [Item a] -> Compiler [Item a]
modFirst = fmap reverse . modified
where
modified = sortByM (getItemModificationTime . itemIdentifier)
sortByM f xs = map fst . sortOn snd <$> mapM (\x -> (,) x <$> f x) xs
2018-09-20 20:58:27 +03:00
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
2019-03-27 21:39:43 +02:00
dateField "date" "%B %e, %Y" <>
modifiedField "modified" "%B %e, %Y" <>
2018-09-20 20:58:27 +03:00
defaultContext
2018-09-20 21:57:49 +03:00
where
modifiedField key format = field key $ \i -> do
time <- getItemModificationTime $ itemIdentifier i
return $ formatTime defaultTimeLocale format time