hledger/site/site.hs

60 lines
1.9 KiB
Haskell
Raw Normal View History

2010-05-17 18:33:05 +04:00
#!/usr/bin/env runhaskell
2011-08-28 22:03:20 +04:00
{-# LANGUAGE OverloadedStrings #-}
2013-09-16 02:00:40 +04:00
import Control.Applicative ((<$>))
2013-03-10 01:13:21 +04:00
import Control.Monad
import Data.List
2013-09-16 02:00:40 +04:00
import Data.Monoid (mappend)
import Hakyll
2013-03-10 01:13:21 +04:00
import System.Directory
import System.Process
import Text.Pandoc.Options
import Text.Printf
2010-05-17 18:33:05 +04:00
2011-08-28 22:03:20 +04:00
main = do
-- preview doesn't detect changes in symlinked files
2011-08-28 22:03:20 +04:00
symlinkPagesFromParentDir
-- copyPagesFromParentDir
2011-08-28 22:03:20 +04:00
symlinkProfsDir
hakyll $ do
2013-03-10 01:13:21 +04:00
match ("images/*" .||. "js/**" .||. "robots.txt") $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "templates/*" $ compile templateCompiler
match ("README.md") $ do
route $ constRoute "index.html"
compile $
pandocCompilerWith def def
>>= loadAndApplyTemplate "templates/frontpage.html" defaultContext
>>= relativizeUrls
2013-12-14 07:24:46 +04:00
match (("*.md" .&&. complement "README.md") .||. "0.22/*.md" .||. "0.21/*.md" .||. "0.20/*.md" .||. "0.19/*.md" .||. "0.18/*.md") $ do
2013-03-10 01:13:21 +04:00
route $ setExtension "html"
compile $
pandocCompilerWith
def
def{writerTableOfContents=True
,writerTOCDepth=5
2013-03-10 01:13:21 +04:00
,writerStandalone=True
,writerTemplate="<div id=toc>$toc$</div>\n$body$"
}
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
2011-08-28 22:03:20 +04:00
symlinkPagesFromParentDir = do
filter (".md" `isSuffixOf`) `fmap` getDirectoryContents ".."
>>= mapM_ (\f -> system $ printf "[ -f %s ] || ln -s ../%s" f f)
copyPagesFromParentDir = do
2011-08-28 22:03:20 +04:00
fs <- filter (".md" `isSuffixOf`) `fmap` getDirectoryContents ".."
forM_ fs $ \f -> system $ printf "cp ../%s ." f
2013-03-10 01:13:21 +04:00
symlinkProfsDir = ensureSiteDir >> system "ln -sf ../../profs _site/profs"
2011-08-28 22:03:20 +04:00
2013-03-10 01:13:21 +04:00
ensureSiteDir = system "mkdir -p _site"
2013-06-08 04:00:04 +04:00
2013-06-08 04:02:03 +04:00