Added URL filter which removes 'index.html'.

This commit is contained in:
Wen Kokke 2020-10-28 12:17:56 +01:00
parent 39c3de6a99
commit 9776956c5e
2 changed files with 21 additions and 7 deletions

View file

@ -4,9 +4,11 @@ module Hakyll.Web.Routes.Permalink
( convertPermalink
, permalinkRoute
, permalinkRouteWithDefault
, stripIndexFile
) where
import Data.List (stripPrefix)
import Data.List.Extra (stripSuffix)
import Data.Maybe (fromMaybe)
import Hakyll
import System.FilePath ((</>))
@ -23,3 +25,8 @@ permalinkRouteWithDefault :: Routes -> Routes
permalinkRouteWithDefault def = metadataRoute $ \metadata ->
maybe def (constRoute . convertPermalink) (lookupString "permalink" metadata)
-- Removes "index.html" from URLs.
stripIndexFile :: String -> String
stripIndexFile = withUrls dir
where
dir link = fromMaybe link (stripSuffix "index.html" link)

View file

@ -176,7 +176,7 @@ main = do
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/page.html" siteSectionContext
>>= loadAndApplyTemplate "templates/default.html" siteSectionContext
>>= relativizeUrls
>>= prettifyUrls
-- Build compiler for literate Agda pages
let pageWithAgdaCompiler :: CommandLineOptions -> Compiler (Item String)
@ -192,7 +192,7 @@ main = do
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/page.html" siteSectionContext
>>= loadAndApplyTemplate "templates/default.html" siteSectionContext
>>= relativizeUrls
>>= prettifyUrls
-- Run Hakyll
--
@ -241,7 +241,7 @@ main = do
<&> writeHTML5With siteWriterOptions
>>= loadAndApplyTemplate "templates/page.html" siteContext
>>= loadAndApplyTemplate "templates/default.html" siteContext
>>= relativizeUrls
>>= prettifyUrls
match "src/**.metadata" $
compile getResourceBody
@ -256,7 +256,7 @@ main = do
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/page.html" siteContext
>>= loadAndApplyTemplate "templates/default.html" siteContext
>>= relativizeUrls
>>= prettifyUrls
match "authors/*.metadata" $
compile getResourceBody
@ -271,7 +271,7 @@ main = do
>>= applyAsTemplate postListContext
>>= loadAndApplyTemplate "templates/page.html" siteContext
>>= loadAndApplyTemplate "templates/default.html" siteContext
>>= relativizeUrls
>>= prettifyUrls
match "posts/*" $ do
route $ setExtension "html"
@ -285,7 +285,7 @@ main = do
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/post.html" postContext
>>= loadAndApplyTemplate "templates/default.html" siteContext
>>= relativizeUrls
>>= prettifyUrls
-- Compile sections using literate Agda
match "src/**.lagda.md" $ do
@ -355,7 +355,7 @@ main = do
match (fromGlob $ "versions" </> v </> "**.html") $ do
route $ gsubRoute "versions/" (const "")
compile $ getResourceBody
>>= relativizeUrls
>>= prettifyUrls
-- Copy other files
match (fromGlob $ "versions" </> v </> "**") $ do
@ -427,3 +427,10 @@ compilePandocTemplate i = do
contentField :: String -> Snapshot -> Context String
contentField key snapshot = field key $ \item ->
itemBody <$> loadSnapshot (itemIdentifier item) snapshot
--------------------------------------------------------------------------------
-- Relativise URLs and strip "index.html" suffixes
--------------------------------------------------------------------------------
prettifyUrls :: Item String -> Compiler (Item String)
prettifyUrls = relativizeUrls <=< withItemBody (return . stripIndexFile)