Commit 0b1bd8a7 authored by Nicolas Lenz's avatar Nicolas Lenz ❄️
Browse files

Use whole source meta in index articles

parent 26fef542
Loading
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -90,16 +90,16 @@ buildArticles templateArticle templateIndex navbar inputs = do
            return (path, contentW)

generateIndex :: Meta -> [(Path Rel File, Pandoc)] -> Pandoc
generateIndex extraMeta = generateIndex' extraMeta . sortOn (Down . (\(_, (Pandoc meta _)) -> lookupMeta "date" meta)) where
    generateIndex' :: Meta -> [(Path Rel File, Pandoc)] -> Pandoc
    generateIndex' extraMeta articles = Pandoc metaOutput [] where
generateIndex extraMeta = generateIndex' . sortOn (Down . (\(_, Pandoc meta _) -> lookupMeta "date" meta)) where
    generateIndex' :: [(Path Rel File, Pandoc)] -> Pandoc
    generateIndex' articles = Pandoc metaOutput [] where
        metaOutput = extraMeta <> Meta (Map.fromList [("pagetitle", MetaString "Home"), ("articles", MetaList articlesOutput)])
        articlesOutput = map f articles
        f (path, Pandoc meta body) = MetaMap $ Map.fromList [
            ("title", fromMaybe (MetaString "Untitled") $ lookupMeta "title" meta),
            ("date", fromMaybe (MetaString "0000-00-00") $ lookupMeta "date" meta),
            ("link", MetaString $ toFilePath $ [reldir|article|] </> path),
            ("content", fromMaybe (MetaBlocks body) $ lookupMeta "abstract" meta)]
        articlesOutput = (uncurry generateIndexMeta) <$> articles

-- | Generates the Pandoc MetaMap for a document for the index page. It contains the meta of the source, the link and the body
generateIndexMeta :: Path Rel File -> Pandoc -> MetaValue
generateIndexMeta path (Pandoc (Meta metaMap) body) = MetaMap $ metaMap
    <> Map.fromList [("link", MetaString $ toFilePath path), ("body", MetaBlocks body)]

addMeta :: Meta -> Pandoc -> Pandoc
addMeta (Meta metaMapExtra) (Pandoc (Meta metaMap) blocks) = Pandoc (Meta $ metaMapExtra `Map.union` metaMap) blocks
@@ -121,7 +121,7 @@ build = loadConfig >>= \case
        templateArticle <- readFileUtf8 configTemplateArticle
        templatePage <- readFileUtf8 configTemplatePage
        templateIndex <- readFileUtf8 configTemplateIndex
        articlesInput <- load [reldir|article|]
        articlesInput <- (\(path, pandoc) -> ([reldir|article|] </> path, pandoc)) <$$> load [reldir|article|]
        pagesInput <- load [reldir|page|]
        articlesOutputE <- runIO (buildArticles templateArticle templateIndex (getNavbarMeta $ configNavbar) articlesInput)
        pagesOutputE <- runIO (buildPages templatePage (getNavbarMeta $ configNavbar) pagesInput)
@@ -132,7 +132,7 @@ build = loadConfig >>= \case
        case outputE of
            Left ex -> fail $ "Error while processing articles: " <> show ex
            Right (indexOutput, articlesOutput, pagesOutput) -> do
                save [reldir|out/article|] articlesOutput
                save [reldir|out|] articlesOutput
                save [reldir|out|] pagesOutput
                writeFileUtf8 "out/index.html" indexOutput
                putStrLn "Success!"
+0 −2
Original line number Diff line number Diff line
module Main where

import ClassyPrelude
import Text.Pandoc (runIO)
import Data.Yaml (decodeFileEither, prettyPrintParseException)
import Build

main :: IO ()