Remove index.html from tag listings
This commit is contained in:
55
src/Main.hs
55
src/Main.hs
@@ -32,7 +32,14 @@ import Hakyll.Core.Rules
|
||||
)
|
||||
import Hakyll.Web.CompressCss (compressCssCompiler)
|
||||
import Hakyll.Web.Html (demoteHeaders, withUrls)
|
||||
import Hakyll.Web.Paginate (buildPaginateWith, paginateContext, paginateEvery, paginateRules)
|
||||
import Hakyll.Web.Paginate
|
||||
( Paginate(..)
|
||||
, PageNumber
|
||||
, buildPaginateWith
|
||||
, paginateContext
|
||||
, paginateEvery
|
||||
, paginateRules
|
||||
)
|
||||
import Hakyll.Web.Pandoc
|
||||
( defaultHakyllReaderOptions
|
||||
, defaultHakyllWriterOptions
|
||||
@@ -61,7 +68,7 @@ import System.FilePath
|
||||
, joinPath
|
||||
, replaceExtension
|
||||
, splitDirectories
|
||||
, takeDirectory
|
||||
, dropFileName
|
||||
)
|
||||
import System.Process (rawSystem)
|
||||
import qualified Network.Wai.Application.Static as Static
|
||||
@@ -80,7 +87,7 @@ configuration = Configuration
|
||||
, tmpDirectory = "./var/cache/tmp"
|
||||
, providerDirectory = "."
|
||||
, ignoreFile = ignoreFile'
|
||||
, watchIgnore = const False
|
||||
, watchIgnore = watchIgnore'
|
||||
, deployCommand = "rsync"
|
||||
, deploySite = deploySite'
|
||||
, inMemoryCache = True
|
||||
@@ -90,6 +97,9 @@ configuration = Configuration
|
||||
, previewSettings = Static.defaultFileServerSettings
|
||||
}
|
||||
where
|
||||
watchIgnore' path
|
||||
| "src" : _ <- splitDirectories path = True
|
||||
| otherwise = False
|
||||
ignoreFile' path = isPrefixOf "." path || path == "var"
|
||||
deploySite' deploymentConfiguration
|
||||
= readFile "deployment.txt"
|
||||
@@ -112,9 +122,7 @@ loadAndApplyLayout layout context item =
|
||||
>>= loadAndApplyTemplate "templates/default.html" context
|
||||
|
||||
createIndex :: Tags -> Rules ()
|
||||
createIndex tags = do
|
||||
paginate <- buildPaginateWith grouper "posts/**" makeId
|
||||
paginateRules paginate $ indexRules paginate
|
||||
createIndex tags = createPaginatedPage indexRules "posts/**" ""
|
||||
where
|
||||
indexRules paginate pageNumber pagePattern = do
|
||||
route idRoute
|
||||
@@ -129,8 +137,6 @@ createIndex tags = do
|
||||
makeItem ""
|
||||
>>= loadAndApplyLayout "blog.html" context
|
||||
>>= cleanIndexUrls
|
||||
makeId 1 = "index.html"
|
||||
makeId pageNumber = fromFilePath $ shows pageNumber ".html"
|
||||
|
||||
localizeMonth :: String -> String
|
||||
localizeMonth "01" = "Januar"
|
||||
@@ -203,7 +209,7 @@ cleanIndexUrls :: Item String -> Compiler (Item String)
|
||||
cleanIndexUrls = return . fmap (withUrls cleanIndex)
|
||||
where
|
||||
cleanIndex url
|
||||
| "/index.html" `isSuffixOf` url = takeDirectory url
|
||||
| "/index.html" `isSuffixOf` url = dropFileName url
|
||||
| otherwise = url
|
||||
|
||||
bibtexCompiler :: Compiler (Item String)
|
||||
@@ -222,13 +228,9 @@ bibtexCompiler = do
|
||||
copyMatchedFiles :: Pattern -> Rules ()
|
||||
copyMatchedFiles = flip match $ route idRoute >> compile copyFileCompiler
|
||||
|
||||
grouper :: [Identifier] -> Rules [[Identifier]]
|
||||
grouper = fmap (paginateEvery 25) . sortRecentFirst
|
||||
|
||||
createTagPage :: Tags -> String -> Pattern -> Rules ()
|
||||
createTagPage tags tagName tagPattern = do
|
||||
paginate <- buildPaginateWith grouper tagPattern makeId
|
||||
paginateRules paginate $ paginateTag paginate
|
||||
createTagPage tags tagName tagPattern
|
||||
= createPaginatedPage paginateTag tagPattern $ "tags/" ++ tagName ++ "/"
|
||||
where
|
||||
paginateTag paginate pageNumber pagePattern = do
|
||||
route withoutRootRoute
|
||||
@@ -238,12 +240,25 @@ createTagPage tags tagName tagPattern = do
|
||||
<> constField "title" tagName
|
||||
<> paginateContext paginate pageNumber
|
||||
<> flevumContext tags
|
||||
|
||||
makeItem ""
|
||||
>>= loadAndApplyLayout "tag.html" context
|
||||
tagBase = fromFilePath . (("tags/" ++ tagName) ++)
|
||||
makeId 1 = tagBase "/index.html"
|
||||
makeId pageNumber = tagBase ('/' : shows pageNumber ".html")
|
||||
>>= cleanIndexUrls
|
||||
|
||||
createPaginatedPage
|
||||
:: (Paginate -> PageNumber -> Pattern -> Rules ())
|
||||
-> Pattern
|
||||
-> String
|
||||
-> Rules ()
|
||||
createPaginatedPage rulesBuilder pagePattern prefix =
|
||||
buildPaginateWith grouper pagePattern makePagePath >>= paginateRules'
|
||||
where
|
||||
paginateRules' paginate = paginateRules paginate $ rulesBuilder paginate
|
||||
makePagePath = \case
|
||||
1 -> makePageFileName "index.html"
|
||||
pageNumber -> makePageFileName $ shows pageNumber ".html"
|
||||
makePageFileName = fromFilePath . (prefix ++)
|
||||
grouper :: [Identifier] -> Rules [[Identifier]]
|
||||
grouper = fmap (paginateEvery 25) . sortRecentFirst
|
||||
|
||||
--
|
||||
-- Hakyll rules.
|
||||
@@ -261,7 +276,6 @@ rules = do
|
||||
route withoutRootRoute
|
||||
compile $ bibtexCompiler
|
||||
>>= loadAndApplyLayout "page.html" contextWithTags
|
||||
>>= cleanIndexUrls
|
||||
|
||||
-- Categories.
|
||||
tagsRules tags $ createTagPage tags
|
||||
@@ -272,7 +286,6 @@ rules = do
|
||||
compile $ bibtexCompiler
|
||||
>>= saveSnapshot "content"
|
||||
>>= loadAndApplyLayout "post.html" (postCtx tags)
|
||||
>>= cleanIndexUrls
|
||||
|
||||
match "assets/bibliography/*.bib" $ compile biblioCompiler
|
||||
match "assets/bibliography/*.csl" $ compile cslCompiler
|
||||
|
||||
Reference in New Issue
Block a user