99 lines
3.4 KiB
Haskell
99 lines
3.4 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Main where
|
|
|
|
import Prelude hiding (id)
|
|
import Control.Arrow ((>>>), (***), arr)
|
|
import Control.Category (id)
|
|
import Data.Monoid (mempty, mconcat)
|
|
|
|
import Hakyll
|
|
|
|
main :: IO ()
|
|
main = hakyll $ do
|
|
-- Compress CSS
|
|
match "css/*" $ do
|
|
route idRoute
|
|
compile compressCssCompiler
|
|
|
|
-- Render posts
|
|
match "posts/*" $ do
|
|
route $ setExtension ".html"
|
|
compile $ pageCompiler
|
|
>>> arr (renderDateField "date" "%B %e, %Y" "Date unknown")
|
|
>>> renderTagsField "prettytags" (fromCapture "tags/*")
|
|
>>> applyTemplateCompiler "templates/post.html"
|
|
>>> applyTemplateCompiler "templates/default.html"
|
|
>>> relativizeUrlsCompiler
|
|
|
|
-- Render posts list
|
|
match "posts.html" $ route idRoute
|
|
create "posts.html" $ constA mempty
|
|
>>> arr (setField "title" "All posts")
|
|
>>> requireAllA "posts/*" addPostList
|
|
>>> applyTemplateCompiler "templates/posts.html"
|
|
>>> applyTemplateCompiler "templates/default.html"
|
|
>>> relativizeUrlsCompiler
|
|
|
|
-- Index
|
|
match "index.html" $ route idRoute
|
|
create "index.html" $ constA mempty
|
|
>>> arr (setField "title" "Home")
|
|
>>> requireA "tags" (setFieldA "tagcloud" (renderTagCloud'))
|
|
>>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
|
|
>>> applyTemplateCompiler "templates/index.html"
|
|
>>> applyTemplateCompiler "templates/default.html"
|
|
>>> relativizeUrlsCompiler
|
|
|
|
-- Tags
|
|
create "tags" $
|
|
requireAll "posts/*" (\_ ps -> readTags ps :: Tags String)
|
|
|
|
-- Add a tag list compiler for every tag
|
|
match "tags/*" $ route $ setExtension ".html"
|
|
metaCompile $ require_ "tags"
|
|
>>> arr tagsMap
|
|
>>> arr (map (\(t, p) -> (tagIdentifier t, makeTagList t p)))
|
|
|
|
-- Render RSS feed
|
|
match "rss.xml" $ route idRoute
|
|
create "rss.xml" $
|
|
requireAll_ "posts/*"
|
|
>>> mapCompiler (arr $ copyBodyToField "description")
|
|
>>> renderRss feedConfiguration
|
|
|
|
-- Read templates
|
|
match "templates/*" $ compile templateCompiler
|
|
where
|
|
renderTagCloud' :: Compiler (Tags String) String
|
|
renderTagCloud' = renderTagCloud tagIdentifier 100 120
|
|
|
|
tagIdentifier :: String -> Identifier
|
|
tagIdentifier = fromCapture "tags/*"
|
|
|
|
-- | Auxiliary compiler: generate a post list from a list of given posts, and
|
|
-- add it to the current page under @$posts@
|
|
--
|
|
addPostList :: Compiler (Page String, [Page String]) (Page String)
|
|
addPostList = setFieldA "posts" $
|
|
arr (reverse . sortByBaseName)
|
|
>>> require "templates/postitem.html" (\p t -> map (applyTemplate t) p)
|
|
>>> arr mconcat
|
|
>>> arr pageBody
|
|
|
|
makeTagList :: String
|
|
-> [Page String]
|
|
-> Compiler () (Page String)
|
|
makeTagList tag posts =
|
|
constA (mempty, posts)
|
|
>>> addPostList
|
|
>>> arr (setField "title" ("Posts tagged ‘" ++ tag ++ "’"))
|
|
>>> applyTemplateCompiler "templates/posts.html"
|
|
>>> applyTemplateCompiler "templates/default.html"
|
|
|
|
feedConfiguration :: FeedConfiguration
|
|
feedConfiguration = FeedConfiguration
|
|
{ feedTitle = "SimpleBlog RSS feed."
|
|
, feedDescription = "A simple demo of an RSS feed created with Hakyll."
|
|
, feedAuthorName = "Jasper Van der Jeugt"
|
|
, feedRoot = "http://example.com"
|
|
}
|