1
1
--------------------------------------------------------------------------------
2
2
{-# LANGUAGE OverloadedStrings #-}
3
- import Data.Monoid (mappend )
4
- import Hakyll
5
- import Text.Pandoc
3
+ import Text.Pandoc
4
+ import Data.Maybe (fromMaybe )
5
+ import Data.Monoid (mappend )
6
+ import Hakyll
7
+ import System.FilePath ( (</>) , (<.>)
8
+ , splitExtension , splitFileName
9
+ , takeDirectory )
10
+
6
11
7
12
--------------------------------------------------------------------------------
8
13
main :: IO ()
@@ -11,40 +16,116 @@ main = hakyll $ do
11
16
route idRoute
12
17
compile copyFileCompiler
13
18
14
- match (fromList tops ) $ do
19
+ match (fromList [ {- "index.md", -} " about.md " ] ) $ do
15
20
route $ setExtension " html"
16
21
compile $ pandocCompiler
17
22
>>= loadAndApplyTemplate " templates/page.html" siteCtx
18
23
>>= loadAndApplyTemplate " templates/default.html" siteCtx
19
24
>>= relativizeUrls
20
25
26
+
27
+ -- create ["archive.html"] $ do
28
+ -- route idRoute
29
+ -- compile $ do
30
+ -- posts <- recentFirst =<< loadAll "posts/*"
31
+ -- let archiveCtx = listField "posts" postCtx (return posts) `mappend`
32
+ -- constField "title" "Archives" `mappend`
33
+ -- siteCtx
34
+
35
+ -- makeItem ""
36
+ -- >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
37
+ -- >>= loadAndApplyTemplate "templates/default.html" archiveCtx
38
+ -- >>= relativizeUrls
39
+
40
+
21
41
match " posts/*" $ do
22
- route $ setExtension " html"
42
+ route $ setExtension " html" `composeRoutes`
43
+ dateFolders `composeRoutes`
44
+ dropPostsPrefix `composeRoutes`
45
+ -- prependCategory `composeRoutes`
46
+ appendIndex
23
47
compile $ pandocCompiler
24
- >>= loadAndApplyTemplate " templates/post.html" postCtx
25
- >>= loadAndApplyTemplate " templates/default.html" postCtx
26
- >>= relativizeUrls
48
+ >>= loadAndApplyTemplate " templates/post.html" postCtx
49
+ >>= loadAndApplyTemplate " templates/default.html" postCtx
50
+ >>= relativizeUrls
27
51
28
52
create [" archive.html" ] $ do
29
- route idRoute
53
+ route appendIndex
30
54
compile $ do
31
55
posts <- recentFirst =<< loadAll " posts/*"
32
56
let archiveCtx = listField " posts" postCtx (return posts) `mappend`
33
57
constField " title" " Archives" `mappend`
58
+ constField " demo" " SimpleRefinements.hs" `mappend`
59
+ dropIndexHtml " url" `mappend`
34
60
siteCtx
35
61
36
62
makeItem " "
37
- >>= loadAndApplyTemplate " templates/archive.html" archiveCtx
38
- >>= loadAndApplyTemplate " templates/default.html" archiveCtx
63
+ >>= loadAndApplyTemplate " templates/archive.html" archiveCtx
64
+ >>= loadAndApplyTemplate " templates/default.html" archiveCtx
65
+ >>= relativizeUrls
66
+
67
+ match (fromList [{- "index.md", -} " about.md" ]) $ do
68
+ route $ setExtension " html"
69
+ compile $ pandocCompiler
70
+ >>= loadAndApplyTemplate " templates/page.html" siteCtx
71
+ >>= loadAndApplyTemplate " templates/default.html" siteCtx
39
72
>>= relativizeUrls
40
73
74
+ match " index.md" $ do
75
+ route $ setExtension " html"
76
+ compile $ do
77
+ posts <- fmap (take 5 ) . recentFirst =<< loadAll " posts/*"
78
+ let indexCtx = listField " posts" postCtx (return posts) `mappend`
79
+ -- constField "title" "Home" `mappend`
80
+ constField " demo" " SimpleRefinements.hs" `mappend`
81
+ dropIndexHtml " url" `mappend`
82
+ siteCtx
83
+
84
+ -- getResourceBody
85
+ pandocCompiler
86
+ >>= applyAsTemplate indexCtx
87
+ >>= loadAndApplyTemplate " templates/index.html" indexCtx
88
+ >>= loadAndApplyTemplate " templates/default.html" indexCtx
89
+ >>= relativizeUrls
90
+
41
91
match " templates/*" $ compile templateCompiler
42
92
93
+
94
+
95
+ appendIndex :: Routes
96
+ appendIndex = customRoute $ (\ (p, e) -> p </> " index" <.> e) . splitExtension . toFilePath
97
+
98
+ transform :: String -> String
99
+ transform url = case splitFileName url of
100
+ (p, " index.html" ) -> takeDirectory p
101
+ _ -> url
102
+
103
+ dropIndexHtml :: String -> Context a
104
+ dropIndexHtml key = mapContext transform (urlField key)
105
+ where
106
+ transform url = case splitFileName url of
107
+ (p, " index.html" ) -> takeDirectory p
108
+ _ -> url
109
+
110
+ dateFolders :: Routes
111
+ dateFolders =
112
+ gsubRoute " /[0-9]{4}-[0-9]{2}-[0-9]{2}-" $ replaceAll " -" (const " /" )
113
+
114
+ dropPostsPrefix :: Routes
115
+ dropPostsPrefix = gsubRoute " posts/" $ const " "
116
+
117
+ -- prependCategory :: Routes
118
+ -- prependCategory = metadataRoute $ \md -> customRoute $
119
+ -- let mbCategory = lookupString "category" md
120
+ -- category = fromMaybe (error "Posts: Post without category") mbCategory
121
+ -- in (category </>) . toFilePath
122
+
43
123
--------------------------------------------------------------------------------
44
124
postCtx :: Context String
45
125
postCtx =
46
- dateField " date" " %B %e, %Y" `mappend`
47
- siteCtx
126
+ dateField " date" " %b %e, %Y" `mappend`
127
+ dropIndexHtml " url" `mappend`
128
+ siteCtx
48
129
49
130
50
131
-- http://goto.ucsd.edu:8090/index.html#?demo=ANF.hs
@@ -63,9 +144,8 @@ siteCtx =
63
144
constField " github_username" " ucsd-progsys" `mappend`
64
145
constField
" google_username" " [email protected] " `mappend`
65
146
constField " google_userid" " u/0/106612421534244742464" `mappend`
66
- constField " demo" " SimpleRefinements.hs" `mappend`
147
+ -- constField "demo" "SimpleRefinements.hs" `mappend`
67
148
constField " headerImg" " sea.jpg" `mappend`
149
+ constField " summary" " todo" `mappend`
150
+ constField " disqus_short_name" " liquidhaskell" `mappend`
68
151
defaultContext
69
-
70
- tops :: [Identifier ]
71
- tops = [ " index.md" , " about.md" ]
0 commit comments