2018-08-18 07:24:54 -04:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2018-08-18 21:17:10 -04:00
|
|
|
import Data.Monoid ((<>))
|
2018-08-18 07:24:54 -04:00
|
|
|
import Data.List (sortBy,isSuffixOf)
|
|
|
|
import GHC.IO.Encoding
|
2018-08-22 21:14:11 -04:00
|
|
|
import Hakyll
|
|
|
|
import Hakyll.Favicon (faviconsRules, faviconsField)
|
|
|
|
import System.FilePath.Posix (takeBaseName,takeDirectory,(</>))
|
2018-08-18 07:24:54 -04:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
setLocaleEncoding utf8
|
|
|
|
hakyll $ do
|
2018-08-22 21:14:11 -04:00
|
|
|
faviconsRules "icons/favicon.svg"
|
2018-08-18 07:24:54 -04:00
|
|
|
match "humans.txt" $ do
|
|
|
|
route idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
|
|
|
match "css/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile compressCssCompiler
|
|
|
|
|
2018-08-23 00:07:19 -04:00
|
|
|
match "fonts/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
2018-08-18 07:24:54 -04:00
|
|
|
match (fromList ["about.md", "contact.md"]) $ do
|
|
|
|
route $ cleanRoute
|
|
|
|
compile $ pandocCompiler
|
2018-08-18 21:17:10 -04:00
|
|
|
>>= loadAndApplyTemplate "templates/default.html" ctx
|
2018-08-18 07:24:54 -04:00
|
|
|
>>= relativizeUrls
|
|
|
|
>>= cleanIndexUrls
|
|
|
|
|
|
|
|
match "archive.md" $ do
|
|
|
|
route $ cleanRoute
|
|
|
|
compile $ pandocCompiler
|
2018-08-18 21:17:10 -04:00
|
|
|
>>= loadAndApplyTemplate "templates/archive.html" ctx
|
2018-08-18 07:24:54 -04:00
|
|
|
>>= relativizeUrls
|
|
|
|
>>= cleanIndexUrls
|
|
|
|
|
|
|
|
compile $ do
|
|
|
|
posts <- recentFirst =<< loadAll "posts/*"
|
|
|
|
let archiveCtx =
|
2018-08-18 21:17:10 -04:00
|
|
|
listField "posts" postCtx (return posts) <>
|
|
|
|
ctx
|
2018-08-18 07:24:54 -04:00
|
|
|
pandocCompiler
|
|
|
|
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
|
|
|
|
>>= relativizeUrls
|
|
|
|
>>= cleanIndexUrls
|
|
|
|
|
|
|
|
match "posts/*" $ do
|
|
|
|
route $ cleanRoute
|
|
|
|
compile $ pandocCompiler
|
|
|
|
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
2018-08-22 21:49:50 -04:00
|
|
|
>>= saveSnapshot "content"
|
2018-08-18 07:24:54 -04:00
|
|
|
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
|
|
|
>>= relativizeUrls
|
|
|
|
>>= cleanIndexUrls
|
|
|
|
>>= cleanIndexHtmls
|
|
|
|
|
|
|
|
match "index.html" $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
posts <- recentFirst =<< loadAll "posts/*"
|
|
|
|
let indexCtx =
|
2018-08-22 21:14:11 -04:00
|
|
|
listField "posts" postCtx (return posts) <> ctx
|
2018-08-18 07:24:54 -04:00
|
|
|
getResourceBody
|
|
|
|
>>= applyAsTemplate indexCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" indexCtx
|
|
|
|
>>= relativizeUrls
|
|
|
|
>>= cleanIndexUrls
|
|
|
|
>>= cleanIndexHtmls
|
|
|
|
|
|
|
|
match "templates/*" $ compile templateBodyCompiler
|
|
|
|
|
2018-08-22 21:49:50 -04:00
|
|
|
create ["atom.xml"] $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
let feedCtx = postCtx <>
|
|
|
|
bodyField "description"
|
|
|
|
posts <- fmap (take 10) . recentFirst
|
|
|
|
=<< loadAllSnapshots "posts/*" "content"
|
|
|
|
renderAtom feedConfig feedCtx posts
|
|
|
|
|
|
|
|
create ["rss.xml"] $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
let feedCtx = postCtx <>
|
|
|
|
bodyField "description"
|
|
|
|
posts <- fmap (take 10) . recentFirst
|
|
|
|
=<< loadAllSnapshots "posts/*" "content"
|
|
|
|
renderRss feedConfig feedCtx posts
|
|
|
|
|
2018-08-18 21:17:10 -04:00
|
|
|
ctx :: Context String
|
2018-08-22 21:14:11 -04:00
|
|
|
ctx = defaultContext <>
|
|
|
|
faviconsField
|
2018-08-18 21:17:10 -04:00
|
|
|
|
2018-08-18 07:24:54 -04:00
|
|
|
postCtx :: Context String
|
|
|
|
postCtx =
|
2018-08-18 21:17:10 -04:00
|
|
|
(dateField "date" "%B %e, %Y") <> ctx
|
2018-08-18 07:24:54 -04:00
|
|
|
|
|
|
|
cleanRoute :: Routes
|
|
|
|
cleanRoute = customRoute createIndexRoute
|
|
|
|
where
|
|
|
|
createIndexRoute ident =
|
|
|
|
takeDirectory p </> takeBaseName p </> "index.html"
|
|
|
|
where p = toFilePath ident
|
|
|
|
|
|
|
|
cleanIndexUrls :: Item String -> Compiler (Item String)
|
|
|
|
cleanIndexUrls = return . fmap (withUrls cleanIndex)
|
|
|
|
|
|
|
|
cleanIndexHtmls :: Item String -> Compiler (Item String)
|
|
|
|
cleanIndexHtmls = return . fmap (replaceAll pattern replacement)
|
|
|
|
where
|
|
|
|
pattern = "/index.html"
|
|
|
|
replacement = const "/"
|
|
|
|
|
|
|
|
cleanIndex :: String -> String
|
|
|
|
cleanIndex url
|
|
|
|
| idx `isSuffixOf` url = take (length url - length idx) url
|
|
|
|
| otherwise = url
|
|
|
|
where idx = "index.html"
|
2018-08-22 21:49:50 -04:00
|
|
|
|
|
|
|
feedConfig :: FeedConfiguration
|
|
|
|
feedConfig = FeedConfiguration {
|
|
|
|
feedTitle = "Regular Flolloping"
|
|
|
|
, feedDescription = "tA's Blog"
|
|
|
|
, feedAuthorName = "Shaun Kerr"
|
|
|
|
, feedAuthorEmail = "s@p7.co.nz"
|
|
|
|
, feedRoot = "https://regularflolloping.com"
|
|
|
|
}
|