rauhala.info/site.hs

81 lines
2.7 KiB
Haskell
Raw Normal View History

2018-09-20 20:58:27 +03:00
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
2018-09-20 21:57:49 +03:00
import Data.List (sortBy, sortOn)
import Data.Time (formatTime, defaultTimeLocale)
2018-09-20 20:58:27 +03:00
--------------------------------------------------------------------------------
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
2018-09-20 21:57:49 +03:00
match "posts/guides/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
2018-09-20 20:58:27 +03:00
2018-09-20 21:57:49 +03:00
match "posts/brainstorming/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
2018-09-20 20:58:27 +03:00
2018-09-20 21:57:49 +03:00
create ["guides.html"] $ do
route idRoute
compile $ do
posts <- modFirst =<< loadAll "posts/guides/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
2018-09-20 22:01:03 +03:00
constField "title" "Guides" `mappend`
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 =
dateField "date" "%B %e, %Y" `mappend`
2018-09-20 21:57:49 +03:00
modifiedField "modified" "%B %e, %Y" `mappend`
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