on master help sign in
Partition tutorials into series and articles
d129cdcJasper Van der Jeugt
web/site.hs+15−5
@@ -3,7 +3,7 @@
3import Control.Applicative ((<$>))
3import Control.Applicative ((<$>))
4import Control.Arrow (second)
4import Control.Arrow (second)
5import Control.Monad (forM_)
5import Control.Monad (forM_)
6−import Data.List (isPrefixOf)
6+import Data.List (isPrefixOf, partition)
7import Data.Monoid (mappend)
7import Data.Monoid (mappend)
8import Hakyll
8import Hakyll
9import System.FilePath (dropTrailingPathSeparator, splitPath)
9import System.FilePath (dropTrailingPathSeparator, splitPath)
@@ -53,12 +53,16 @@ main = hakyllWith config $ do
53 compile $ do
53 compile $ do
54 tutorials <- loadAll "tutorials/*"
54 tutorials <- loadAll "tutorials/*"
55 itemTpl <- loadBody "templates/tutorial-item.html"
55 itemTpl <- loadBody "templates/tutorial-item.html"
56− list <- applyTemplateList itemTpl defaultContext $
56+ let (series, articles) = partitionTutorials $
57− chronological tutorials
57+ chronological tutorials
58+
59+ series' <- applyTemplateList itemTpl defaultContext series
60+ articles' <- applyTemplateList itemTpl defaultContext articles
58
61
59 let tutorialsCtx =
62 let tutorialsCtx =
60− constField "title" "Tutorials" `mappend`
63+ constField "title" "Tutorials" `mappend`
64+ constField "series" series' `mappend`
61− constField "tutorials" list `mappend`
65+ constField "articles" articles' `mappend`
62 defaultContext
66 defaultContext
63
67
64 makeItem ""
68 makeItem ""
@@ -102,3 +106,9 @@ hackage url
102 (packageName, version') = second (drop 1) $ break (== '-') package
106 (packageName, version') = second (drop 1) $ break (== '-') package
103 (baseName : package : _) = map dropTrailingPathSeparator $
107 (baseName : package : _) = map dropTrailingPathSeparator $
104 reverse $ splitPath url
108 reverse $ splitPath url
109+
110+
111+--------------------------------------------------------------------------------
112+-- | Partition tutorials into tutorial series & other articles
113+partitionTutorials :: [Item a] -> ([Item a], [Item a])
114+partitionTutorials = partition $ matches (fromRegex "\\d*-.*") . itemIdentifier
web/templates/tutorials.html+7−8
@@ -1,14 +1,13 @@
1<h1>Tutorials about Hakyll</h1>
1<h1>Tutorials about Hakyll</h1>
2−<p>
2+<h2>Tutorial series</h2>
3− Here is a list of tutorials I've written about Hakyll:
3+<ul>$series$</ul>
4−</p>
4+<h2>Other articles</h2>
5−<ul>
5+<p>In no particular order:</p>
6− $tutorials$
6+<ul>$articles$</ul>
7−</ul>
8<p>
7<p>
9 All these tutorials assume you are using the latest stable version of
8 All these tutorials assume you are using the latest stable version of
10 Hakyll. If this is not the case, you might want to update using:
9 Hakyll. If this is not the case, you might want to update using:
10+</p>
11− <pre><code>$ ghc-pkg unregister hakyll
11+<pre><code>$ ghc-pkg unregister hakyll
12$ cabal update
12$ cabal update
13$ cabal install hakyll</code></pre>
13$ cabal install hakyll</code></pre>
14−</p>