rauhala.info/site/app/site.hs

108 lines
3.0 KiB
Haskell
Raw Permalink Normal View History

2018-09-20 20:58:27 +03:00
{-# LANGUAGE OverloadedStrings #-}
2021-01-25 21:11:14 +02:00
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
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 21:11:14 +02:00
match "projects/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/project.html" postContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
2021-01-25 20:35:41 +02:00
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 21:11:14 +02:00
archive $ Archive { output = "posts.html"
, input = "posts/*"
, title = "Posts"
, template = "templates/post-list.html"
, context = postContext
}
2018-09-20 20:58:27 +03:00
2021-01-25 21:11:14 +02:00
archive $ Archive { output = "projects.html"
, input = "projects/*"
, title = "Projects"
, template = "templates/project-list.html"
, context = postContext
}
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 21:11:14 +02:00
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
2021-01-25 21:11:14 +02:00
data Archive
= Archive { output :: Identifier
, input :: Pattern
, title :: String
, template :: Identifier
, context :: Context String
}
archive :: Archive -> Rules ()
archive Archive{..} = create [output] $ do
route idRoute
compile $ do
let itemsContext =
listField "items" context items
<> constField "title" title
<> defaultContext
items = recentFirst =<< loadAll input
makeItem ""
>>= loadAndApplyTemplate template itemsContext
>>= loadAndApplyTemplate "templates/default.html" itemsContext
>>= relativizeUrls
2020-02-01 22:25:52 +02:00
prepend :: a -> [a] -> [a]
prepend = (:)