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