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

Shorten all lines to 100 chars

parent f325deaa
Loading
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -24,20 +24,24 @@ mapMT = mapM . mapM

-- | Generate the Pandoc MetaValue for a navbar from a list of NavItem from a Nebelhorn config.
generateNavbarMeta :: [NavItem] -> MetaValue
generateNavbarMeta navItems = MetaList $ map (\NavItem{..} -> MetaMap $ Map.fromList [("name", MetaString $ unpack navItemName), ("link", MetaString $ unpack navItemLink)]) navItems
generateNavbarMeta navItems = MetaList $ map f navItems where
    f NavItem{..} = MetaMap $ Map.fromList
        [("name", MetaString $ unpack navItemName), ("link", MetaString $ unpack navItemLink)]

-- | Reads in a single document to a Pandoc value using an extra Meta.
read :: (PandocMonad m, MonadIO m) => Meta -> (Path Rel File, Text) -> m (Path Rel File, Pandoc)
read extraMeta (path, content) = do
    contentR <- read' content
    newPath <- liftIO $ setFileExtension ".html" path  -- TODO: This should really be done without IO...
    -- TODO: This should really be done without IO...
    newPath <- liftIO $ setFileExtension ".html" path
    return (newPath, addMeta extraMeta contentR)
    where read' = readMarkdown $ def {readerExtensions = pandocExtensions}

-- | Writes a single Pandoc document to HTML5 output using a template.
write :: (PandocMonad m) => Text -> Pandoc -> m Text
write template = writeHtml5String writerOptions where
    writerOptions = def {writerExtensions = pandocExtensions, writerTemplate = Just $ unpack template}
    writerOptions = def
        {writerExtensions = pandocExtensions, writerTemplate = Just $ unpack template}

-- | Builds a list of pages, using a MetaValue for the navbar, from raw markdown to HTML5.
buildPages :: (PandocMonad m, MonadIO m)
@@ -66,18 +70,19 @@ buildArticles navbar inputs = do

    return (indexOutput, articlesOutput)

    where
        extraMeta = Meta $ Map.fromList [("navbar", navbar)]
    where extraMeta = Meta $ Map.fromList [("navbar", navbar)]

-- | Generate an index page from a list of Articles.
generateIndex :: Meta -> [(Path Rel File, Pandoc)] -> Pandoc
generateIndex extraMeta = generateIndex' . sort where
    sort = sortOn (Down . (\(_, Pandoc meta _) -> lookupMeta "date" meta))
    generateIndex' articles = Pandoc metaOutput [] where
        metaOutput = extraMeta <> Meta (Map.fromList [("pagetitle", MetaString "Home"), ("articles", MetaList articlesOutput)])
        articlesOutput = (uncurry generateIndexMeta) <$> articles
        metaOutput = extraMeta <> Meta (Map.fromList
            [("pagetitle", MetaString "Home"), ("articles", MetaList articlesOutput)])
        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.
-- | 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)]