rauhala.info/site.hs

61 lines
1.8 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 ()
2020-02-01 22:25:52 +02:00
main = hakyllWith defaultConfiguration $ do
match "well-known/*" $ do
route (customRoute (prepend '.'. toFilePath))
compile copyFileCompiler
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
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
2020-02-01 22:25:52 +02:00
prepend :: a -> [a] -> [a]
prepend = (:)