summaryrefslogtreecommitdiff
path: root/site.hs
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2015-08-17 21:06:06 +0200
committerrekado <rekado@elephly.net>2015-08-17 22:56:03 +0200
commit89752ab353c9a4872f264b9c9ccdf871d0115b17 (patch)
tree627eb217634e1901c605879af8d4dd794a8d5b8d /site.hs
parentb074fa8551a7717c8d20cdf9206627756a5e0887 (diff)
Goodbye Hakyll, hello Haunt!
Diffstat (limited to 'site.hs')
-rw-r--r--site.hs180
1 files changed, 0 insertions, 180 deletions
diff --git a/site.hs b/site.hs
deleted file mode 100644
index f854817..0000000
--- a/site.hs
+++ /dev/null
@@ -1,180 +0,0 @@
---------------------------------------------------------------------------------
-{-# LANGUAGE OverloadedStrings #-}
-import Control.Applicative ((<$>))
-import Data.Monoid ((<>))
-import Hakyll
-import Data.Map as M
-import qualified Data.Set as S
-import Data.Maybe (fromMaybe)
-import Text.Pandoc.Options
-
-config :: Configuration
-config = defaultConfiguration
- { deployCommand =
- "rsync -Havz _site/ rekado@elephly.net:/home/rekado/elephly.net" }
-
-myFeedConfiguration :: FeedConfiguration
-myFeedConfiguration = FeedConfiguration
- { feedTitle = "Rekado's website"
- , feedDescription = "Music, words, and hacking"
- , feedAuthorName = "Rekado"
- , feedAuthorEmail = "rekado+feed@elephly.net"
- , feedRoot = "http://elephly.net"
- }
-
---------------------------------------------------------------------------------
-main :: IO ()
-main = hakyllWith config $ do
- tags <- buildTags "posts/*.markdown" (fromCapture "tags/*.html")
-
- match ( "js/libs/*"
- .||. "js/hyphenator/*"
- .||. "js/hyphenator/patterns/*"
- .||. "js/*"
- .||. "css/*.woff"
- .||. "downies/*"
- .||. "downies/music/*"
- .||. "images/*"
- .||. "images/posts/*"
- .||. "images/posts/*/*"
- .||. "favicon.ico"
- .||. "rekado.pubkey"
- ) $ do
- route idRoute
- compile copyFileCompiler
-
- match "css/*" $ do
- route idRoute
- compile compressCssCompiler
-
- -- place static markdown files in site root
- match ( "static/*.markdown" .||. "static/*/*.markdown" ) $ do
- route $ setExtension "html"
- `composeRoutes` gsubRoute "static/" (const "")
- compile $ pandocCompiler
- >>= loadAndApplyTemplate "templates/default.html" defaultContext
- >>= relativizeUrls
-
- -- place static html files in site root
- match "static/*.html" $ do
- route $ gsubRoute "static/" (const "")
- compile $ do
- getResourceBody
- >>= loadAndApplyTemplate "templates/default.html" defaultContext
- >>= relativizeUrls
-
- match "posts/*.markdown" $ do
- route $ setExtension "html"
- compile defaultCompiler
-
- -- direct links
- match "posts/2010-03-28-elephly.markdown" $ version "direct" $ do
- route $ constRoute "elephly.html"
- compile defaultCompiler
-
- match "posts/2010-03-23-fur-man.markdown" $ version "direct" $ do
- route $ constRoute "fur-man.html"
- compile defaultCompiler
-
- -- blog post archive
- create ["posts/index.html"] $ do
- let title = "Archive"
-
- route idRoute
- compile $ do
- let archiveCtx =
- constField "title" title <>
- field "posts" (\_ -> postList "posts/*.markdown" recentFirst) <>
- field "tags" (\_ -> renderTagList tags) <>
- defaultContext
-
- makeItem ""
- >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
- >>= loadAndApplyTemplate "templates/default.html" archiveCtx
- >>= relativizeUrls
-
- create ["rss.xml"] $ postFeed renderRss
- create ["atom.xml"] $ postFeed renderAtom
-
- -- always show the most recent blog post
- create ["posts/latest.html"] $ do
- route idRoute
- compile $ do
- mostRecent <- fmap head . recentFirst =<< loadAllSnapshots "posts/*.markdown" "non-relative"
- makeItem (itemBody mostRecent) >>= relativizeUrls
-
-
- tagsRules tags $ \tag pattern -> do
- let title = "Posts tagged &ldquo;" ++ tag ++ "&rdquo;"
-
- route idRoute
- compile $ do
- let ctx = constField "title" title <>
- field "posts" (\_ -> postList pattern recentFirst) <>
- tagsField "tags" tags <>
- defaultContext
-
- makeItem ""
- >>= loadAndApplyTemplate "templates/archive.html" ctx
- >>= loadAndApplyTemplate "templates/default.html" ctx
- >>= relativizeUrls
-
- match "templates/*" $ compile templateCompiler
-
-
---------------------------------------------------------------------------------
-postCtx :: Context String
-postCtx = dateField "date" "%B %e, %Y"
- <> photoSnippet
- <> flattrSnippet
- <> licenseSnippet
- <> defaultContext
-
--- If a post declares a certain key in the metadata header,
--- load the given template, otherwise ignore.
-snippet :: String -> String -> Identifier -> Context String
-snippet name key templatePath = field name $ \item -> do
- metadata <- getMetadata (itemIdentifier item)
- case M.lookup key metadata of
- Just file -> itemBody <$> loadAndApplyTemplate templatePath postCtx item
- _ -> return ""
-
-photoSnippet = snippet "photo-snippet" "photo" "templates/photo.html"
-flattrSnippet = snippet "flattr-snippet" "flattr" "templates/flattr.html"
-licenseSnippet = snippet "license-snippet" "license" "templates/license.html"
-
-postFeed renderer = do
- route idRoute
- compile $ do
- let feedCtx = postCtx <> bodyField "description"
- posts <- fmap (take 10) . recentFirst =<<
- loadAllSnapshots "posts/*.markdown" "content"
- renderer myFeedConfiguration feedCtx posts
-
---------------------------------------------------------------------------------
-postList :: Pattern -> ([Item String] -> Compiler [Item String]) -> Compiler String
-postList pattern sortFilter = do
- posts <- sortFilter =<< loadAll (pattern .&&. hasNoVersion)
- itemTpl <- loadBody "templates/post-item.html"
- list <- applyTemplateList itemTpl postCtx posts
- return list
-
-customPandocCompiler :: Compiler (Item String)
-customPandocCompiler =
- pandocCompilerWith
- (addRExt [Ext_pipe_tables] defaultHakyllReaderOptions)
- (addWExt [Ext_pipe_tables] defaultHakyllWriterOptions)
- where
- addRExt es opts =
- opts { readerExtensions = S.union (S.fromList es) (readerExtensions opts)
- , readerSmart = True
- }
- addWExt es opts =
- opts { writerExtensions = S.union (S.fromList es) (writerExtensions opts) }
-
-defaultCompiler = customPandocCompiler
- >>= loadAndApplyTemplate "templates/post.html" postCtx
- >>= saveSnapshot "content"
- >>= loadAndApplyTemplate "templates/default.html" postCtx
- >>= saveSnapshot "non-relative"
- >>= relativizeUrls