Add external articles
This commit is contained in:
parent
7d4a83294d
commit
bb3f0d3cff
4 changed files with 74 additions and 26 deletions
47
web/site.hs
47
web/site.hs
|
@ -1,11 +1,10 @@
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
import Control.Applicative ((<$>))
|
|
||||||
import Control.Arrow (second)
|
import Control.Arrow (second)
|
||||||
import Control.Monad (forM_)
|
import Control.Monad (forM_)
|
||||||
import Data.Char (isDigit)
|
import Data.Char (isDigit)
|
||||||
import Data.List (isPrefixOf, partition, sortBy)
|
import Data.List (isPrefixOf, sortBy)
|
||||||
import Data.Monoid (mappend)
|
import Data.Monoid ((<>))
|
||||||
import Data.Ord (comparing)
|
import Data.Ord (comparing)
|
||||||
import Hakyll
|
import Hakyll
|
||||||
import System.FilePath (dropTrailingPathSeparator, splitPath)
|
import System.FilePath (dropTrailingPathSeparator, splitPath)
|
||||||
|
@ -53,18 +52,12 @@ main = hakyllWith config $ do
|
||||||
create ["tutorials.html"] $ do
|
create ["tutorials.html"] $ do
|
||||||
route idRoute
|
route idRoute
|
||||||
compile $ do
|
compile $ do
|
||||||
tutorials <- loadAll "tutorials/*"
|
tuts <-
|
||||||
itemTpl <- loadBody "templates/tutorial-item.html"
|
sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
|
||||||
let (series, articles) = partitionTutorials $
|
|
||||||
sortBy (comparing itemIdentifier) tutorials
|
|
||||||
|
|
||||||
series' <- applyTemplateList itemTpl defaultContext series
|
|
||||||
articles' <- applyTemplateList itemTpl defaultContext articles
|
|
||||||
|
|
||||||
let tutorialsCtx =
|
let tutorialsCtx =
|
||||||
constField "title" "Tutorials" `mappend`
|
constField "title" "Tutorials" `mappend`
|
||||||
constField "series" series' `mappend`
|
listField "tutorials" tutorialCtx (return tuts) `mappend`
|
||||||
constField "articles" articles' `mappend`
|
|
||||||
defaultContext
|
defaultContext
|
||||||
|
|
||||||
makeItem ""
|
makeItem ""
|
||||||
|
@ -112,9 +105,27 @@ hackage url
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- | Partition tutorials into tutorial series & other articles
|
data TutorialType = SeriesTutorial | ArticlesTutorial | ExternalTutorial
|
||||||
partitionTutorials :: [Item a] -> ([Item a], [Item a])
|
deriving (Eq)
|
||||||
partitionTutorials = partition $ \i ->
|
|
||||||
case splitPath (toFilePath $ itemIdentifier i) of
|
|
||||||
[_, (x : _)] -> isDigit x
|
--------------------------------------------------------------------------------
|
||||||
_ -> False
|
-- | Partition tutorials into tutorial series, other articles, external articles
|
||||||
|
tutorialCtx :: Context String
|
||||||
|
tutorialCtx =
|
||||||
|
field "isSeries" (isTutorialType SeriesTutorial) <>
|
||||||
|
field "isArticle" (isTutorialType ArticlesTutorial) <>
|
||||||
|
field "isExternal" (isTutorialType ExternalTutorial) <>
|
||||||
|
defaultContext
|
||||||
|
where
|
||||||
|
getTutorialType item = do
|
||||||
|
mbExternal <- getMetadataField (itemIdentifier item) "external"
|
||||||
|
return $ case mbExternal of
|
||||||
|
Just _ -> ExternalTutorial
|
||||||
|
_ -> case splitPath (toFilePath $ itemIdentifier item) of
|
||||||
|
[_, (x : _)] -> if isDigit x then SeriesTutorial else ArticlesTutorial
|
||||||
|
_ -> ArticlesTutorial
|
||||||
|
|
||||||
|
isTutorialType ty0 item = do
|
||||||
|
ty1 <- getTutorialType item
|
||||||
|
if ty0 == ty1 then return "yes" else fail "no"
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
<li><a href="$url$">$title$</a> by <em>$author$</em></li>
|
|
|
@ -1,9 +1,36 @@
|
||||||
<h1>Tutorials about Hakyll</h1>
|
<h1>Tutorials about Hakyll</h1>
|
||||||
<h2>Tutorial series</h2>
|
<h2>Tutorial series</h2>
|
||||||
<ul>$series$</ul>
|
<ul>
|
||||||
|
$for(tutorials)$
|
||||||
|
$if(isSeries)$
|
||||||
|
<li>
|
||||||
|
<a href="$url$">$title$</a>
|
||||||
|
</li>
|
||||||
|
$endif$
|
||||||
|
$endfor$
|
||||||
|
</ul>
|
||||||
<h2>Other articles</h2>
|
<h2>Other articles</h2>
|
||||||
<p>In no particular order:</p>
|
<p>In no particular order:</p>
|
||||||
<ul>$articles$</ul>
|
<ul>
|
||||||
|
$for(tutorials)$
|
||||||
|
$if(isArticle)$
|
||||||
|
<li>
|
||||||
|
<a href="$url$">$title$</a> by <em>$author$</em>
|
||||||
|
</li>
|
||||||
|
$endif$
|
||||||
|
$endfor$
|
||||||
|
</ul>
|
||||||
|
<h2>External articles</h2>
|
||||||
|
<p>In no particular order:</p>
|
||||||
|
<ul>
|
||||||
|
$for(tutorials)$
|
||||||
|
$if(isExternal)$
|
||||||
|
<li>
|
||||||
|
<a href="$url$">$title$</a> by <em>$author$</em>
|
||||||
|
</li>
|
||||||
|
$endif$
|
||||||
|
$endfor$
|
||||||
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
All these tutorials assume you are using the latest stable version of
|
All these tutorials assume you are using the latest stable version of
|
||||||
Hakyll. If this is not the case, you might want to update using:
|
Hakyll. If this is not the case, you might want to update using:
|
||||||
|
@ -11,3 +38,8 @@
|
||||||
<pre><code>$$ ghc-pkg unregister hakyll
|
<pre><code>$$ ghc-pkg unregister hakyll
|
||||||
$$ cabal update
|
$$ cabal update
|
||||||
$$ cabal install hakyll</code></pre>
|
$$ cabal install hakyll</code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Or using stack:
|
||||||
|
</p>
|
||||||
|
<pre><code>$$ stack install hakyll</code></pre>
|
||||||
|
|
6
web/tutorials/external-clean-urls-with-hakyll.md
Normal file
6
web/tutorials/external-clean-urls-with-hakyll.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
title: Clean URLs with Hakyll
|
||||||
|
author: Rohan Jain
|
||||||
|
url: http://www.rohanjain.in/hakyll-clean-urls/
|
||||||
|
external: true
|
||||||
|
---
|
Loading…
Reference in a new issue