summaryrefslogtreecommitdiff
path: root/app/Main.hs
blob: ec508d46160f4604b334ad9faa507d54543683ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
module Main where

import Prolog
import Hakyll
import Data.List qualified as L
import Data.Ord (Down (..))

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 Hakyll.Web.Sass
import Text.Jasmine (minify)
import WWW.Base (baseHakyll, domain, myHakyllWriterOptions, myHakyllReaderOptions)
import WWW.Templates (myContext, defaultTemplate)

import GHC.IO.Encoding qualified as E



main :: IO ()
main = do
  E.setLocaleEncoding E.utf8
  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_)

    -- load any snippets
    match "**/_*.html" $ compile getResourceBody

    match "assets/**" $ do
        route $ dropParentRoute 1
        compile copyFileCompiler
    -- match ("www/css/*.scss" .||. "www/css/*.sass") $ do
    --     route $ dropParentRoute 1 `composeRoutes` setExtension "css"
    --     compile $ compressCss <<$>> sassCompiler
    -- match "www/css/*.css" $ do
    --     route $ dropParentRoute 1
    --     compile compressCssCompiler
    -- match "www/js/*.js" $ do
    --     route $ dropParentRoute 1
    --     compile $ minify <<$>> getResourceLBS

    match "www/img/**" $ do
        route $ dropParentRoute 1
        compile copyFileCompiler

    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/index.html" $ do
        route $ dropParentRoute 1
        compile $ do
            getResourceBody >>= applyAsTemplate baseCtxt >>= applyTemplate defaultTemplate baseCtxt

    match "www/research/index.html" $ do
        route $ dropParentRoute 1
        compile $ do
            papers <- loadBody @[Paper String] "data/papers.bib"
            let fixedPapers = L.sortOn Down $ 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 (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

    match "www/links/index.md" $ do
        route $ dropParentRoute 1 `composeRoutes` setExtension ".html"
        compile $ getResourceBody >>= applyAsTemplate baseCtxt >>= myRenderPandoc >>= applyTemplate defaultTemplate baseCtxt

    -- match "www/contact/*.html" $ do
    --     route $ dropParentRoute 1
    --     compile $ getResourceBody >>= applyAsTemplate baseCtxt >>= applyTemplate defaultTemplate baseCtxt
    --
    -- match "www/code/*.html" $ do
    --     route $ dropParentRoute 1
    --     compile $ getResourceBody >>= applyAsTemplate baseCtxt >>= applyTemplate defaultTemplate baseCtxt
    --
    -- match "www/credits/*.html" $ do
    --     route $ dropParentRoute 1
    --     compile $ myPandocCompiler >>= applyTemplate defaultTemplate baseCtxt

    -- compile any other html
    match "www/**/*.html" $ do
        route $ dropParentRoute 1
        compile $ getResourceBody >>= applyTemplate defaultTemplate baseCtxt

    -- just copy anything else hanging around
    match "www/**" $ do
        route idRoute
        compile copyFileCompiler


myPandocCompiler :: Compiler (Item String)
myPandocCompiler = pandocCompilerWith myHakyllReaderOptions myHakyllWriterOptions

myRenderPandoc :: Item String -> Compiler (Item String)
myRenderPandoc = renderPandocWith myHakyllReaderOptions myHakyllWriterOptions