hakyll/web/site.hs

121 lines
4.2 KiB
Haskell
Raw Normal View History

2012-12-05 15:54:57 +00:00
--------------------------------------------------------------------------------
2011-02-12 14:16:42 +00:00
{-# LANGUAGE OverloadedStrings #-}
2012-12-29 15:24:27 +00:00
import Control.Applicative ((<$>))
import Control.Arrow (second)
import Control.Monad (forM_)
2013-01-13 11:36:45 +00:00
import Data.Char (isDigit)
import Data.List (isPrefixOf, partition, sortBy)
2012-12-29 15:24:27 +00:00
import Data.Monoid (mappend)
import Data.Ord (comparing)
2012-12-05 15:54:57 +00:00
import Hakyll
2012-12-29 15:24:27 +00:00
import System.FilePath (dropTrailingPathSeparator, splitPath)
2012-12-05 15:54:57 +00:00
import Text.Pandoc
2010-01-02 19:47:52 +00:00
2012-12-05 15:54:57 +00:00
--------------------------------------------------------------------------------
2011-02-12 14:16:42 +00:00
main :: IO ()
2011-06-16 09:51:55 +00:00
main = hakyllWith config $ do
match "css/*" $ do
route idRoute
compile compressCssCompiler
2011-02-12 14:16:42 +00:00
-- Static directories
2012-12-29 15:24:27 +00:00
forM_ ["images/*", "examples/*"] $ \f -> match f $ do
route idRoute
compile copyFileCompiler
-- Haddock stuff
match "reference/**.html" $ do
route idRoute
compile $ fmap (withUrls hackage) <$> getResourceString
-- Haddock stuff
match ("reference/**" `mappend` complement "**.html") $ do
route idRoute
compile copyFileCompiler
2010-01-02 19:47:52 +00:00
2011-02-12 14:16:42 +00:00
-- Pages
2012-12-05 15:54:57 +00:00
match "*.markdown" $ do
route $ setExtension "html"
2012-12-16 09:05:21 +00:00
compile $ pandocCompiler
2012-12-14 09:42:30 +00:00
>>= loadAndApplyTemplate "templates/default.html" defaultContext
2012-12-05 15:54:57 +00:00
>>= relativizeUrls
2011-06-13 16:26:04 +00:00
-- Tutorials
match "tutorials/*" $ do
route $ setExtension "html"
2013-02-24 09:57:18 +00:00
compile $ pandocCompilerWith defaultHakyllReaderOptions withToc
2012-12-14 09:42:30 +00:00
>>= loadAndApplyTemplate "templates/tutorial.html" defaultContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
2012-12-05 15:54:57 +00:00
>>= relativizeUrls
2011-06-13 16:26:04 +00:00
-- Tutorial list
2013-01-06 08:51:09 +00:00
create ["tutorials.html"] $ do
2012-12-05 15:54:57 +00:00
route idRoute
compile $ do
2012-12-14 09:42:30 +00:00
tutorials <- loadAll "tutorials/*"
itemTpl <- loadBody "templates/tutorial-item.html"
let (series, articles) = partitionTutorials $
sortBy (comparing itemIdentifier) tutorials
series' <- applyTemplateList itemTpl defaultContext series
articles' <- applyTemplateList itemTpl defaultContext articles
2012-12-05 15:54:57 +00:00
let tutorialsCtx =
constField "title" "Tutorials" `mappend`
constField "series" series' `mappend`
constField "articles" articles' `mappend`
2012-12-05 15:54:57 +00:00
defaultContext
2011-06-13 16:26:04 +00:00
2012-12-05 15:54:57 +00:00
makeItem ""
2012-12-14 09:42:30 +00:00
>>= loadAndApplyTemplate "templates/tutorials.html" tutorialsCtx
>>= loadAndApplyTemplate "templates/default.html" tutorialsCtx
2012-12-05 15:54:57 +00:00
>>= relativizeUrls
2011-02-12 14:16:42 +00:00
-- Templates
match "templates/*" $ compile templateCompiler
where
2011-02-12 14:21:26 +00:00
withToc = defaultHakyllWriterOptions
2011-02-12 14:16:42 +00:00
{ writerTableOfContents = True
2011-06-13 16:26:04 +00:00
, writerTemplate = "$toc$\n$body$"
2011-02-12 14:16:42 +00:00
, writerStandalone = True
}
2011-06-16 09:51:55 +00:00
2012-12-05 15:54:57 +00:00
--------------------------------------------------------------------------------
config :: Configuration
config = defaultConfiguration
2013-01-06 08:51:09 +00:00
{ deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
2013-01-15 16:15:46 +00:00
\_site/* \
\jaspervdj@jaspervdj.be:jaspervdj.be/hakyll/"
2011-06-16 09:51:55 +00:00
}
2012-12-29 15:24:27 +00:00
--------------------------------------------------------------------------------
-- | Turns
--
-- > /usr/share/doc/ghc/html/libraries/base-4.6.0.0/Data-String.html
--
-- into
--
-- > http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Data-String.html
hackage :: String -> String
hackage url
| "/usr" `isPrefixOf` url =
"http://hackage.haskell.org/packages/archive/" ++
packageName ++ "/" ++ version' ++ "/doc/html/" ++ baseName
| otherwise = url
where
(packageName, version') = second (drop 1) $ break (== '-') package
(baseName : package : _) = map dropTrailingPathSeparator $
reverse $ splitPath url
--------------------------------------------------------------------------------
-- | Partition tutorials into tutorial series & other articles
partitionTutorials :: [Item a] -> ([Item a], [Item a])
2013-01-13 11:36:45 +00:00
partitionTutorials = partition $ \i ->
case splitPath (toFilePath $ itemIdentifier i) of
[_, (x : _)] -> isDigit x
_ -> False