rauhala.info/site/app/site.hs

79 lines
2.1 KiB
Haskell
Raw Normal View History

2018-09-20 20:58:27 +03:00
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
2021-01-25 19:29:45 +02:00
import Hakyll
import Data.List
2021-01-25 19:35:21 +02:00
(isPrefixOf, isSuffixOf)
import System.FilePath
(takeFileName)
2018-09-20 20:58:27 +03:00
--------------------------------------------------------------------------------
main :: IO ()
2021-01-25 19:35:21 +02:00
main = hakyllWith defaultConfiguration{ignoreFile = ignore} $ do
2021-01-25 19:29:45 +02:00
match "well-known/*" $ do
route (customRoute (prepend '.'. toFilePath))
compile copyFileCompiler
2020-02-01 22:25:52 +02:00
2021-01-25 19:29:45 +02:00
match "images/*" $ do
route idRoute
compile copyFileCompiler
2018-09-20 20:58:27 +03:00
2021-01-25 19:29:45 +02:00
match "resources/*" $ do
route idRoute
compile copyFileCompiler
2018-09-20 20:58:27 +03:00
2021-01-25 19:29:45 +02:00
match "css/*" $ do
route idRoute
compile compressCssCompiler
2018-09-20 20:58:27 +03:00
2021-01-25 19:29:45 +02:00
match "js/*" $ do
route idRoute
compile compressCssCompiler
2018-09-20 22:23:57 +03:00
2021-01-25 20:35:41 +02:00
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
2021-01-25 19:29:45 +02:00
match (fromList ["index.markdown", "contact.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
2018-09-20 20:58:27 +03:00
2021-01-25 20:35:41 +02:00
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
2018-09-20 20:58:27 +03:00
2021-01-25 19:29:45 +02:00
match "templates/*" $ compile templateBodyCompiler
2021-01-25 19:35:21 +02:00
where
2021-01-25 20:35:41 +02:00
postContext :: Context String
postContext = dateField "date" "%B %e, %Y" <> defaultContext
ignore :: FilePath -> Bool
2021-01-25 19:35:21 +02:00
ignore path = any ($ takeFileName path)
[ ("." `isPrefixOf`)
, ("#" `isPrefixOf`)
, ("~" `isSuffixOf`)
, (".swp" `isSuffixOf`)
]
2018-09-20 20:58:27 +03:00
2020-02-01 22:25:52 +02:00
prepend :: a -> [a] -> [a]
prepend = (:)