summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web.hs
blob: 92cdab510ae86066bc0d0d2ebdd401b689cedf67 (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
-- | Module exporting commonly used web-related functions
--
module Hakyll.Web
    ( defaultPageRead
    , defaultTemplateRead
    , defaultRelativizeUrls
    , defaultCopyFile
    , defaultCompressCss
    ) where

import Prelude hiding (id)
import Control.Category (id)
import Control.Arrow (arr, (>>>), (>>^), (&&&))

import Text.Hamlet (HamletSettings, defaultHamletSettings)

import Hakyll.Core.Compiler
import Hakyll.Core.Writable
import Hakyll.Core.Identifier
import Hakyll.Web.Page
import Hakyll.Web.Pandoc
import Hakyll.Web.Template
import Hakyll.Web.Template.Read
import Hakyll.Web.RelativizeUrls
import Hakyll.Web.Util.String
import Hakyll.Web.CompressCss

defaultPageRead :: Compiler () (Page String)
defaultPageRead = cached "Hakyll.Web.defaultPageRead" $
    pageRead >>> addDefaultFields >>> arr applySelf >>> pageRenderPandoc

defaultRelativizeUrls :: Compiler (Page String) (Page String)
defaultRelativizeUrls = getRoute &&& id >>^ uncurry relativize
  where
    relativize Nothing = id
    relativize (Just r) = fmap (relativizeUrls $ toSiteRoot r)

defaultTemplateRead :: Compiler () Template
defaultTemplateRead = cached "Hakyll.Web.defaultTemplateRead" $
    getResourceString >>^ readTemplate

defaultHamletTemplateRead :: Compiler () Template
defaultHamletTemplateRead = defaultHamletTemplateReadWith defaultHamletSettings

defaultHamletTemplateReadWith :: HamletSettings -> Compiler () Template
defaultHamletTemplateReadWith settings =
    cached "Hakyll.Web.defaultHamletTemplateReadWith" $
        getResourceString >>^ readHamletTemplateWith settings

defaultCopyFile :: Compiler () CopyFile
defaultCopyFile = getIdentifier >>^ CopyFile . toFilePath

defaultCompressCss :: Compiler () String
defaultCompressCss = getResourceString >>^ compressCss