@@ -1,8 +1,12 @@
11--------------------------------------------------------------------------------
22{-# LANGUAGE OverloadedStrings #-}
3−import Control.Monad (forM_)
4−import Data.Monoid (mappend)
3+import Control.Applicative ((<$>))
4+import Control.Arrow (second)
5+import Control.Monad (forM_)
6+import Data.List (isPrefixOf)
7+import Data.Monoid (mappend)
58import Hakyll
9+import System.FilePath (dropTrailingPathSeparator, splitPath)
610import Text.Pandoc
711
812
@@ -14,7 +18,17 @@ main = hakyllWith config $ do
1418 compile compressCssCompiler
1519
1620 -- Static directories
17− forM_ ["images/*", "examples/*", "reference/**"] $ \f -> match f $ do
21+ forM_ ["images/*", "examples/*"] $ \f -> match f $ do
22+ route idRoute
23+ compile copyFileCompiler
24+
25+ -- Haddock stuff
26+ match "reference/**.html" $ do
27+ route idRoute
28+ compile $ fmap (withUrls hackage) <$> getResourceString
29+
30+ -- Haddock stuff
31+ match ("reference/**" `mappend` complement "**.html") $ do
1832 route idRoute
1933 compile copyFileCompiler
2034
@@ -69,3 +83,23 @@ config = defaultConfiguration
6983 , deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
7084 \_site/* jaspervdj@jaspervdj.be:jaspervdj.be/tmp/hakyll4"
7185 }
86+
87+
88+--------------------------------------------------------------------------------
89+-- | Turns
90+--
91+-- > /usr/share/doc/ghc/html/libraries/base-4.6.0.0/Data-String.html
92+--
93+-- into
94+--
95+-- > http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/Data-String.html
96+hackage :: String -> String
97+hackage url
98+ | "/usr" `isPrefixOf` url =
99+ "http://hackage.haskell.org/packages/archive/" ++
100+ packageName ++ "/" ++ version' ++ "/doc/html/" ++ baseName
101+ | otherwise = url
102+ where
103+ (packageName, version') = second (drop 1) $ break (== '-') package
104+ (baseName : package : _) = map dropTrailingPathSeparator $
105+ reverse $ splitPath url