-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhakyll.hs
executable file
·104 lines (77 loc) · 2.96 KB
/
hakyll.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- Hakyll script for building http://alex.hirzel.us
-- Alexander Hirzel <[email protected]>
-- August, 2011
-- Resources:
-- https://github.com/jaspervdj/hakyll-examples
-- http://citationneeded.me/
-- http://jaspervdj.be/hakyll/tutorials/hakyll-3-to-hakyll4-migration-guide.html
-- http://sigkill.dk/programs/sigkill.html
-- Areas of future work:
-- https://groups.google.com/d/topic/hakyll/p-zk3MFQ_ts/discussion
import Hakyll
import System.FilePath
import Data.Monoid
import Control.Applicative ((<$>))
import Text.Pandoc
config = defaultConfiguration {
deployCommand = "rsync -rv htdocs/ nfsn:/home/public",
destinationDirectory = "htdocs"
}
main :: IO ()
main = let s --> r = match (fromGlob s) r
in hakyllWith config $ do
-- Use empty favicon.ico and robots.txt for performance reasons on NFSN
-- (http://blog.nearlyfreespeech.net/2009/06/16/quick-wordpress-performance-tip-create-a-favicon/)
emptyfile "favicon.ico"
emptyfile "robots.txt"
-- List out the remaining file types
"pages/**.page" --> markdown upDirRoute
"pages/**.jpg" --> static upDirRoute
"pages/**.png" --> static upDirRoute
"*.css" --> css
"*.scss" --> sassycss
"*.mt" --> template
emptyfile :: String -> Rules ()
emptyfile fn = create [fromFilePath fn] $ do route idRoute
compile $ makeItem ""
template = do compile templateCompiler
static r = do route r
compile copyFileCompiler
css = do route idRoute
compile compressCssCompiler
sassycss = do route $ setExtension ".css"
compile $ getResourceString >>=
withItemBody (unixFilter "scss" ["-s"]) >>=
return . fmap compressCss
markdown r = do route $ r `composeRoutes` setExtension ".html"
compile $ myPandocCompiler
>>= loadAndApplyTemplate template defaultContext
>>= relativizeUrls
where template = fromFilePath "default.mt"
myPandocCompiler :: Compiler (Item String)
myPandocCompiler = cached cacheName $ writePandocWith wopt . (fmap $ readMarkdown ropt) <$> getResourceBody
where
cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
ropt = defaultHakyllReaderOptions { readerInitialURLs = [("mtu", "mtu", "mtu")] }
wopt = defaultHakyllWriterOptions
-- | Route which uses @upDir'@ to chop off the top-level directory during routing.
--
-- >>> route upDirRoute
--
-- >>> route $ upDirRoute `composeRoutes` upDirRoute
upDirRoute :: Routes
upDirRoute = customRoute $ upDir . toFilePath
-- | Chops off the top-level directory from a @FilePath@.
--
-- >>> upDir "/foo/bar/baz"
-- "/bar/baz"
--
-- >>> upDir "foo/bar/baz"
-- "bar/baz"
upDir :: FilePath -> FilePath
upDir = joinPath . dropTopDir . splitDirectories
where
dropTopDir ("/":x2:xs) = "/" : tail xs
dropTopDir (x1 :x2:xs) = x2:xs
dropTopDir xs = xs
-- vim:set et sw=2: