module Main where import Prolog import Hakyll import Data.List qualified as L import Hakyll.Alias import Hakyll.Util import Data.Alias (AliasMap) import Data.Name (Name (..), Name_) import Data.Person (Person_) import Data.Journal (Journal_) import Data.License (License_) import Data.Paper (Paper (..)) import Hakyll.Aeson (yamlCompiler) import Hakyll.Paper (papersCompiler, mkPaperContext, FieldContext (..)) import Hakyll.TeX.BibTeX (bibtexCompiler) import WWW.Base (baseHakyll, domain, myHakyllWriterOptions, myHakyllReaderOptions) import WWW.Templates (myContext, defaultTemplate) main :: IO () main = baseHakyll domain $ do match "templates/**" $ compile templateCompiler -- match "data/*.bib" $ compile bibtexCompiler match "data/papers.bib" $ compile papersCompiler match "data/people.yaml" $ compile $ yamlCompiler @(AliasMap Name_ Person_) match "data/licenses.yaml" $ compile $ yamlCompiler @(AliasMap StrictText License_) match "data/journals.yaml" $ compile $ yamlCompiler @(AliasMap StrictText Journal_) let baseCtxt :: Context String baseCtxt = fold $ [ myContext , personCtxt "data/people.yaml" , licenseCtxt "data/licenses.yaml" , journalCtxt "data/journals.yaml" ] -- let baseCtxt :: Compiler (Context String) -- baseCtxt = fold <$> sequence -- [ pure myContext -- , personCtxt @StrictText <$> loadBody "data/people.yaml" -- , licenseCtxt @StrictText <$> loadBody "data/licenses.yaml" -- , journalCtxt @StrictText <$> loadBody "data/journals.yaml" -- ] match "www/research/index.html" $ do route $ dropParentRoute 1 compile $ do papers <- loadBody @[Paper String] "data/papers.bib" let fixedPapers = L.reverse $ L.sort $ papers <&> \p -> p { authors = (`filter` authors p) $ flip notElem [ Name "Cox" "Christopher" Nothing , Name "Wells" "Chris" Nothing ] -- Remove me from the author list } getResourceBody >>= applyAsTemplate (mkPaperContext (FieldContext (personCtxt "data/people.yaml") (journalCtxt "data/journals.yaml")) fixedPapers) >>= applyTemplate defaultTemplate baseCtxt match "www/teaching/index.md" $ do route $ dropParentRoute 1 `composeRoutes` setExtension ".html" -- compile $ myPandocCompiler >>= applyAsTemplate baseCtxt >>= applyTemplate defaultTemplate baseCtxt compile $ getResourceBody >>= applyAsTemplate baseCtxt >>= myRenderPandoc >>= applyTemplate defaultTemplate baseCtxt pure () myPandocCompiler :: Compiler (Item String) myPandocCompiler = pandocCompilerWith myHakyllReaderOptions myHakyllWriterOptions myRenderPandoc :: Item String -> Compiler (Item String) myRenderPandoc = renderPandocWith myHakyllReaderOptions myHakyllWriterOptions