From bb3f0d3cff573fe20df41b715b787e77d6bc9b40 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 30 Mar 2016 21:32:12 +0200 Subject: [PATCH] Add external articles --- web/site.hs | 57 +++++++++++-------- web/templates/tutorial-item.html | 1 - web/templates/tutorials.html | 36 +++++++++++- .../external-clean-urls-with-hakyll.md | 6 ++ 4 files changed, 74 insertions(+), 26 deletions(-) delete mode 100644 web/templates/tutorial-item.html create mode 100644 web/tutorials/external-clean-urls-with-hakyll.md 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 @@ -
  • $title$ by $author$
  • 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 @@

    Tutorials about Hakyll

    Tutorial series

    - +

    Other articles

    In no particular order:

    - + +

    External articles

    +

    In no particular order:

    +

    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 @@

    $$ ghc-pkg unregister hakyll
     $$ cabal update
     $$ cabal install hakyll
    + +

    + Or using stack: +

    +
    $$ stack install hakyll
    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 +---