on master help sign in
Refactor tutorials on hakyll website
d832cd8Jasper Van der Jeugt
web/site.hs+13−32
@@ -1,8 +1,7 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3import Control.Arrow (second)
3import Control.Arrow (second)
4−import Control.Monad (forM_)
4+import Control.Monad (filterM, forM_)
5−import Data.Char (isDigit)
6import Data.List (isPrefixOf, sortBy)
5import Data.List (isPrefixOf, sortBy)
7import Data.Monoid ((<>))
6import Data.Monoid ((<>))
8import Data.Ord (comparing)
7import Data.Ord (comparing)
@@ -57,17 +56,11 @@ main = hakyllWith config $ do
57 create ["tutorials.html"] $ do
56 create ["tutorials.html"] $ do
58 route idRoute
57 route idRoute
59 compile $ do
58 compile $ do
60− tuts <-
59+ ctx <- tutorialsCtx <$>
61 sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
60 sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
62−
63− let tutorialsCtx =
64− constField "title" "Tutorials" `mappend`
65− listField "tutorials" tutorialCtx (return tuts) `mappend`
66− defaultContext
67−
68 makeItem ""
61 makeItem ""
69− >>= loadAndApplyTemplate "templates/tutorials.html" tutorialsCtx
62+ >>= loadAndApplyTemplate "templates/tutorials.html" ctx
70− >>= loadAndApplyTemplate "templates/default.html" tutorialsCtx
63+ >>= loadAndApplyTemplate "templates/default.html" ctx
71 >>= relativizeUrls
64 >>= relativizeUrls
72
65
73 -- Templates
66 -- Templates
@@ -108,28 +101,16 @@ hackage url
108 reverse $ splitPath url
101 reverse $ splitPath url
109
102
110
103
111−--------------------------------------------------------------------------------
112−data TutorialType = SeriesTutorial | ArticlesTutorial | ExternalTutorial
113− deriving (Eq)
114−
115−
116--------------------------------------------------------------------------------
104--------------------------------------------------------------------------------
117-- | Partition tutorials into tutorial series, other articles, external articles
105-- | Partition tutorials into tutorial series, other articles, external articles
118−tutorialCtx :: Context String
106+tutorialsCtx :: [Item String] -> Context String
119−tutorialCtx =
107+tutorialsCtx tuts =
120− field "isSeries" (isTutorialType SeriesTutorial) <>
108+ constField "title" "Tutorials" <>
121− field "isArticle" (isTutorialType ArticlesTutorial) <>
109+ listField "main" defaultContext (ofType "main") <>
122− field "isExternal" (isTutorialType ExternalTutorial) <>
110+ listField "articles" defaultContext (ofType "article") <>
111+ listField "externals" defaultContext (ofType "external") <>
123 defaultContext
112 defaultContext
124 where
113 where
125− getTutorialType item = do
114+ ofType ty = filterM (\item -> do
126− mbExternal <- getMetadataField (itemIdentifier item) "external"
115+ mbType <- getMetadataField (itemIdentifier item) "type"
127− return $ case mbExternal of
116+ return $ Just ty == mbType) tuts
128− Just _ -> ExternalTutorial
129− _ -> case splitPath (toFilePath $ itemIdentifier item) of
130− [_, (x : _)] -> if isDigit x then SeriesTutorial else ArticlesTutorial
131− _ -> ArticlesTutorial
132−
133− isTutorialType ty0 item = do
134− ty1 <- getTutorialType item
135− if ty0 == ty1 then return "yes" else fail "no"
web/templates/tutorials.html+12−18
@@ -1,23 +1,19 @@
1<h1>Tutorials about Hakyll</h1>
1<h1>Tutorials about Hakyll</h1>
2<h2 id="series">Tutorial series</h2>
2<h2 id="series">Tutorial series</h2>
3<ul>
3<ul>
4− $for(tutorials)$
4+ $for(main)$
5− $if(isSeries)$
6− <li>
5+ <li>
7− <a href="$url$">$title$</a>
6+ <a href="$url$">$title$</a>
8− </li>
7+ </li>
9− $endif$
10 $endfor$
8 $endfor$
11</ul>
9</ul>
12<h2 id="articles">Other articles</h2>
10<h2 id="articles">Other articles</h2>
13<p>In no particular order:</p>
11<p>In no particular order:</p>
14<ul>
12<ul>
15− $for(tutorials)$
13+ $for(articles)$
16− $if(isArticle)$
17− <li>
14+ <li>
18− <a href="$url$">$title$</a> by <em>$author$</em>
15+ <a href="$url$">$title$</a> by <em>$author$</em>
19− </li>
16+ </li>
20− $endif$
21 $endfor$
17 $endfor$
22</ul>
18</ul>
23<h2 id="external-articles">External articles</h2>
19<h2 id="external-articles">External articles</h2>
@@ -28,12 +24,10 @@
28</p>
24</p>
29<p>In no particular order:</p>
25<p>In no particular order:</p>
30<ul>
26<ul>
31− $for(tutorials)$
27+ $for(externals)$
32− $if(isExternal)$
33− <li>
28+ <li>
34− <a href="$url$">$title$</a> by <em>$author$</em>
29+ <a href="$url$">$title$</a> by <em>$author$</em>
35− </li>
30+ </li>
36− $endif$
37 $endfor$
31 $endfor$
38</ul>
32</ul>
39<p>
33<p>
web/tutorials/01-installation.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Installation
2title: Installation
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Installation
7Installation
web/tutorials/02-basics.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: The basics
2title: The basics
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Building and cleaning
7Building and cleaning
web/tutorials/03-rules-routes-compilers.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Rules, routes and compilers
2title: Rules, routes and compilers
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Basic rules
7Basic rules
web/tutorials/04-compilers.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: 'More on compilers: load, and templates'
2title: 'More on compilers: load, and templates'
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Loading items
7Loading items
web/tutorials/05-snapshots-feeds.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Snapshots, and how to produce an RSS/Atom feed
2title: Snapshots, and how to produce an RSS/Atom feed
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Basic feed configuration
7Basic feed configuration
web/tutorials/06-versions.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Producing multiple versions of a single file
2title: Producing multiple versions of a single file
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: main
4---
5---
5
6
6Basics
7Basics
web/tutorials/a-guide-to-the-hakyll-module-zoo.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: A Guide to the Hakyll Module Zoo
2title: A Guide to the Hakyll Module Zoo
3author: Brent Yorgey
3author: Brent Yorgey
4+type: article
4---
5---
5
6
6The hakyll package [contains a bewildering array](/reference/) of modules, and
7The hakyll package [contains a bewildering array](/reference/) of modules, and
web/tutorials/external-add-tags-to-your-hakyll-blog.md+1−1
@@ -2,5 +2,5 @@
2title: Add tags to your Hakyll blog
2title: Add tags to your Hakyll blog
3author: Javran Cheng
3author: Javran Cheng
4url: https://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html
4url: https://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html
5−external: true
5+type: external
6---
6---
web/tutorials/external-blogger-port.md+1−1
@@ -2,5 +2,5 @@
2title: Port an existing Blogger blog to Hakyll
2title: Port an existing Blogger blog to Hakyll
3author: Daniel Campoverde
3author: Daniel Campoverde
4url: 'http://www.sillybytes.net/posts/from_blogger_to_hakyll.html'
4url: 'http://www.sillybytes.net/posts/from_blogger_to_hakyll.html'
5−external: true
5+type: external
6---
6---
web/tutorials/external-cassius-template.md+1−1
@@ -2,5 +2,5 @@
2title: Using Cassius templating with Hakyll
2title: Using Cassius templating with Hakyll
3author: Daniel Campoverde
3author: Daniel Campoverde
4url: 'http://www.sillybytes.net/posts/using_hakyll_with_cassius.html'
4url: 'http://www.sillybytes.net/posts/using_hakyll_with_cassius.html'
5−external: true
5+type: external
6---
6---
web/tutorials/external-clean-urls-with-hakyll.md+1−1
@@ -2,5 +2,5 @@
2title: Clean URLs with Hakyll
2title: Clean URLs with Hakyll
3author: Rohan Jain
3author: Rohan Jain
4url: http://www.rohanjain.in/hakyll-clean-urls/
4url: http://www.rohanjain.in/hakyll-clean-urls/
5−external: true
5+type: external
6---
6---
web/tutorials/external-deploying-with-widely.md+1−1
@@ -2,5 +2,5 @@
2title: Deploying with Widely
2title: Deploying with Widely
3author: Kyle Marek-Spartz
3author: Kyle Marek-Spartz
4url: http://kyle.marek-spartz.org/posts/2013-12-09-widely-and-hakyll.html
4url: http://kyle.marek-spartz.org/posts/2013-12-09-widely-and-hakyll.html
5−external: true
5+type: external
6---
6---
web/tutorials/external-functionfield.md+1−1
@@ -2,5 +2,5 @@
2title: Hakyll's functionField
2title: Hakyll's functionField
3author: Beerend Lauwers
3author: Beerend Lauwers
4url: http://beerendlauwers.be/posts/2015-09-21-hakylls-functionfield.html
4url: http://beerendlauwers.be/posts/2015-09-21-hakylls-functionfield.html
5−external: true
5+type: external
6---
6---
web/tutorials/external-github-pages-circle-ci.md+1−1
@@ -2,5 +2,5 @@
2title: Create a GitHub page with Hakyll and CircleCI
2title: Create a GitHub page with Hakyll and CircleCI
3author: Juan Pedro Villa
3author: Juan Pedro Villa
4url: https://www.stackbuilders.com/news/dr-hakyll-create-a-github-page-with-hakyll-and-circleci
4url: https://www.stackbuilders.com/news/dr-hakyll-create-a-github-page-with-hakyll-and-circleci
5−external: true
5+type: external
6---
6---
web/tutorials/external-inlining-and-compressing-css.md+1−1
@@ -2,5 +2,5 @@
2title: Inlining and compressing CSS
2title: Inlining and compressing CSS
3author: Kyle Marek-Spartz
3author: Kyle Marek-Spartz
4url: http://kyle.marek-spartz.org/posts/2014-12-09-hakyll-css-template-compiler.html
4url: http://kyle.marek-spartz.org/posts/2014-12-09-hakyll-css-template-compiler.html
5−external: true
5+type: external
6---
6---
web/tutorials/faq.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: FAQ
2title: FAQ
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: article
4---
5---
5
6
6## "hGetContents: invalid argument" or "commitBuffer: invalid argument"
7## "hGetContents: invalid argument" or "commitBuffer: invalid argument"
web/tutorials/github-pages-tutorial.md+1
@@ -1,6 +1,7 @@
1---
1---
2title: Using Hakyll with GitHub Pages
2title: Using Hakyll with GitHub Pages
3author: Erik Stevenson
3author: Erik Stevenson
4+type: article
4---
5---
5
6
6## Introduction
7## Introduction
web/tutorials/hakyll-3-to-hakyll4-migration-guide.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Hakyll 3 to Hakyll 4 migration guide
2title: Hakyll 3 to Hakyll 4 migration guide
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: article
4---
5---
5
6
6Introduction
7Introduction
web/tutorials/using-clay-with-hakyll.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Using Clay with Hakyll
2title: Using Clay with Hakyll
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4+type: article
4---
5---
5
6
6[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
7[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
web/tutorials/using-teasers-in-hakyll.markdown+1
@@ -1,6 +1,7 @@
1---
1---
2title: Using teasers in Hakyll
2title: Using teasers in Hakyll
3author: Ivan Veselov
3author: Ivan Veselov
4+type: article
4---
5---
5
6
6## Introduction
7## Introduction