diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2016-03-30 21:32:12 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2016-03-30 21:32:12 +0200 |
commit | bb3f0d3cff573fe20df41b715b787e77d6bc9b40 (patch) | |
tree | 3219ccb94d5112e5bd680c9098c556bf2f8256a1 /web | |
parent | 7d4a83294dc7cc88b0823759364bab39bae56276 (diff) | |
download | hakyll-bb3f0d3cff573fe20df41b715b787e77d6bc9b40.tar.gz |
Add external articles
Diffstat (limited to 'web')
-rw-r--r-- | web/site.hs | 57 | ||||
-rw-r--r-- | web/templates/tutorial-item.html | 1 | ||||
-rw-r--r-- | web/templates/tutorials.html | 36 | ||||
-rw-r--r-- | web/tutorials/external-clean-urls-with-hakyll.md | 6 |
4 files changed, 74 insertions, 26 deletions
diff --git a/web/site.hs b/web/site.hs index a1c2a49..bf84f1e 100644 --- a/web/site.hs +++ b/web/site.hs @@ -1,14 +1,13 @@ -------------------------------------------------------------------------------- {-# 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.Ord (comparing) +import Control.Arrow (second) +import Control.Monad (forM_) +import Data.Char (isDigit) +import Data.List (isPrefixOf, sortBy) +import Data.Monoid ((<>)) +import Data.Ord (comparing) import Hakyll -import System.FilePath (dropTrailingPathSeparator, splitPath) +import System.FilePath (dropTrailingPathSeparator, splitPath) import Text.Pandoc @@ -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" diff --git a/web/templates/tutorial-item.html b/web/templates/tutorial-item.html deleted file mode 100644 index e0d7866..0000000 --- a/web/templates/tutorial-item.html +++ /dev/null @@ -1 +0,0 @@ -<li><a href="$url$">$title$</a> by <em>$author$</em></li> diff --git a/web/templates/tutorials.html b/web/templates/tutorials.html index 36c808c..6bd8351 100644 --- a/web/templates/tutorials.html +++ b/web/templates/tutorials.html @@ -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> diff --git a/web/tutorials/external-clean-urls-with-hakyll.md b/web/tutorials/external-clean-urls-with-hakyll.md new file mode 100644 index 0000000..127a192 --- /dev/null +++ b/web/tutorials/external-clean-urls-with-hakyll.md @@ -0,0 +1,6 @@ +--- +title: Clean URLs with Hakyll +author: Rohan Jain +url: http://www.rohanjain.in/hakyll-clean-urls/ +external: true +--- |