links in output html are not updated automatically via Hakyll’s pandoc compiler with modified route.
For this reason, it is necessary to manually rewrite the link in markdown.
withUrls is a function in Hakyll can apply String->String convert in each URLs.
so it can be used to create a specific parser.
below is usage example.
parseInnerLinks: applyparseInnerLinkeach URLs bywithUrls.parseInnerLink: applyparsePostLinkonly URL has prefix/posts
parseInnerLinks :: Item String -> Compiler (Item String)
parseInnerLinks = pure . fmap (withUrls parseInnerLink)
parseInnerLink :: String -> String
parseInnerLink url
| isExternal url = url
| "/posts" `L.isPrefixOf` url =
parsePostLink url
| otherwise =
urlparsePostLink: it convert URL which include#(section link). convert URL before#and re-concat URL after#.convPostUrl: applyString->Stringconvert in same as usedRoutedelete/which head of URL bytailto getFilepath.
parsePostLink :: String -> String
parsePostLink url = case map T.unpack . T.splitOn "#" $ T.pack url of
[base] -> addHtml . convPostUrl $ base
[base, section] -> (++ section) . (++ "#") . addHtml . convPostUrl $ base
convPostUrl :: String -> String
convPostUrl url = (++) "/" . getLangPath . fromFilePath $ tail url
addHtml :: String -> String
addHtml = (++ ".html")below is example of usage parseInnerLinks.
pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= parseInnerLinks
>>= relativizeUrls