Commit 26fef542 authored by Nicolas Lenz's avatar Nicolas Lenz

Remove Summary type, use pandocs directly

parent a9ecf320
......@@ -35,13 +35,6 @@ save basePath = mapM_ $ \(path, output) -> do
getNavbarMeta :: [Navitem] -> MetaValue
getNavbarMeta navItems = MetaList $ map (\Navitem{..} -> MetaMap $ Map.fromList [("name", MetaString $ unpack navitemName), ("link", MetaString $ unpack navitemLink)]) navItems
data Summary = Summary {
summaryTitle :: MetaValue,
summaryDate :: MetaValue,
summaryLink :: Path Rel File,
summaryContent :: MetaValue
} deriving Eq
read :: (PandocMonad m) => Text -> m Pandoc
read = readMarkdown readerOptions where
readerOptions = def {readerExtensions = pandocExtensions}
......@@ -97,23 +90,16 @@ buildArticles templateArticle templateIndex navbar inputs = do
return (path, contentW)
generateIndex :: Meta -> [(Path Rel File, Pandoc)] -> Pandoc
generateIndex extraMeta = generateIndex' extraMeta . sortOn (Down . summaryDate) . map (uncurry generateSummary) where
generateIndex' :: Meta -> [Summary] -> Pandoc
generateIndex' extraMeta summaries = Pandoc meta [] where
meta = extraMeta <> Meta (Map.fromList [("pagetitle", MetaString "Home"), ("articles", MetaList articles)])
articles = map f summaries
f Summary{..} = MetaMap $ Map.fromList [
("title", summaryTitle),
("date", summaryDate),
("link", MetaString $ toFilePath summaryLink),
("content", summaryContent)]
generateSummary :: Path Rel File -> Pandoc -> Summary
generateSummary path (Pandoc meta body) = Summary
(fromMaybe (MetaString "Untitled") $ lookupMeta "title" meta)
(fromMaybe (MetaString "0000-00-00") $ lookupMeta "date" meta)
([reldir|article|] </> path)
(fromMaybe (MetaBlocks body) $ lookupMeta "abstract" meta)
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
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)]
addMeta :: Meta -> Pandoc -> Pandoc
addMeta (Meta metaMapExtra) (Pandoc (Meta metaMap) blocks) = Pandoc (Meta $ metaMapExtra `Map.union` metaMap) blocks
......@@ -124,7 +110,7 @@ copyFolders Config{..} = do
forM_ folders $ \folder -> copyDirRecur folder ([reldir|out|] </> folder)
compileStylesheet :: IO ()
compileStylesheet = callCommand $ "sassc style/stylesheet.scss out/style/stylesheet.css"
compileStylesheet = callCommand "sassc style/stylesheet.scss out/style/stylesheet.css"
build :: IO ()
build = loadConfig >>= \case
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment