Simplify templates.

This commit is contained in:
Justin Hsu
2018-05-07 15:40:05 -04:00
parent 51a44c1f41
commit a11179a6ed
8 changed files with 111 additions and 134 deletions
+21 -33
View File
@@ -15,7 +15,7 @@ config = defaultConfiguration
--------------------------------------------------------------------------------
bibHeaders :: [(String, [String])]
bibHeaders = [ ("draft" , [ "-c", "$type='UNPUBLISHED'" ] ) ,
bibHeaders = [ ("drafts" , [ "-c", "$type='UNPUBLISHED'" ] ) ,
("thesis" , [ "-c", "$type='PHDTHESIS'" ] ) ,
("pubs" , [ "-c", "$type='INPROCEEDINGS' or $type='ARTICLE'" ] ) ]
@@ -70,31 +70,6 @@ main = hakyllWith config $ do
route $ setExtension "css"
compile $ compass
forM_ bibHeaders $ \(nick, flags) ->
create [fromCapture (fromGlob "bibs/*.html") nick] $ do
route idRoute
compile $
let biblioCtx = mconcat
[ field "bibitems" $ return . itemBody ] in do
bibTpl <- loadBody $ fromFilePath "templates/bibitemtpl.html"
(bib2bib flags)
>>= bib2bibParse
>>= applyTemplateList bibTpl bibEntryContext
>>= makeItem
>>= loadAndApplyTemplate (fromFilePath "templates/biblisttpl.html") biblioCtx
>>= relativizeUrls
match (fromGlob "content/biblio.md") $ do
route $ setExtension "html"
compile $ do
let makeBibCtx (nick, _) =
field nick (\_ -> loadBody $ fromFilePath ("bibs/" ++ nick ++ ".html"))
secDiv = defaultHakyllWriterOptions { writerSectionDivs = True }
biblioCtx = mconcat $ map makeBibCtx bibHeaders in do
pandocCompilerWith defaultHakyllReaderOptions secDiv
>>= applyAsTemplate biblioCtx
>>= relativizeUrls
match (fromGlob "content/*.md") $ do
route $ setExtension "html"
compile $ do
@@ -107,14 +82,27 @@ main = hakyllWith config $ do
compile $ do
let loadSec sec = field sec
(\_ -> loadBody (fromFilePath $ "content/" ++ sec ++ ".md"))
mainContext = mconcat $ fmap loadSec contentSections
indexContext =
field "footer" (\_ -> loadBody $ fromFilePath "content/footer.md")
`mappend`
defaultContext
makeBibCtx (nick, _) =
field nick (\_ -> loadBody $ fromFilePath ("bibs/" ++ nick ++ ".html"))
biblioContext = mconcat $ map makeBibCtx bibHeaders
indexContext = mconcat $ fmap loadSec contentSections
footerContext = field "footer" (\_ -> loadBody $ fromFilePath "content/footer.md")
getResourceBody
>>= applyAsTemplate mainContext
>>= loadAndApplyTemplate (fromFilePath "templates/main.html") indexContext
>>= applyAsTemplate (indexContext <> biblioContext <> footerContext <> defaultContext)
>>= relativizeUrls
forM_ bibHeaders $ \(nick, flags) ->
create [fromCapture (fromGlob "bibs/*.html") nick] $ do
route idRoute
compile $
let biblioCtx = mconcat
[ field "bibitems" $ return . itemBody ] in do
bibTpl <- loadBody $ fromFilePath "templates/bibitem.html"
(bib2bib flags)
>>= bib2bibParse
>>= applyTemplateList bibTpl bibEntryContext
>>= makeItem
>>= applyAsTemplate biblioCtx
>>= relativizeUrls
match (fromGlob "templates/*") $ compile templateCompiler