on master help sign in
Update examples to new matching mechanism
commit8dd1f94e02d7df918f2e3a08328468c4b584d683 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 5 Apr 2011, 16:20 (16 years ago) parentff118fe
6 files changed+107−114
examples/brochure/hakyll.hs+10−8 examples/feedblog/hakyll.hs+22−26 examples/hakyll/hakyll.hs+18−16 examples/morepages/hakyll.hs+12−11 examples/simpleblog/hakyll.hs+21−25 examples/tagblog/hakyll.hs+24−28
examples/brochure/hakyll.hs+10−8
@@ -6,13 +6,15 @@ import Hakyll
66
77main :: IO ()
88main = hakyll $ do
9− route "css/*" idRoute
10− compile "css/*" compressCssCompiler
9+ match "css/*" $ do
10+ route idRoute
11+ compile compressCssCompiler
1112
12− compile "templates/*" templateCompiler
13+ match "templates/*" $ compile templateCompiler
1314
14− forM_ ["about.rst", "index.markdown", "code.lhs"] $ \page -> do
15− route page $ setExtension "html"
16− compile page $ pageCompiler
17− >>> applyTemplateCompiler "templates/default.html"
18− >>> relativizeUrlsCompiler
15+ forM_ ["about.rst", "index.markdown", "code.lhs"] $ \page ->
16+ match page $ do
17+ route $ setExtension "html"
18+ compile $ pageCompiler
19+ >>> applyTemplateCompiler "templates/default.html"
20+ >>> relativizeUrlsCompiler
examples/feedblog/hakyll.hs+22−26
@@ -11,47 +11,43 @@ import Hakyll
1111main :: IO ()
1212main = hakyll $ do
1313 -- Compress CSS
14− route "css/*" idRoute
15− compile "css/*" compressCssCompiler
14+ match "css/*" $ do
15+ route idRoute
16+ compile compressCssCompiler
1617
1718 -- Render posts
18− route "posts/*" $ setExtension ".html"
19− compile "posts/*" $
20− pageCompiler
19+ match "posts/*" $ do
20+ route $ setExtension ".html"
21+ compile $ pageCompiler
2122 >>> applyTemplateCompiler "templates/post.html"
2223 >>> applyTemplateCompiler "templates/default.html"
2324 >>> relativizeUrlsCompiler
2425
2526 -- Render posts list
26− route "posts.html" $ idRoute
27− create "posts.html" $
28− constA mempty
29− >>> arr (setField "title" "All posts")
30− >>> requireAllA "posts/*" addPostList
31− >>> applyTemplateCompiler "templates/posts.html"
32− >>> applyTemplateCompiler "templates/default.html"
33− >>> relativizeUrlsCompiler
27+ match "posts.html" $ route idRoute
28+ create "posts.html" $ constA mempty
29+ >>> arr (setField "title" "All posts")
30+ >>> requireAllA "posts/*" addPostList
31+ >>> applyTemplateCompiler "templates/posts.html"
32+ >>> applyTemplateCompiler "templates/default.html"
33+ >>> relativizeUrlsCompiler
3434
3535 -- Index
36− route "index.html" $ idRoute
37− create "index.html" $
38− constA mempty
39− >>> arr (setField "title" "Home")
40− >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
41− >>> applyTemplateCompiler "templates/index.html"
42− >>> applyTemplateCompiler "templates/default.html"
43− >>> relativizeUrlsCompiler
36+ match "index.html" $ route idRoute
37+ create "index.html" $ constA mempty
38+ >>> arr (setField "title" "Home")
39+ >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
40+ >>> applyTemplateCompiler "templates/index.html"
41+ >>> applyTemplateCompiler "templates/default.html"
42+ >>> relativizeUrlsCompiler
4443
4544 -- Render RSS feed
46− route "rss.xml" $ idRoute
45+ match "rss.xml" $ route idRoute
4746 create "rss.xml" $
4847 requireAll_ "posts/*" >>> renderRss feedConfiguration
4948
5049 -- Read templates
51− compile "templates/*" templateCompiler
52−
53− -- End
54− return ()
50+ match "templates/*" $ compile templateCompiler
5551
5652-- | Auxiliary compiler: generate a post list from a list of given posts, and
5753-- add it to the current page under @$posts@
examples/hakyll/hakyll.hs+18−16
@@ -6,35 +6,37 @@ import Text.Pandoc
66
77main :: IO ()
88main = hakyll $ do
9− route "css/*" idRoute
10− compile "css/*" compressCssCompiler
9+ match "css/*" $ do
10+ route idRoute
11+ compile compressCssCompiler
1112
1213 -- Static directories
13− forM_ ["images/*", "examples/*", "reference/*"] $ \f -> do
14− route f idRoute
15− compile f copyFileCompiler
14+ forM_ ["images/*", "examples/*", "reference/*"] $ \f -> match f $ do
15+ route idRoute
16+ compile copyFileCompiler
1617
1718 -- Pages
18− forM_ pages $ \p -> do
19− route p $ setExtension "html"
20− compile p $ pageCompiler
19+ forM_ pages $ \p -> match p $ do
20+ route $ setExtension "html"
21+ compile $ pageCompiler
2122 >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
2223 >>> applyTemplateCompiler "templates/default.html"
2324 >>> relativizeUrlsCompiler
2425
2526 -- Tutorial
26− route "tutorial.markdown" $ setExtension "html"
27− compile "tutorial.markdown" $ readPageCompiler
28− >>> pageRenderPandocWith defaultHakyllParserState withToc
29− >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
30− >>> applyTemplateCompiler "templates/default.html"
31− >>> relativizeUrlsCompiler
27+ match "tutorial.markdown" $ do
28+ route $ setExtension "html"
29+ compile $ readPageCompiler
30+ >>> pageRenderPandocWith defaultHakyllParserState withToc
31+ >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
32+ >>> applyTemplateCompiler "templates/default.html"
33+ >>> relativizeUrlsCompiler
3234
3335 -- Sidebar
34− compile "sidebar.markdown" pageCompiler
36+ match "sidebar.markdown" $ compile pageCompiler
3537
3638 -- Templates
37− compile "templates/*" templateCompiler
39+ match "templates/*" $ compile templateCompiler
3840 where
3941 withToc = defaultHakyllWriterOptions
4042 { writerTableOfContents = True
examples/morepages/hakyll.hs+12−11
@@ -9,20 +9,21 @@ import Hakyll
99main :: IO ()
1010main = hakyll $ do
1111 -- Compress CSS
12− route "css/*" idRoute
13− compile "css/*" compressCssCompiler
12+ match "css/*" $ do
13+ route idRoute
14+ compile compressCssCompiler
1415
1516 -- Render static pages
16− forM_ ["about.markdown", "index.markdown", "products.markdown"] $ \p -> do
17− route p $ setExtension ".html"
18− compile p $
19− pageCompiler
20− >>> requireA "footer.markdown" (setFieldA "footer" $ arr pageBody)
21− >>> applyTemplateCompiler "templates/default.html"
22− >>> relativizeUrlsCompiler
17+ forM_ ["about.markdown", "index.markdown", "products.markdown"] $ \p ->
18+ match p $ do
19+ route $ setExtension ".html"
20+ compile $ pageCompiler
21+ >>> requireA "footer.markdown" (setFieldA "footer" $ arr pageBody)
22+ >>> applyTemplateCompiler "templates/default.html"
23+ >>> relativizeUrlsCompiler
2324
2425 -- Compile footer
25− compile "footer.markdown" pageCompiler
26+ match "footer.markdown" $ compile pageCompiler
2627
2728 -- Read templates
28− compile "templates/*" templateCompiler
29+ match "templates/*" $ compile templateCompiler
examples/simpleblog/hakyll.hs+21−25
@@ -11,42 +11,38 @@ import Hakyll
1111main :: IO ()
1212main = hakyll $ do
1313 -- Compress CSS
14− route "css/*" idRoute
15− compile "css/*" compressCssCompiler
14+ match "css/*" $ do
15+ route idRoute
16+ compile compressCssCompiler
1617
1718 -- Render posts
18− route "posts/*" $ setExtension ".html"
19− compile "posts/*" $
20− pageCompiler
19+ match "posts/*" $ do
20+ route $ setExtension ".html"
21+ compile $ pageCompiler
2122 >>> applyTemplateCompiler "templates/post.html"
2223 >>> applyTemplateCompiler "templates/default.html"
2324 >>> relativizeUrlsCompiler
2425
2526 -- Render posts list
26− route "posts.html" $ idRoute
27− create "posts.html" $
28− constA mempty
29− >>> arr (setField "title" "All posts")
30− >>> requireAllA "posts/*" addPostList
31− >>> applyTemplateCompiler "templates/posts.html"
32− >>> applyTemplateCompiler "templates/default.html"
33− >>> relativizeUrlsCompiler
27+ match "posts.html" $ route idRoute
28+ create "posts.html" $ constA mempty
29+ >>> arr (setField "title" "All posts")
30+ >>> requireAllA "posts/*" addPostList
31+ >>> applyTemplateCompiler "templates/posts.html"
32+ >>> applyTemplateCompiler "templates/default.html"
33+ >>> relativizeUrlsCompiler
3434
3535 -- Index
36− route "index.html" idRoute
37− create "index.html" $
38− constA mempty
39− >>> arr (setField "title" "Home")
40− >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
41− >>> applyTemplateCompiler "templates/index.html"
42− >>> applyTemplateCompiler "templates/default.html"
43− >>> relativizeUrlsCompiler
36+ match "index.html" $ route idRoute
37+ create "index.html" $ constA mempty
38+ >>> arr (setField "title" "Home")
39+ >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
40+ >>> applyTemplateCompiler "templates/index.html"
41+ >>> applyTemplateCompiler "templates/default.html"
42+ >>> relativizeUrlsCompiler
4443
4544 -- Read templates
46− compile "templates/*" templateCompiler
47−
48− -- End
49− return ()
45+ match "templates/*" $ compile templateCompiler
5046
5147-- | Auxiliary compiler: generate a post list from a list of given posts, and
5248-- add it to the current page under @$posts@
examples/tagblog/hakyll.hs+24−28
@@ -12,13 +12,14 @@ import Hakyll
1212main :: IO ()
1313main = hakyll $ do
1414 -- Compress CSS
15− route "css/*" idRoute
16− compile "css/*" compressCssCompiler
15+ match "css/*" $ do
16+ route idRoute
17+ compile compressCssCompiler
1718
1819 -- Render posts
19− route "posts/*" $ setExtension ".html"
20− compile "posts/*" $
21− pageCompiler
20+ match "posts/*" $ do
21+ route $ setExtension ".html"
22+ compile $ pageCompiler
2223 >>> arr (renderDateField "date" "%B %e, %Y" "Date unknown")
2324 >>> renderTagsField "prettytags" (fromCaptureString "tags/*")
2425 >>> applyTemplateCompiler "templates/post.html"
@@ -26,48 +27,43 @@ main = hakyll $ do
2627 >>> relativizeUrlsCompiler
2728
2829 -- Render posts list
29− route "posts.html" $ idRoute
30− create "posts.html" $
31− constA mempty
32− >>> arr (setField "title" "All posts")
33− >>> requireAllA "posts/*" addPostList
34− >>> applyTemplateCompiler "templates/posts.html"
35− >>> applyTemplateCompiler "templates/default.html"
36− >>> relativizeUrlsCompiler
30+ match "posts.html" $ route idRoute
31+ create "posts.html" $ constA mempty
32+ >>> arr (setField "title" "All posts")
33+ >>> requireAllA "posts/*" addPostList
34+ >>> applyTemplateCompiler "templates/posts.html"
35+ >>> applyTemplateCompiler "templates/default.html"
36+ >>> relativizeUrlsCompiler
3737
3838 -- Index
39− route "index.html" $ idRoute
40− create "index.html" $
41− constA mempty
42− >>> arr (setField "title" "Home")
43− >>> requireA "tags" (setFieldA "tagcloud" (renderTagCloud'))
44− >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
45− >>> applyTemplateCompiler "templates/index.html"
46− >>> applyTemplateCompiler "templates/default.html"
47− >>> relativizeUrlsCompiler
39+ match "index.html" $ route idRoute
40+ create "index.html" $ constA mempty
41+ >>> arr (setField "title" "Home")
42+ >>> requireA "tags" (setFieldA "tagcloud" (renderTagCloud'))
43+ >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
44+ >>> applyTemplateCompiler "templates/index.html"
45+ >>> applyTemplateCompiler "templates/default.html"
46+ >>> relativizeUrlsCompiler
4847
4948 -- Tags
5049 create "tags" $
5150 requireAll "posts/*" (\_ ps -> readTags ps :: Tags String)
5251
5352 -- Add a tag list compiler for every tag
54− route "tags/*" $ setExtension ".html"
53+ match "tags/*" $ route $ setExtension ".html"
5554 metaCompile $ require_ "tags"
5655 >>> arr (M.toList . tagsMap)
5756 >>> arr (map (\(t, p) -> (tagIdentifier t, makeTagList t p)))
5857
5958 -- Render RSS feed
60− route "rss.xml" $ idRoute
59+ match "rss.xml" $ route idRoute
6160 create "rss.xml" $
6261 requireAll_ "posts/*"
6362 >>> mapCompiler (arr $ copyBodyToField "description")
6463 >>> renderRss feedConfiguration
6564
6665 -- Read templates
67− compile "templates/*" templateCompiler
68−
69− -- End
70− return ()
66+ match "templates/*" $ compile templateCompiler
7167 where
7268 renderTagCloud' :: Compiler (Tags String) String
7369 renderTagCloud' = renderTagCloud tagIdentifier 100 120