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