1
0

172 lines
5.7 KiB
Haskell

--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad (filterM)
import Data.Maybe (fromMaybe)
import Data.Monoid (mappend)
import Data.Time
import Hakyll
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "images/**" $ do
route idRoute
compile copyFileCompiler
match "lib/**" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match (fromList ["about.rst", "contact.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" staticPageContext
>>= relativizeUrls
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "events/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/event.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "pages/en/plamo/**" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend`
constField "language" "en" `mappend`
langDict "en" <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
create ["plamo.html"] $ do
route idRoute
compile $ do
kits <- recentFirst =<< loadAll "pages/en/plamo/**"
let plamoCtx =
listField "kits" postCtx (return kits) `mappend`
constField "title" "Plamo" `mappend`
constField "logosub" "Plamo enthousiast" `mappend`
constField "language" "en" `mappend`
langDict "en" <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/plamo.html" plamoCtx
>>= loadAndApplyTemplate "templates/default.html" plamoCtx
>>= relativizeUrls
match (fromList
[ "index.html"
, "en/index.html"
, "nl/index.html"
, "jp/index.html"
]) $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
now <- unsafeCompiler getCurrentTime
ident <- getUnderlying
language <- getMetadataField' ident "language"
let cutoff = addUTCTime (7 * 24 * 60 * 60) now
events <-
loadAll "events/*"
>>= filterM (isUpcoming cutoff)
>>= chronological
let indexCtx =
-- (<> is the modern version of `mappend`.)
listField "posts" postCtx (return posts) <>
listField "events" postCtx (return events) <>
langDict language <>
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
--------------------------------------------------------------------------------
staticPageContext :: Context String
staticPageContext =
langDict "en" <>
defaultContext
postCtx :: Context String
postCtx =
dateField "date" "%e %B %Y" `mappend`
constField "language" "en" `mappend`
langDict "en" <>
defaultContext
isUpcoming :: UTCTime -> Item a -> Compiler Bool
isUpcoming cutoff item = do
metadata <- getMetadata (itemIdentifier item)
case lookupString "date" metadata of
Nothing -> return False
Just ds ->
case parseTimeM True defaultTimeLocale "%Y-%m-%d" ds of
Nothing -> return False
Just date -> return (date >= cutoff)
langDict :: String -> Context a
langDict "nl" =
constField "welcome" "Welkom" <>
constField "switcher" "Taal" <>
constField "title-japan" "Japan" <>
constField "title-plamo" "Plamo" <>
constField "title-radio" "Radio" <>
constField "title-software" "Software" <>
mempty
langDict "jp" =
constField "welcome" "ようこそ" <>
constField "switcher" "言語" <>
constField "title-japan" "日本" <>
constField "title-plamo" "プラモ" <>
constField "title-radio" "ラジオ" <>
constField "title-software" "ソフトウェア" <>
mempty
langDict "en" =
constField "welcome" "Welcome" <>
constField "switcher" "Language" <>
constField "title-japan" "Japan" <>
constField "title-plamo" "Plamo" <>
constField "title-radio" "Radio" <>
constField "title-software" "Software" <>
mempty
langDict _ = mempty