Commit b5714d71 authored by Nicolas Lenz's avatar Nicolas Lenz

Detect active links

parent 528c031b
Pipeline #284 passed with stage
in 2 minutes and 59 seconds
......@@ -11,18 +11,30 @@ import Load
import Save
-- | Generate the Pandoc MetaValue for a navbar from a list of NavItem from a Nebelhorn config.
generateNavbarMeta :: [NavItem] -> MetaValue
generateNavbarMeta navItems = MetaList $ map f navItems where
generateNavbarMeta :: [NavItem] -> Maybe MetaValue -> MetaValue
generateNavbarMeta navItems (Just (MetaString link)) = MetaList $ map f navItems where
f NavItem{..} = MetaMap $ Map.fromList
[("name", MetaString $ unpack navItemName), ("link", MetaString $ unpack navItemLink)]
[ ("name", MetaString $ unpack navItemName)
, ("link", MetaString $ unpack navItemLink)
, ("active", if unpack navItemLink == ("/" <> link) then MetaBool True else MetaBool False)
]
generateNavbarMeta navItems _ = MetaList $ map f navItems where
f NavItem{..} = MetaMap $ Map.fromList
[ ("name", MetaString $ unpack navItemName)
, ("link", MetaString $ unpack navItemLink)
, ("active", MetaBool False)
]
putNavbarPage :: [NavItem] -> Pandoc -> Pandoc
putNavbarPage navItems pandoc@(Pandoc meta _)
= addMeta "navbar" (generateNavbarMeta navItems $ lookupMeta "link" meta) pandoc
-- Puts the navbar into all documents of a Nebelhorn.
putNavbar :: Nebelhorn -> Nebelhorn
putNavbar nebelhorn@Nebelhorn{..}
= nebelhorn{nebelhornArticles = addMeta "navbar" navbar <$> nebelhornArticles,
nebelhornPages = addMeta "navbar" navbar <$> nebelhornPages,
nebelhornIndex = addMeta "navbar" navbar nebelhornIndex} where
navbar = generateNavbarMeta nebelhornNavItems
= nebelhorn{nebelhornArticles = putNavbarPage nebelhornNavItems <$> nebelhornArticles,
nebelhornPages = putNavbarPage nebelhornNavItems <$> nebelhornPages,
nebelhornIndex = putNavbarPage nebelhornNavItems nebelhornIndex}
-- | Gets the previous and next neigbors for each article in the list.
-- This only works if every pandocument has the link meta value set.
......
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