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)
|
2013-01-13 11:18:24 +00:00
|
|
|
import Data.List (isPrefixOf, partition)
|
2012-12-29 15:24:27 +00:00
|
|
|
import Data.Monoid (mappend)
|
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
|
2011-04-05 14:20:43 +00:00
|
|
|
match "css/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile compressCssCompiler
|
2009-12-29 18:26:51 +00:00
|
|
|
|
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
|
2011-04-05 14:20:43 +00:00
|
|
|
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
|
2011-04-05 14:20:43 +00:00
|
|
|
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
|
2010-03-30 17:36:41 +00:00
|
|
|
|
2011-06-13 16:26:04 +00:00
|
|
|
-- Tutorials
|
|
|
|
match "tutorials/*" $ do
|
2011-04-05 14:20:43 +00:00
|
|
|
route $ setExtension "html"
|
2013-01-20 08:35:39 +00:00
|
|
|
compile $ pandocCompilerWith def 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
|
2009-12-29 18:26:51 +00:00
|
|
|
|
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"
|
2013-01-13 11:18:24 +00:00
|
|
|
let (series, articles) = partitionTutorials $
|
|
|
|
chronological tutorials
|
|
|
|
|
|
|
|
series' <- applyTemplateList itemTpl defaultContext series
|
|
|
|
articles' <- applyTemplateList itemTpl defaultContext articles
|
2012-12-05 15:54:57 +00:00
|
|
|
|
|
|
|
let tutorialsCtx =
|
2013-01-13 11:18:24 +00:00
|
|
|
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
|
2011-04-05 14:20:43 +00:00
|
|
|
match "templates/*" $ compile templateCompiler
|
2010-01-19 09:08:57 +00:00
|
|
|
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/* \
|
2013-01-16 11:58:58 +00:00
|
|
|
\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
|
2013-01-13 11:18:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | 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
|