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 #-}
|
||||
import Control.Applicative ((<$>))
|
||||
import Control.Arrow (second)
|
||||
import Control.Monad (forM_)
|
||||
import Data.Char (isDigit)
|
||||
import Data.List (isPrefixOf, partition, sortBy)
|
||||
import Data.Monoid (mappend)
|
||||
import Data.List (isPrefixOf, sortBy)
|
||||
import Data.Monoid ((<>))
|
||||
import Data.Ord (comparing)
|
||||
import Hakyll
|
||||
import System.FilePath (dropTrailingPathSeparator, splitPath)
|
||||
|
@ -53,18 +52,12 @@ main = hakyllWith config $ do
|
|||
create ["tutorials.html"] $ do
|
||||
route idRoute
|
||||
compile $ do
|
||||
tutorials <- loadAll "tutorials/*"
|
||||
itemTpl <- loadBody "templates/tutorial-item.html"
|
||||
let (series, articles) = partitionTutorials $
|
||||
sortBy (comparing itemIdentifier) tutorials
|
||||
|
||||
series' <- applyTemplateList itemTpl defaultContext series
|
||||
articles' <- applyTemplateList itemTpl defaultContext articles
|
||||
tuts <-
|
||||
sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
|
||||
|
||||
let tutorialsCtx =
|
||||
constField "title" "Tutorials" `mappend`
|
||||
constField "series" series' `mappend`
|
||||
constField "articles" articles' `mappend`
|
||||
listField "tutorials" tutorialCtx (return tuts) `mappend`
|
||||
defaultContext
|
||||
|
||||
makeItem ""
|
||||
|
@ -112,9 +105,27 @@ hackage url
|
|||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- | Partition tutorials into tutorial series & other articles
|
||||
partitionTutorials :: [Item a] -> ([Item a], [Item a])
|
||||
partitionTutorials = partition $ \i ->
|
||||
case splitPath (toFilePath $ itemIdentifier i) of
|
||||
[_, (x : _)] -> isDigit x
|
||||
_ -> False
|
||||
data TutorialType = SeriesTutorial | ArticlesTutorial | ExternalTutorial
|
||||
deriving (Eq)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- | 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>
|
||||
<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>
|
||||
<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>
|
||||
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:
|
||||
|
@ -11,3 +38,8 @@
|
|||
<pre><code>$$ ghc-pkg unregister hakyll
|
||||
$$ cabal update
|
||||
$$ 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