on 3ebdc76 help sign in
.circleci/config.ymldeleted−19
since splitsnapshots
unifiedsplit
@@ -1,19 +0,0 @@
1−version: 2
2−jobs:
3− build:
4− docker:
5− - image: 'fpco/stack-build:latest'
6− steps:
7− - checkout
8− - restore_cache:
9− key: 'v3-hakyll-{{ arch }}-{{ .Branch }}'
10− - run:
11− # We set jobs to 1 here because that prevents Out-Of-Memory exceptions
12− # while compiling dependencies.
13− name: 'Install dependencies'
14− command: '.circleci/tickle.sh stack build --test --copy-bins --jobs=1'
15− - save_cache:
16− key: 'v3-hakyll-{{ arch }}-{{ .Branch }}-{{ .Revision }}'
17− paths:
18− - '~/.stack-work'
19− - '~/.stack'
.circleci/tickle.shdeleted−24
@@ -1,24 +0,0 @@
1−#!/bin/bash
2−set -o nounset -o errexit -o pipefail
3−
4−function tickle() {
5− while [ true ]; do
6− echo "[$(date +%H:%M:%S)] Tickling..."
7− sleep 60
8− done
9−}
10−
11−echo "Forking tickle process..."
12−tickle &
13−TICKLE_PID=$!
14−
15−echo "Forking build process..."
16−eval $@ &
17−BUILD_PID=$!
18−
19−echo "Waiting for build thread ($BUILD_PID)..."
20−wait $BUILD_PID
21−
22−echo "Killing tickle thread ($TICKLE_PID)..."
23−kill $TICKLE_PID
24−echo "All done!"
.ghci+2−1
@@ -1 +1,2 @@
1−:set -isrc -itests -idist/build/autogen -DPREVIEW_SERVER
1+:set -isrc -isrc-interval -itests -idist/build/autogen -DPREVIEW_SERVER
2+:set -optP-include -optPdist/build/autogen/cabal_macros.h
.gitignore−3
@@ -23,6 +23,3 @@ web/_cache
23web/_site
23web/_site
24web/site
24web/site
25web/reference
25web/reference
26−
27−# This is generated from the CHANGELOG
28−web/releases.markdown
.travis.ymlnew file+2
@@ -0,0 +1,2 @@
1+language: haskell
2+ghc: '7.10'
CODE_OF_CONDUCT.mddeleted−45
@@ -1,45 +0,0 @@
1−# Contributor Covenant Code of Conduct
2−
3−## Our Pledge
4−
5−In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6−
7−## Our Standards
8−
9−Examples of behavior that contributes to creating a positive environment include:
10−* Using welcoming and inclusive language
11−* Being respectful of differing viewpoints and experiences
12−* Gracefully accepting constructive criticism
13−* Focusing on what is best for the community
14−* Showing empathy towards other community members
15−
16−Examples of unacceptable behavior by participants include:
17−
18−* The use of sexualized language or imagery and unwelcome sexual attention or advances
19−* Trolling, insulting/derogatory comments, and personal or political attacks
20−* Public or private harassment
21−* Publishing others' private information, such as a physical or electronic address, without explicit permission
22−* Other conduct which could reasonably be considered inappropriate in a professional setting
23−
24−## Our Responsibilities
25−
26−Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
27−
28−Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
29−
30−## Scope
31−
32−This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
33−
34−## Enforcement
35−
36−Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by [contacting the project team at m@jaspervdj.be](mailto:m@jaspervdj.be). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
37−
38−Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
39−
40−## Attribution
41−
42−This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
43−
44−[homepage]: http://contributor-covenant.org
45−[version]: http://contributor-covenant.org/version/1/4/
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2009 - 2017, Jasper Van der Jeugt
1+Copyright (c) 2009, Jasper Van der Jeugt
2 
2 
3All rights reserved.
3All rights reserved.
4 
4 
Makefile+6−6
@@ -1,9 +1,9 @@
1−PACKAGE="$(shell stack list-dependencies --separator='-' | grep hakyll)"
2−LOCAL_DOC_ROOT="$(shell stack path --local-doc-root)"
3−
4# Generate the docs and copy them to the website dir
1# Generate the docs and copy them to the website dir
5haddock:
2haddock:
6− stack build --haddock --no-haddock-deps
3+ cabal haddock --hyperlink-source
7− rsync -r "$(LOCAL_DOC_ROOT)/$(PACKAGE)/" web/reference/
4+ rm -rf web/reference/
5+ cp -r dist/doc/html/hakyll/ web/reference/
8
6
9−.PHONY: haddock
7+# Run the tests
8+test:
9+ runghc -isrc -itests tests/TestSuite.hs
README.markdown+1−1
@@ -1,6 +1,6 @@
1# hakyll
1# hakyll
2
2
3−[![Build Status](https://img.shields.io/circleci/project/github/jaspervdj/hakyll.svg)](https://circleci.com/gh/jaspervdj/hakyll)
3+[![Build Status](https://img.shields.io/travis/jaspervdj/hakyll.svg)](http://travis-ci.org/jaspervdj/hakyll)
4
4
5Hakyll is a static site generator library in Haskell. More information
5Hakyll is a static site generator library in Haskell. More information
6(including a tutorial) can be found on
6(including a tutorial) can be found on
data/example/css/default.css+37−122
@@ -1,141 +1,56 @@
1−html {
1+body {
2+ color: black;
2− font-size: 62.5%;
3+ font-size: 16px;
4+ margin: 0px auto 0px auto;
5+ width: 600px;
3}
6}
4
7
5−body {
8+div#header {
6− font-size: 1.6rem;
9+ border-bottom: 2px solid black;
7− color: #000;
10+ margin-bottom: 30px;
11+ padding: 12px 0px 12px 0px;
8}
12}
9
13
10−header {
14+div#logo a {
11− border-bottom: 0.2rem solid #000;
15+ color: black;
16+ float: left;
17+ font-size: 18px;
18+ font-weight: bold;
19+ text-decoration: none;
12}
20}
13
21
14−nav {
22+div#header #navigation {
15− text-align: right;
23+ text-align: right;
16}
24}
17
25
18−nav a {
26+div#header #navigation a {
27+ color: black;
19− font-size: 1.8rem;
28+ font-size: 18px;
20− font-weight: bold;
29+ font-weight: bold;
21− color: black;
30+ margin-left: 12px;
22− text-decoration: none;
31+ text-decoration: none;
23− text-transform: uppercase;
32+ text-transform: uppercase;
24}
33}
25
34
26−footer {
35+div#footer {
27− margin-top: 3rem;
28− padding: 1.2rem 0;
29− border-top: 0.2rem solid #000;
36+ border-top: solid 2px black;
30− font-size: 1.2rem;
31− color: #555;
37+ color: #555;
38+ font-size: 12px;
39+ margin-top: 30px;
40+ padding: 12px 0px 12px 0px;
41+ text-align: right;
32}
42}
33
43
34h1 {
44h1 {
35− font-size: 2.4rem;
45+ font-size: 24px;
36}
46}
37
47
38h2 {
48h2 {
39− font-size: 2rem;
40−}
41−
42−article .header {
43− font-size: 1.4rem;
44− font-style: italic;
45− color: #555;
46−}
47−
48−.logo a {
49− font-weight: bold;
50− color: #000;
51− text-decoration: none;
52−}
53−
54−@media (max-width: 319px) {
55− body {
56− width: 90%;
57− margin: 0;
58− padding: 0 5%;
59− }
60− header {
61− margin: 4.2rem 0;
62− }
63− nav {
64− margin: 0 auto 3rem;
65− text-align: center;
66− }
67− footer {
68− text-align: center;
69− }
70− .logo {
71− text-align: center;
72− margin: 1rem auto 3rem;
73− }
74− .logo a {
75− font-size: 2.4rem;
49+ font-size: 20px;
76− }
77− nav a {
78− display: block;
79− line-height: 1.6;
80− }
81−}
82−
83−@media (min-width: 320px) {
84− body {
85− width: 90%;
86− margin: 0;
87− padding: 0 5%;
88− }
89− header {
90− margin: 4.2rem 0;
91− }
92− nav {
93− margin: 0 auto 3rem;
94− text-align: center;
95− }
96− footer {
97− text-align: center;
98− }
99− .logo {
100− text-align: center;
101− margin: 1rem auto 3rem;
102− }
103− .logo a {
104− font-size: 2.4rem;
105− }
106− nav a {
107− display: inline;
108− margin: 0 0.6rem;
109− }
110}
50}
111
51
112−@media (min-width: 640px) {
52+div.info {
113− body {
53+ color: #555;
114− width: 60rem;
115− margin: 0 auto;
116− padding: 0;
117− }
118− header {
119− margin: 0 0 3rem;
120− padding: 1.2rem 0;
121− }
122− nav {
123− margin: 0;
124− text-align: right;
125− }
126− nav a {
127− margin: 0 0 0 1.2rem;
128− display: inline;
129− }
130− footer {
131− text-align: right;
132− }
133− .logo {
134− margin: 0;
135− text-align: left;
136− }
137− .logo a {
138− float: left;
139− font-size: 1.8rem;
54+ font-size: 14px;
140− }
55+ font-style: italic;
141}
56}
data/example/templates/default.html+16−16
@@ -1,33 +1,33 @@
1−<!doctype html>
1+<?xml version="1.0" encoding="UTF-8"?>
2−<html lang="en">
2+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
5 <head>
4− <meta charset="utf-8">
6+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5− <meta http-equiv="x-ua-compatible" content="ie=edge">
6− <meta name="viewport" content="width=device-width, initial-scale=1">
7 <title>My Hakyll Blog - $title$</title>
7 <title>My Hakyll Blog - $title$</title>
8− <link rel="stylesheet" href="/css/default.css" />
8+ <link rel="stylesheet" type="text/css" href="/css/default.css" />
9 </head>
9 </head>
10 <body>
10 <body>
11− <header>
11+ <div id="header">
12− <div class="logo">
12+ <div id="logo">
13 <a href="/">My Hakyll Blog</a>
13 <a href="/">My Hakyll Blog</a>
14 </div>
14 </div>
15− <nav>
15+ <div id="navigation">
16 <a href="/">Home</a>
16 <a href="/">Home</a>
17 <a href="/about.html">About</a>
17 <a href="/about.html">About</a>
18 <a href="/contact.html">Contact</a>
18 <a href="/contact.html">Contact</a>
19 <a href="/archive.html">Archive</a>
19 <a href="/archive.html">Archive</a>
20− </nav>
20+ </div>
21− </header>
21+ </div>
22
22
23− <main role="main">
23+ <div id="content">
24 <h1>$title$</h1>
24 <h1>$title$</h1>
25− $body$
26− </main>
27
25
26+ $body$
27+ </div>
28− <footer>
28+ <div id="footer">
29 Site proudly generated by
29 Site proudly generated by
30 <a href="http://jaspervdj.be/hakyll">Hakyll</a>
30 <a href="http://jaspervdj.be/hakyll">Hakyll</a>
31− </footer>
31+ </div>
32 </body>
32 </body>
33</html>
33</html>
data/example/templates/post.html+8−11
@@ -1,11 +1,8 @@
1−<article>
1+<div class="info">
2− <section class="header">
3− Posted on $date$
2+ Posted on $date$
4− $if(author)$
3+ $if(author)$
5− by $author$
4+ by $author$
6− $endif$
5+ $endif$
7− </section>
6+</div>
8− <section>
7+
9− $body$
8+$body$
10− </section>
11−</article>
hakyll.cabal+126−146
@@ -1,5 +1,5 @@
1Name: hakyll
1Name: hakyll
2−Version: 4.13.0.0
2+Version: 4.7.5.2
3
3
4Synopsis: A static website compiler library
4Synopsis: A static website compiler library
5Description:
5Description:
@@ -37,7 +37,7 @@ License: BSD3
37License-File: LICENSE
37License-File: LICENSE
38Category: Web
38Category: Web
39
39
40−Cabal-Version: >= 1.10
40+Cabal-Version: >= 1.8
41Build-Type: Simple
41Build-Type: Simple
42Data-Dir: data
42Data-Dir: data
43
43
@@ -56,28 +56,19 @@ Data-files:
56 example/index.html
56 example/index.html
57 example/about.rst
57 example/about.rst
58 example/contact.markdown
58 example/contact.markdown
59+ templates/atom-item.xml
60+ templates/atom.xml
61+ templates/rss-item.xml
62+ templates/rss.xml
59
63
60Extra-source-files:
64Extra-source-files:
61− CHANGELOG.md
62 tests/data/example.md
65 tests/data/example.md
63 tests/data/example.md.metadata
66 tests/data/example.md.metadata
64 tests/data/images/favicon.ico
67 tests/data/images/favicon.ico
65− tests/data/just-meta.html
66− tests/data/just-meta.html.out
67− tests/data/partial-helper.html
68− tests/data/partial.html
69− tests/data/partial.html.out
70 tests/data/posts/2010-08-26-birthday.md
68 tests/data/posts/2010-08-26-birthday.md
71− tests/data/posts/2018-09-26.md
72 tests/data/russian.md
69 tests/data/russian.md
73− tests/data/strip.html
74− tests/data/strip.html.out
75 tests/data/template.html
70 tests/data/template.html
76 tests/data/template.html.out
71 tests/data/template.html.out
77− data/templates/atom-item.xml
78− data/templates/atom.xml
79− data/templates/rss-item.xml
80− data/templates/rss.xml
81
72
82Source-Repository head
73Source-Repository head
83 Type: git
74 Type: git
@@ -95,43 +86,23 @@ Flag checkExternal
95 Description: Include external link checking
86 Description: Include external link checking
96 Default: True
87 Default: True
97
88
98−Flag buildWebsite
99− Description: Build the hakyll website
100− Default: False
101− Manual: True
102−
103−Flag usePandoc
104− Description: Include Pandoc support
105− Default: True
106− Manual: True
107−
108Library
89Library
109− Ghc-Options: -Wall
90+ Ghc-Options: -Wall
110− Hs-Source-Dirs: lib
91+ Hs-Source-Dirs: src
111− Default-language: Haskell2010
112
92
113 Exposed-Modules:
93 Exposed-Modules:
114 Hakyll
94 Hakyll
115− Hakyll.Commands
116 Hakyll.Core.Compiler
95 Hakyll.Core.Compiler
117− Hakyll.Core.Compiler.Internal
118 Hakyll.Core.Configuration
96 Hakyll.Core.Configuration
119 Hakyll.Core.Dependencies
97 Hakyll.Core.Dependencies
120 Hakyll.Core.File
98 Hakyll.Core.File
121 Hakyll.Core.Identifier
99 Hakyll.Core.Identifier
122 Hakyll.Core.Identifier.Pattern
100 Hakyll.Core.Identifier.Pattern
123 Hakyll.Core.Item
101 Hakyll.Core.Item
124− Hakyll.Core.Logger
125 Hakyll.Core.Metadata
102 Hakyll.Core.Metadata
126− Hakyll.Core.Provider
127− Hakyll.Core.Provider.Metadata
128 Hakyll.Core.Routes
103 Hakyll.Core.Routes
129 Hakyll.Core.Rules
104 Hakyll.Core.Rules
130− Hakyll.Core.Rules.Internal
131− Hakyll.Core.Runtime
132− Hakyll.Core.Store
133 Hakyll.Core.UnixFilter
105 Hakyll.Core.UnixFilter
134− Hakyll.Core.Util.File
135 Hakyll.Core.Util.String
106 Hakyll.Core.Util.String
136 Hakyll.Core.Writable
107 Hakyll.Core.Writable
137 Hakyll.Main
108 Hakyll.Main
@@ -139,67 +110,76 @@ Library
139 Hakyll.Web.Feed
110 Hakyll.Web.Feed
140 Hakyll.Web.Html
111 Hakyll.Web.Html
141 Hakyll.Web.Html.RelativizeUrls
112 Hakyll.Web.Html.RelativizeUrls
142− Hakyll.Web.Paginate
113+ Hakyll.Web.Pandoc
143− Hakyll.Web.Redirect
114+ Hakyll.Web.Pandoc.Biblio
115+ Hakyll.Web.Pandoc.FileType
144 Hakyll.Web.Tags
116 Hakyll.Web.Tags
117+ Hakyll.Web.Paginate
145 Hakyll.Web.Template
118 Hakyll.Web.Template
146− Hakyll.Web.Template.Context
147 Hakyll.Web.Template.Internal
119 Hakyll.Web.Template.Internal
148− Hakyll.Web.Template.Internal.Element
120+ Hakyll.Web.Template.Context
149− Hakyll.Web.Template.Internal.Trim
150 Hakyll.Web.Template.List
121 Hakyll.Web.Template.List
151
122
152 Other-Modules:
123 Other-Modules:
153 Data.List.Extended
124 Data.List.Extended
154 Data.Yaml.Extended
125 Data.Yaml.Extended
155 Hakyll.Check
126 Hakyll.Check
127+ Hakyll.Commands
128+ Hakyll.Core.Compiler.Internal
156 Hakyll.Core.Compiler.Require
129 Hakyll.Core.Compiler.Require
157− Hakyll.Core.Identifier.Pattern.Internal
158 Hakyll.Core.Item.SomeItem
130 Hakyll.Core.Item.SomeItem
131+ Hakyll.Core.Logger
132+ Hakyll.Core.Provider
159 Hakyll.Core.Provider.Internal
133 Hakyll.Core.Provider.Internal
134+ Hakyll.Core.Provider.Metadata
160 Hakyll.Core.Provider.MetadataCache
135 Hakyll.Core.Provider.MetadataCache
136+ Hakyll.Core.Rules.Internal
137+ Hakyll.Core.Runtime
138+ Hakyll.Core.Store
139+ Hakyll.Core.Util.File
161 Hakyll.Core.Util.Parser
140 Hakyll.Core.Util.Parser
141+ Hakyll.Web.Pandoc.Binary
162 Paths_hakyll
142 Paths_hakyll
163
143
164 Build-Depends:
144 Build-Depends:
165− base >= 4.8 && < 5,
145+ base >= 4.8 && < 5,
166− binary >= 0.5 && < 0.10,
146+ binary >= 0.5 && < 0.8,
167− blaze-html >= 0.5 && < 0.10,
147+ blaze-html >= 0.5 && < 0.9,
168− blaze-markup >= 0.5.1 && < 0.9,
148+ blaze-markup >= 0.5.1 && < 0.8,
169− bytestring >= 0.9 && < 0.11,
149+ bytestring >= 0.9 && < 0.11,
150+ cmdargs >= 0.10 && < 0.11,
170− containers >= 0.3 && < 0.7,
151+ containers >= 0.3 && < 0.6,
171− cryptohash >= 0.7 && < 0.12,
152+ cryptohash >= 0.7 && < 0.12,
172− data-default >= 0.4 && < 0.8,
153+ data-default >= 0.4 && < 0.6,
173− deepseq >= 1.3 && < 1.5,
154+ deepseq >= 1.3 && < 1.5,
174− directory >= 1.0 && < 1.4,
155+ directory >= 1.0 && < 1.3,
175− file-embed >= 0.0.10.1 && < 0.0.12,
176− filepath >= 1.0 && < 1.5,
156+ filepath >= 1.0 && < 1.5,
177− lrucache >= 1.1.1 && < 1.3,
157+ lrucache >= 1.1.1 && < 1.3,
178− mtl >= 1 && < 2.3,
158+ mtl >= 1 && < 2.3,
179− network-uri >= 2.6 && < 2.7,
159+ network >= 2.6 && < 2.7,
180− optparse-applicative >= 0.12 && < 0.15,
160+ network-uri >= 2.6 && < 2.7,
161+ pandoc >= 1.14 && < 1.18,
162+ pandoc-citeproc >= 0.4 && < 0.10,
181− parsec >= 3.0 && < 3.2,
163+ parsec >= 3.0 && < 3.2,
182− process >= 1.6 && < 1.7,
164+ process >= 1.0 && < 1.3,
183− random >= 1.0 && < 1.2,
165+ random >= 1.0 && < 1.2,
166+ regex-base >= 0.93 && < 0.94,
184− regex-tdfa >= 1.1 && < 1.3,
167+ regex-tdfa >= 1.1 && < 1.3,
185− resourcet >= 1.1 && < 1.3,
168+ resourcet >= 1.1 && < 1.2,
186− scientific >= 0.3.4 && < 0.4,
187− tagsoup >= 0.13.1 && < 0.15,
169+ tagsoup >= 0.13.1 && < 0.14,
188− template-haskell >= 2.14 && < 2.15,
189− text >= 0.11 && < 1.3,
170+ text >= 0.11 && < 1.3,
190− time >= 1.8 && < 1.10,
171+ time >= 1.4 && < 1.6,
191− time-locale-compat >= 0.1 && < 0.2,
172+ time-locale-compat >= 0.1 && < 0.2,
192− unordered-containers >= 0.2 && < 0.3,
173+ unordered-containers >= 0.2 && < 0.3,
193− vector >= 0.11 && < 0.13,
174+ vector >= 0.11 && < 0.12,
194− yaml >= 0.8.11 && < 0.12
175+ yaml >= 0.8 && < 0.9
195
176
196 If flag(previewServer)
177 If flag(previewServer)
197 Build-depends:
178 Build-depends:
198− wai >= 3.2 && < 3.3,
179+ snap-core >= 0.6 && < 0.10,
199− warp >= 3.2 && < 3.3,
180+ snap-server >= 0.6 && < 0.10,
200− wai-app-static >= 3.1 && < 3.2,
201− http-types >= 0.9 && < 0.13,
202− fsnotify >= 0.2 && < 0.4
181+ fsnotify >= 0.2 && < 0.3,
182+ system-filepath >= 0.4.6 && <= 0.5
203 Cpp-options:
183 Cpp-options:
204 -DPREVIEW_SERVER
184 -DPREVIEW_SERVER
205 Other-modules:
185 Other-modules:
@@ -208,7 +188,8 @@ Library
208
188
209 If flag(watchServer)
189 If flag(watchServer)
210 Build-depends:
190 Build-depends:
211− fsnotify >= 0.2 && < 0.4
191+ fsnotify >= 0.2 && < 0.3,
192+ system-filepath >= 0.4.6 && <= 0.5
212 Cpp-options:
193 Cpp-options:
213 -DWATCH_SERVER
194 -DWATCH_SERVER
214 Other-modules:
195 Other-modules:
@@ -216,31 +197,16 @@ Library
216
197
217 If flag(checkExternal)
198 If flag(checkExternal)
218 Build-depends:
199 Build-depends:
219− http-conduit >= 2.2 && < 2.4,
200+ http-conduit >= 2.1 && < 2.2,
220− http-types >= 0.7 && < 0.13
201+ http-types >= 0.7 && < 0.10
221 Cpp-options:
202 Cpp-options:
222 -DCHECK_EXTERNAL
203 -DCHECK_EXTERNAL
223
204
224− If flag(usePandoc)
225− Exposed-Modules:
226− Hakyll.Web.Pandoc
227− Hakyll.Web.Pandoc.Biblio
228− Hakyll.Web.Pandoc.FileType
229− Other-Modules:
230− Hakyll.Web.Pandoc.Binary
231− Build-Depends:
232− pandoc >= 2.0.5 && < 2.8,
233− pandoc-citeproc >= 0.14 && < 0.17
234− Cpp-options:
235− -DUSE_PANDOC
236−
237Test-suite hakyll-tests
205Test-suite hakyll-tests
238− Type: exitcode-stdio-1.0
206+ Type: exitcode-stdio-1.0
239− Hs-source-dirs: tests
207+ Hs-source-dirs: src tests
240− Main-is: TestSuite.hs
208+ Main-is: TestSuite.hs
241− Ghc-options: -Wall -threaded
209+ Ghc-options: -Wall
242− Default-language: Haskell2010
243−
244 Other-modules:
210 Other-modules:
245 Hakyll.Core.Dependencies.Tests
211 Hakyll.Core.Dependencies.Tests
246 Hakyll.Core.Identifier.Tests
212 Hakyll.Core.Identifier.Tests
@@ -252,76 +218,90 @@ Test-suite hakyll-tests
252 Hakyll.Core.Store.Tests
218 Hakyll.Core.Store.Tests
253 Hakyll.Core.UnixFilter.Tests
219 Hakyll.Core.UnixFilter.Tests
254 Hakyll.Core.Util.String.Tests
220 Hakyll.Core.Util.String.Tests
255− Hakyll.Web.CompressCss.Tests
256 Hakyll.Web.Html.RelativizeUrls.Tests
221 Hakyll.Web.Html.RelativizeUrls.Tests
257 Hakyll.Web.Html.Tests
222 Hakyll.Web.Html.Tests
258− Hakyll.Web.Tags.Tests
223+ Hakyll.Web.Pandoc.FileType.Tests
259 Hakyll.Web.Template.Context.Tests
224 Hakyll.Web.Template.Context.Tests
260 Hakyll.Web.Template.Tests
225 Hakyll.Web.Template.Tests
261 TestSuite.Util
226 TestSuite.Util
262
227
263 Build-Depends:
228 Build-Depends:
264− hakyll,
229+ HUnit >= 1.2 && < 1.4,
265− QuickCheck >= 2.8 && < 2.14,
230+ QuickCheck >= 2.4 && < 2.9,
266− tasty >= 0.11 && < 1.3,
231+ test-framework >= 0.4 && < 0.9,
267− tasty-hunit >= 0.9 && < 0.11,
232+ test-framework-hunit >= 0.3 && < 0.4,
268− tasty-quickcheck >= 0.8 && < 0.11,
233+ test-framework-quickcheck2 >= 0.3 && < 0.4,
269 -- Copy pasted from hakyll dependencies:
234 -- Copy pasted from hakyll dependencies:
270− base >= 4.8 && < 5,
235+ base >= 4.8 && < 5,
236+ binary >= 0.5 && < 0.8,
237+ blaze-html >= 0.5 && < 0.9,
238+ blaze-markup >= 0.5.1 && < 0.8,
271− bytestring >= 0.9 && < 0.11,
239+ bytestring >= 0.9 && < 0.11,
240+ cmdargs >= 0.10 && < 0.11,
272− containers >= 0.3 && < 0.7,
241+ containers >= 0.3 && < 0.6,
242+ cryptohash >= 0.7 && < 0.12,
243+ data-default >= 0.4 && < 0.6,
244+ deepseq >= 1.3 && < 1.5,
245+ directory >= 1.0 && < 1.3,
273− filepath >= 1.0 && < 1.5,
246+ filepath >= 1.0 && < 1.5,
247+ lrucache >= 1.1.1 && < 1.3,
248+ mtl >= 1 && < 2.3,
249+ network >= 2.6 && < 2.7,
250+ network-uri >= 2.6 && < 2.7,
251+ pandoc >= 1.14 && < 1.18,
252+ pandoc-citeproc >= 0.4 && < 0.10,
253+ parsec >= 3.0 && < 3.2,
254+ process >= 1.0 && < 1.3,
255+ random >= 1.0 && < 1.2,
256+ regex-base >= 0.93 && < 0.94,
257+ regex-tdfa >= 1.1 && < 1.3,
258+ resourcet >= 1.1 && < 1.2,
259+ tagsoup >= 0.13.1 && < 0.14,
274− text >= 0.11 && < 1.3,
260+ text >= 0.11 && < 1.3,
261+ time >= 1.4 && < 1.6,
262+ time-locale-compat >= 0.1 && < 0.2,
275− unordered-containers >= 0.2 && < 0.3,
263+ unordered-containers >= 0.2 && < 0.3,
264+ vector >= 0.11 && < 0.12,
276− yaml >= 0.8.11 && < 0.12
265+ yaml >= 0.8 && < 0.9
277
266
278 If flag(previewServer)
267 If flag(previewServer)
268+ Build-depends:
269+ snap-core >= 0.6 && < 0.10,
270+ snap-server >= 0.6 && < 0.10,
271+ fsnotify >= 0.2 && < 0.3,
272+ system-filepath >= 0.4.6 && <= 0.5
279 Cpp-options:
273 Cpp-options:
280 -DPREVIEW_SERVER
274 -DPREVIEW_SERVER
275+ Other-modules:
276+ Hakyll.Preview.Poll
277+ Hakyll.Preview.Server
281
278
282 If flag(watchServer)
279 If flag(watchServer)
280+ Build-depends:
281+ fsnotify >= 0.2 && < 0.3,
282+ system-filepath >= 0.4.6 && <= 0.5
283 Cpp-options:
283 Cpp-options:
284 -DWATCH_SERVER
284 -DWATCH_SERVER
285+ Other-modules:
286+ Hakyll.Preview.Poll
285
287
286 If flag(checkExternal)
288 If flag(checkExternal)
289+ Build-depends:
290+ http-conduit >= 2.1 && < 2.2,
291+ http-types >= 0.7 && < 0.10
287 Cpp-options:
292 Cpp-options:
288 -DCHECK_EXTERNAL
293 -DCHECK_EXTERNAL
289
294
290− If flag(usePandoc)
291− Other-modules:
292− Hakyll.Web.Pandoc.FileType.Tests
293− Cpp-options:
294− -DUSE_PANDOC
295−
296Executable hakyll-init
295Executable hakyll-init
297− Main-is: Init.hs
298− Ghc-options: -Wall -threaded
296+ Ghc-options: -Wall
299− Hs-source-dirs: src
297+ Hs-source-dirs: src
300− Default-language: Haskell2010
298+ Main-is: Hakyll/Init.hs
301−
302− Other-modules:
303− Paths_hakyll
304
299
305 Build-depends:
300 Build-depends:
306− hakyll,
307 base >= 4 && < 5,
301 base >= 4 && < 5,
308− directory >= 1.0 && < 1.4,
302+ directory >= 1.0 && < 1.3,
309 filepath >= 1.0 && < 1.5
303 filepath >= 1.0 && < 1.5
310
304
311−Executable hakyll-website
305+ Other-modules:
312− Main-is: site.hs
306+ Hakyll.Core.Util.File
313− Ghc-options: -Wall -threaded
307+ Paths_hakyll
314− Hs-source-dirs: web
315− Default-language: Haskell2010
316−
317− If flag(buildWebsite)
318− Buildable: True
319− Else
320− Buildable: False
321−
322− Build-depends:
323− hakyll,
324− base >= 4 && < 5,
325− directory >= 1.0 && < 1.4,
326− filepath >= 1.0 && < 1.5,
327− pandoc >= 2.0.5 && < 2.8
lib/Hakyll/Core/Identifier/Pattern/Internal.hsdeleted−92
@@ -1,92 +0,0 @@
1−-- | This internal module is mostly here to prevent CPP conflicting with Haskell
2−-- comments.
3−{-# LANGUAGE CPP #-}
4−module Hakyll.Core.Identifier.Pattern.Internal
5− ( GlobComponent (..)
6− , Pattern (..)
7− ) where
8−
9−
10−--------------------------------------------------------------------------------
11−import Data.Binary (Binary (..), getWord8, putWord8)
12−import Data.Set (Set)
13−
14−
15−--------------------------------------------------------------------------------
16−#if MIN_VERSION_base(4,9,0)
17−import Data.Semigroup (Semigroup (..))
18−#endif
19−
20−
21−--------------------------------------------------------------------------------
22−import Hakyll.Core.Identifier
23−
24−
25−--------------------------------------------------------------------------------
26−-- | Elements of a glob pattern
27−data GlobComponent
28− = Capture
29− | CaptureMany
30− | Literal String
31− deriving (Eq, Show)
32−
33−
34−--------------------------------------------------------------------------------
35−instance Binary GlobComponent where
36− put Capture = putWord8 0
37− put CaptureMany = putWord8 1
38− put (Literal s) = putWord8 2 >> put s
39−
40− get = getWord8 >>= \t -> case t of
41− 0 -> pure Capture
42− 1 -> pure CaptureMany
43− 2 -> Literal <$> get
44− _ -> error "Data.Binary.get: Invalid GlobComponent"
45−
46−
47−--------------------------------------------------------------------------------
48−-- | Type that allows matching on identifiers
49−data Pattern
50− = Everything
51− | Complement Pattern
52− | And Pattern Pattern
53− | Glob [GlobComponent]
54− | List (Set Identifier)
55− | Regex String
56− | Version (Maybe String)
57− deriving (Show)
58−
59−
60−--------------------------------------------------------------------------------
61−instance Binary Pattern where
62− put Everything = putWord8 0
63− put (Complement p) = putWord8 1 >> put p
64− put (And x y) = putWord8 2 >> put x >> put y
65− put (Glob g) = putWord8 3 >> put g
66− put (List is) = putWord8 4 >> put is
67− put (Regex r) = putWord8 5 >> put r
68− put (Version v) = putWord8 6 >> put v
69−
70− get = getWord8 >>= \t -> case t of
71− 0 -> pure Everything
72− 1 -> Complement <$> get
73− 2 -> And <$> get <*> get
74− 3 -> Glob <$> get
75− 4 -> List <$> get
76− 5 -> Regex <$> get
77− _ -> Version <$> get
78−
79−
80−--------------------------------------------------------------------------------
81−#if MIN_VERSION_base(4,9,0)
82−instance Semigroup Pattern where
83− (<>) = And
84−
85−instance Monoid Pattern where
86− mempty = Everything
87− mappend = (<>)
88−#else
89−instance Monoid Pattern where
90− mempty = Everything
91− mappend = And
92−#endif
lib/Hakyll/Main.hsdeleted−180
@@ -1,180 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Module providing the main hakyll function and command-line argument parsing
3−{-# LANGUAGE CPP #-}
4−
5−module Hakyll.Main
6− ( hakyll
7− , hakyllWith
8− , hakyllWithArgs
9− , hakyllWithExitCode
10− , hakyllWithExitCodeAndArgs
11− , Options(..)
12− , Command(..)
13− ) where
14−
15−
16−--------------------------------------------------------------------------------
17−import System.Environment (getProgName)
18−import System.Exit (ExitCode (ExitSuccess), exitWith)
19−import System.IO.Unsafe (unsafePerformIO)
20−
21−
22−--------------------------------------------------------------------------------
23−import Data.Monoid ((<>))
24−import qualified Options.Applicative as OA
25−
26−
27−--------------------------------------------------------------------------------
28−import qualified Hakyll.Check as Check
29−import qualified Hakyll.Commands as Commands
30−import qualified Hakyll.Core.Configuration as Config
31−import qualified Hakyll.Core.Logger as Logger
32−import Hakyll.Core.Rules
33−
34−
35−--------------------------------------------------------------------------------
36−-- | This usually is the function with which the user runs the hakyll compiler
37−hakyll :: Rules a -> IO ()
38−hakyll = hakyllWith Config.defaultConfiguration
39−
40−--------------------------------------------------------------------------------
41−-- | A variant of 'hakyll' which allows the user to specify a custom
42−-- configuration
43−hakyllWith :: Config.Configuration -> Rules a -> IO ()
44−hakyllWith conf rules = hakyllWithExitCode conf rules >>= exitWith
45−
46−--------------------------------------------------------------------------------
47−-- | A variant of 'hakyll' which returns an 'ExitCode'
48−hakyllWithExitCode :: Config.Configuration -> Rules a -> IO ExitCode
49−hakyllWithExitCode conf rules = do
50− args <- defaultParser conf
51− hakyllWithExitCodeAndArgs conf args rules
52−
53−--------------------------------------------------------------------------------
54−-- | A variant of 'hakyll' which expects a 'Configuration' and command-line
55−-- 'Options'. This gives freedom to implement your own parsing.
56−hakyllWithArgs :: Config.Configuration -> Options -> Rules a -> IO ()
57−hakyllWithArgs conf args rules =
58− hakyllWithExitCodeAndArgs conf args rules >>= exitWith
59−
60−--------------------------------------------------------------------------------
61−hakyllWithExitCodeAndArgs :: Config.Configuration ->
62− Options -> Rules a -> IO ExitCode
63−hakyllWithExitCodeAndArgs conf args rules = do
64− let args' = optCommand args
65− verbosity' = if verbosity args then Logger.Debug else Logger.Message
66− check =
67− if internal_links args' then Check.InternalLinks else Check.All
68−
69− logger <- Logger.new verbosity'
70− invokeCommands args' conf check logger rules
71−
72−--------------------------------------------------------------------------------
73−defaultParser :: Config.Configuration -> IO Options
74−defaultParser conf =
75− OA.customExecParser (OA.prefs OA.showHelpOnError)
76− (OA.info (OA.helper <*> optionParser conf)
77− (OA.fullDesc <> OA.progDesc
78− (progName ++ " - Static site compiler created with Hakyll")))
79−
80−
81−--------------------------------------------------------------------------------
82−invokeCommands :: Command -> Config.Configuration ->
83− Check.Check -> Logger.Logger -> Rules a -> IO ExitCode
84−invokeCommands args conf check logger rules =
85− case args of
86− Build -> Commands.build conf logger rules
87− Check _ -> Commands.check conf logger check
88− Clean -> Commands.clean conf logger >> ok
89− Deploy -> Commands.deploy conf
90− Preview p -> Commands.preview conf logger rules p >> ok
91− Rebuild -> Commands.rebuild conf logger rules
92− Server _ _ -> Commands.server conf logger (host args) (port args) >> ok
93− Watch _ p s -> Commands.watch conf logger (host args) p (not s) rules >> ok
94− where
95− ok = return ExitSuccess
96−
97−
98−--------------------------------------------------------------------------------
99−
100−-- | The parsed command-line options.
101−data Options = Options {verbosity :: Bool, optCommand :: Command}
102− deriving (Show)
103−
104−-- | The command to run.
105−data Command
106− = Build
107− -- ^ Generate the site.
108− | Check {internal_links :: Bool}
109− -- ^ Validate the site output.
110− | Clean
111− -- ^ Clean up and remove cache.
112− | Deploy
113− -- ^ Upload/deploy your site.
114− | Preview {port :: Int}
115− -- ^ [DEPRECATED] Please use the watch command.
116− | Rebuild
117− -- ^ Clean and build again.
118− | Server {host :: String, port :: Int}
119− -- ^ Start a preview server.
120− | Watch {host :: String, port :: Int, no_server :: Bool }
121− -- ^ Autocompile on changes and start a preview server.
122− deriving (Show)
123−
124−{-# DEPRECATED Preview "Use Watch instead." #-}
125−
126−optionParser :: Config.Configuration -> OA.Parser Options
127−optionParser conf = Options <$> verboseParser <*> commandParser conf
128− where
129− verboseParser = OA.switch (OA.long "verbose" <> OA.short 'v' <> OA.help "Run in verbose mode")
130−
131−
132−commandParser :: Config.Configuration -> OA.Parser Command
133−commandParser conf = OA.subparser $ foldr ((<>) . produceCommand) mempty commands
134− where
135− portParser = OA.option OA.auto (OA.long "port" <> OA.help "Port to listen on" <> OA.value (Config.previewPort conf))
136− hostParser = OA.strOption (OA.long "host" <> OA.help "Host to bind on" <> OA.value (Config.previewHost conf))
137−
138− produceCommand (c,a,b) = OA.command c (OA.info (OA.helper <*> a) (b))
139−
140− commands =
141− [ ( "build"
142− , pure Build
143− , OA.fullDesc <> OA.progDesc "Generate the site"
144− )
145− , ( "check"
146− , pure Check <*> OA.switch (OA.long "internal-links" <> OA.help "Check internal links only")
147− , OA.fullDesc <> OA.progDesc "Validate the site output"
148− )
149− , ( "clean"
150− , pure Clean
151− , OA.fullDesc <> OA.progDesc "Clean up and remove cache"
152− )
153− , ( "deploy"
154− , pure Deploy
155− , OA.fullDesc <> OA.progDesc "Upload/deploy your site"
156− )
157− , ( "preview"
158− , pure Preview <*> portParser
159− , OA.fullDesc <> OA.progDesc "[DEPRECATED] Please use the watch command"
160− )
161− , ( "rebuild"
162− , pure Rebuild
163− , OA.fullDesc <> OA.progDesc "Clean and build again"
164− )
165− , ( "server"
166− , pure Server <*> hostParser <*> portParser
167− , OA.fullDesc <> OA.progDesc "Start a preview server"
168− )
169− , ( "watch"
170− , pure Watch <*> hostParser <*> portParser <*> OA.switch (OA.long "no-server" <> OA.help "Disable the built-in web server")
171− , OA.fullDesc <> OA.progDesc "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server."
172− )
173− ]
174−
175−
176−--------------------------------------------------------------------------------
177−-- | This is necessary because not everyone calls their program the same...
178−progName :: String
179−progName = unsafePerformIO getProgName
180−{-# NOINLINE progName #-}
lib/Hakyll/Preview/Server.hsdeleted−35
@@ -1,35 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Implements a basic static file server for previewing options
3−{-# LANGUAGE OverloadedStrings #-}
4−module Hakyll.Preview.Server
5− ( staticServer
6− ) where
7−
8−
9−--------------------------------------------------------------------------------
10−import Data.String
11−import qualified Network.Wai.Handler.Warp as Warp
12−import qualified Network.Wai.Application.Static as Static
13−import qualified Network.Wai as Wai
14−import Network.HTTP.Types.Status (Status)
15−
16−--------------------------------------------------------------------------------
17−import Hakyll.Core.Logger (Logger)
18−import qualified Hakyll.Core.Logger as Logger
19−
20−staticServer :: Logger -- ^ Logger
21− -> FilePath -- ^ Directory to serve
22− -> String -- ^ Host to bind on
23− -> Int -- ^ Port to listen on
24− -> IO () -- ^ Blocks forever
25−staticServer logger directory host port = do
26− Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port
27− Warp.runSettings warpSettings $
28− Static.staticApp (Static.defaultFileServerSettings directory)
29− where
30− warpSettings = Warp.setLogger noLog
31− $ Warp.setHost (fromString host)
32− $ Warp.setPort port Warp.defaultSettings
33−
34−noLog :: Wai.Request -> Status -> Maybe Integer -> IO ()
35−noLog _ _ _ = return ()
lib/Hakyll/Web/CompressCss.hsdeleted−101
@@ -1,101 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Module used for CSS compression. The compression is currently in a simple
3−-- state, but would typically reduce the number of bytes by about 25%.
4−module Hakyll.Web.CompressCss
5− ( compressCssCompiler
6− , compressCss
7− ) where
8−
9−
10−--------------------------------------------------------------------------------
11−import Data.Char (isSpace)
12−import Data.List (dropWhileEnd, isPrefixOf)
13−
14−
15−--------------------------------------------------------------------------------
16−import Hakyll.Core.Compiler
17−import Hakyll.Core.Item
18−import Hakyll.Core.Util.String
19−
20−
21−--------------------------------------------------------------------------------
22−-- | Compiler form of 'compressCss'
23−compressCssCompiler :: Compiler (Item String)
24−compressCssCompiler = fmap compressCss <$> getResourceString
25−
26−
27−--------------------------------------------------------------------------------
28−-- | Compress CSS to speed up your site.
29−compressCss :: String -> String
30−compressCss = withoutStrings (handleCalcExpressions compressSeparators . compressWhitespace)
31− . dropWhileEnd isSpace
32− . dropWhile isSpace
33− . stripComments
34−
35−
36−--------------------------------------------------------------------------------
37−-- | Compresses certain forms of separators.
38−compressSeparators :: String -> String
39−compressSeparators =
40− replaceAll "; *}" (const "}") .
41− replaceAll ";+" (const ";") .
42− replaceAll " *[{};,>+~!] *" (take 1 . dropWhile isSpace) .
43− replaceAll ": *" (take 1) -- not destroying pseudo selectors (#323)
44−
45−-- | Uses `compressCalcExpression` on all parenthesised calc expressions
46−-- and applies `transform` to all parts outside of them
47−handleCalcExpressions :: (String -> String) -> String -> String
48−handleCalcExpressions transform = top transform
49− where
50− top f "" = f ""
51− top f str | "calc(" `isPrefixOf` str = f "calc" ++ nested 0 compressCalcExpression (drop 4 str)
52− top f (x:xs) = top (f . (x:)) xs
53−
54− -- when called with depth=0, the first character must be a '('
55− nested :: Int -> (String -> String) -> String -> String
56− nested _ f "" = f "" -- shouldn't happen, mismatched nesting
57− nested depth f str | "calc(" `isPrefixOf` str = nested depth f (drop 4 str)
58− nested 1 f (')':xs) = f ")" ++ top transform xs
59− nested depth f (x:xs) = nested (case x of
60− '(' -> depth + 1
61− ')' -> depth - 1 -- assert: depth > 1
62− _ -> depth
63− ) (f . (x:)) xs
64−
65−-- | does not remove whitespace around + and -, which is important in calc() expressions
66−compressCalcExpression :: String -> String
67−compressCalcExpression =
68− replaceAll " *[*/] *| *\\)|\\( *" (take 1 . dropWhile isSpace)
69−
70−--------------------------------------------------------------------------------
71−-- | Compresses all whitespace.
72−compressWhitespace :: String -> String
73−compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
74−
75−--------------------------------------------------------------------------------
76−-- | Function that strips CSS comments away (outside of strings).
77−stripComments :: String -> String
78−stripComments "" = ""
79−stripComments ('/':'*':str) = stripComments $ eatComment str
80−stripComments (x:xs) | x `elem` "\"'" = retainString x xs stripComments
81− | otherwise = x : stripComments xs
82−
83−eatComment :: String -> String
84−eatComment "" = ""
85−eatComment ('*':'/':str) = str
86−eatComment (_:str) = eatComment str
87−
88−
89−--------------------------------------------------------------------------------
90−-- | Helper functions to handle string tokens correctly.
91−
92−-- TODO: handle backslash escapes
93−withoutStrings :: (String -> String) -> String -> String
94−withoutStrings f str = case span (`notElem` "\"'") str of
95− (text, "") -> f text
96− (text, d:rest) -> f text ++ retainString d rest (withoutStrings f)
97−
98−retainString :: Char -> String -> (String -> String) -> String
99−retainString delim str cont = case span (/= delim) str of
100− (val, "") -> delim : val
101− (val, _:rest) -> delim : val ++ delim : cont rest
lib/Hakyll/Web/Redirect.hsdeleted−100
@@ -1,100 +0,0 @@
1−-- | Module used for generating HTML redirect pages. This allows renaming pages
2−-- to avoid breaking existing links without requiring server-side support for
3−-- formal 301 Redirect error codes
4−module Hakyll.Web.Redirect
5− ( Redirect (..)
6− , createRedirects
7− ) where
8−
9−import Control.Applicative ((<$>))
10−import Control.Monad (forM_, when)
11−import Data.Binary (Binary (..))
12−import Data.List (sort, group)
13−import Hakyll.Core.Compiler
14−import Hakyll.Core.Identifier
15−import Hakyll.Core.Routes
16−import Hakyll.Core.Rules
17−import Hakyll.Core.Writable (Writable (..))
18−
19−-- | This function exposes a higher-level interface compared to using the
20−-- 'Redirect' type manually.
21−--
22−-- This creates, using a database mapping broken URLs to working ones, HTML
23−-- files which will do HTML META tag redirect pages (since, as a static site, we
24−-- can't use web-server-level 301 redirects, and using JS is gross).
25−--
26−-- This is useful for sending people using old URLs to renamed versions, dealing
27−-- with common typos etc, and will increase site traffic. Such broken URLs can
28−-- be found by looking at server logs or by using Google Webmaster Tools.
29−-- Broken URLs must be valid Haskell strings, non-URL-escaped valid POSIX
30−-- filenames, and relative links, since they will be defined in a @hakyll.hs@
31−-- and during generation, written to disk with the filename corresponding to the
32−-- broken URLs. (Target URLs can be absolute or relative, but should be
33−-- URL-escaped.) So broken incoming links like <http://www.gwern.net/foo/> which
34−-- should be <http://www.gwern.net/foobar> cannot be fixed (since you cannot
35−-- create a HTML file named @"foo/"@ on disk, as that would be a directory).
36−--
37−-- An example of a valid association list would be:
38−--
39−-- > brokenLinks =
40−-- > [ ("projects.html", "http://github.com/gwern")
41−-- > , ("/Black-market archive", "Black-market%20archives")
42−-- > ]
43−--
44−-- In which case the functionality can then be used in `main` with a line like:
45−--
46−-- > version "redirects" $ createRedirects brokenLinks
47−--
48−-- The 'version' is recommended to separate these items from your other pages.
49−--
50−-- The on-disk files can then be uploaded with HTML mimetypes
51−-- (either explicitly by generating and uploading them separately, by
52−-- auto-detection of the filetype, or an upload tool defaulting to HTML
53−-- mimetype, such as calling @s3cmd@ with @--default-mime-type=text/html@) and
54−-- will redirect browsers and search engines going to the old/broken URLs.
55−--
56−-- See also <https://groups.google.com/d/msg/hakyll/sWc6zxfh-uM/fUpZPsFNDgAJ>.
57−createRedirects :: [(Identifier, String)] -> Rules ()
58−createRedirects redirects =
59− do -- redirects are many-to-fewer; keys must be unique, and must point somewhere else:
60− let gkeys = group $ sort $ map fst redirects
61− forM_ gkeys $ \gkey -> case gkey of
62− (k : _ : _) -> fail $
63− "Duplicate 301 redirects; " ++ show k ++ " is ambiguous."
64− _ -> return ()
65−
66− forM_ redirects $ \(r, t) ->
67− when (toFilePath r == t) $ fail $
68− "Self-redirect detected: " ++ show r ++ " points to itself."
69−
70− forM_ redirects $ \(ident, to) ->
71− create [ident] $ do
72− route idRoute
73− compile $ makeItem $! Redirect to
74−
75−-- | This datatype can be used directly if you want a lower-level interface to
76−-- generate redirects. For example, if you want to redirect @foo.html@ to
77−-- @bar.jpg@, you can use:
78−--
79−-- > create ["foo.html"] $ do
80−-- > route idRoute
81−-- > compile $ makeItem $ Redirect "bar.jpg"
82−data Redirect = Redirect
83− { redirectTo :: String
84− } deriving (Eq, Ord, Show)
85−
86−instance Binary Redirect where
87− put (Redirect to) = put to
88− get = Redirect <$> get
89−
90−instance Writable Redirect where
91− write path = write path . fmap redirectToHtml
92−
93−redirectToHtml :: Redirect -> String
94−redirectToHtml (Redirect working) =
95− "<!DOCTYPE html><html><head><meta charset=\"utf-8\"/><meta name=\"generator\" content=\"hakyll\"/>" ++
96− "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" ++
97− "<meta http-equiv=\"refresh\" content=\"0; url=" ++ working ++
98− "\"><link rel=\"canonical\" href=\"" ++ working ++
99− "\"><title>Permanent Redirect</title></head><body><p>The page has moved to: <a href=\"" ++ working ++
100− "\">this page</a></p></body></html>"
lib/Hakyll/Web/Template.hsdeleted−178
@@ -1,178 +0,0 @@
1−-- | This module provides means for reading and applying 'Template's.
2−--
3−-- Templates are tools to convert items into a string. They are perfectly suited
4−-- for laying out your site.
5−--
6−-- Let's look at an example template:
7−--
8−-- > <html>
9−-- > <head>
10−-- > <title>My crazy homepage - $title$</title>
11−-- > </head>
12−-- > <body>
13−-- > <div id="header">
14−-- > <h1>My crazy homepage - $title$</h1>
15−-- > </div>
16−-- > <div id="content">
17−-- > $body$
18−-- > </div>
19−-- > <div id="footer">
20−-- > By reading this you agree that I now own your soul
21−-- > </div>
22−-- > </body>
23−-- > </html>
24−--
25−-- As you can see, the format is very simple -- @$key$@ is used to render the
26−-- @$key$@ field from the page, everything else is literally copied. If you want
27−-- to literally insert @\"$key$\"@ into your page (for example, when you're
28−-- writing a Hakyll tutorial) you can use
29−--
30−-- > <p>
31−-- > A literal $$key$$.
32−-- > </p>
33−--
34−-- Because of it's simplicity, these templates can be used for more than HTML:
35−-- you could make, for example, CSS or JS templates as well.
36−--
37−-- Apart from interpolating @$key$@s from the 'Context' you can also
38−-- use the following macros:
39−--
40−-- * @$if(key)$@
41−--
42−-- > $if(key)$
43−-- > <b> Defined </b>
44−-- > $else$
45−-- > <b> Non-defined </b>
46−-- > $endif$
47−--
48−-- This example will print @Defined@ if @key@ is defined in the
49−-- context and @Non-defined@ otherwise. The @$else$@ clause is
50−-- optional.
51−--
52−-- * @$for(key)$@
53−--
54−-- The @for@ macro is used for enumerating 'Context' elements that are
55−-- lists, i.e. constructed using the 'listField' function. Assume that
56−-- in a context we have an element @listField \"key\" c itms@. Then
57−-- the snippet
58−--
59−-- > $for(key)$
60−-- > $x$
61−-- > $sep$,
62−-- > $endfor$
63−--
64−-- would, for each item @i@ in 'itms', lookup @$x$@ in the context @c@
65−-- with item @i@, interpolate it, and join the resulting list with
66−-- @,@.
67−--
68−-- Another concrete example one may consider is the following. Given the
69−-- context
70−--
71−-- > listField "things" (field "thing" (return . itemBody))
72−-- > (sequence [makeItem "fruits", makeItem "vegetables"])
73−--
74−-- and a template
75−--
76−-- > I like
77−-- > $for(things)$
78−-- > fresh $thing$$sep$, and
79−-- > $endfor$
80−--
81−-- the resulting page would look like
82−--
83−-- > <p>
84−-- > I like
85−-- >
86−-- > fresh fruits, and
87−-- >
88−-- > fresh vegetables
89−-- > </p>
90−--
91−-- The @$sep$@ part can be omitted. Usually, you can get by using the
92−-- 'applyListTemplate' and 'applyJoinListTemplate' functions.
93−--
94−-- * @$partial(path)$@
95−--
96−-- Loads a template located in a separate file and interpolates it
97−-- under the current context.
98−--
99−-- Assuming that the file @test.html@ contains
100−--
101−-- > <b>$key$</b>
102−--
103−-- The result of rendering
104−--
105−-- > <p>
106−-- > $partial("test.html")$
107−-- > </p>
108−--
109−-- is the same as the result of rendering
110−--
111−-- > <p>
112−-- > <b>$key$</b>
113−-- > </p>
114−--
115−-- That is, calling @$partial$@ is equivalent to just copying and pasting
116−-- template code.
117−--
118−-- In the examples above you can see that the outputs contain a lot of leftover
119−-- whitespace that you may wish to remove. Using @'$-'@ or @'-$'@ instead of
120−-- @'$'@ in a macro strips all whitespace to the left or right of that clause
121−-- respectively. Given the context
122−--
123−-- > listField "counts" (field "count" (return . itemBody))
124−-- > (sequence [makeItem "3", makeItem "2", makeItem "1"])
125−--
126−-- and a template
127−--
128−-- > <p>
129−-- > $for(counts)-$
130−-- > $count$
131−-- > $-sep$...
132−-- > $-endfor$
133−-- > </p>
134−--
135−-- the resulting page would look like
136−--
137−-- > <p>
138−-- > 3...2...1
139−-- > </p>
140−--
141−{-# LANGUAGE TemplateHaskell #-}
142−module Hakyll.Web.Template
143− ( Template
144− , templateBodyCompiler
145− , templateCompiler
146− , applyTemplate
147− , loadAndApplyTemplate
148− , applyAsTemplate
149− , readTemplate
150− , compileTemplateItem
151− , unsafeReadTemplateFile
152− , embedTemplate
153− ) where
154−
155−
156−--------------------------------------------------------------------------------
157−import Hakyll.Web.Template.Internal
158−
159−
160−--------------------------------------------------------------------------------
161−import Data.FileEmbed (embedFile)
162−import qualified Data.Text as T
163−import qualified Data.Text.Encoding as T
164−import Language.Haskell.TH (Exp, Q)
165−
166−
167−--------------------------------------------------------------------------------
168−-- | Embed template allows you embed a template within the Haskell binary.
169−-- Example:
170−--
171−-- > myTemplate :: Template
172−-- > myTemplate = $(embedTemplate "test.html")
173−embedTemplate :: FilePath -> Q Exp
174−embedTemplate filePath = [|
175− let source = T.unpack $ T.decodeUtf8 $(embedFile filePath) in
176− case parseTemplateElemsFile filePath source of
177− Left err -> error err
178− Right tpl -> template filePath tpl |]
lib/Hakyll/Web/Template/Internal.hsdeleted−261
@@ -1,261 +0,0 @@
1−{-# LANGUAGE DeriveAnyClass #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4−{-# LANGUAGE ScopedTypeVariables #-}
5−
6−module Hakyll.Web.Template.Internal
7− ( Template (..)
8− , template
9− , templateBodyCompiler
10− , templateCompiler
11− , applyTemplate
12− , loadAndApplyTemplate
13− , applyAsTemplate
14− , readTemplate
15− , compileTemplateItem
16− , unsafeReadTemplateFile
17−
18− , module Hakyll.Web.Template.Internal.Element
19− , module Hakyll.Web.Template.Internal.Trim
20− ) where
21−
22−
23−--------------------------------------------------------------------------------
24−import Control.Monad (forM)
25−import Control.Monad.Except (MonadError (..), catchError)
26−import Data.Binary (Binary)
27−import Data.List (intercalate)
28−import qualified Data.List.NonEmpty as NonEmpty
29−import Data.Typeable (Typeable)
30−import GHC.Exts (IsString (..))
31−import GHC.Generics (Generic)
32−
33−
34−--------------------------------------------------------------------------------
35−import Hakyll.Core.Compiler
36−import Hakyll.Core.Compiler.Internal
37−import Hakyll.Core.Identifier
38−import Hakyll.Core.Item
39−import Hakyll.Core.Writable
40−import Hakyll.Web.Template.Context
41−import Hakyll.Web.Template.Internal.Element
42−import Hakyll.Web.Template.Internal.Trim
43−
44−
45−--------------------------------------------------------------------------------
46−-- | Datatype used for template substitutions.
47−data Template = Template
48− { tplElements :: [TemplateElement]
49− , tplOrigin :: FilePath -- Only for error messages.
50− } deriving (Show, Eq, Generic, Binary, Typeable)
51−
52−
53−--------------------------------------------------------------------------------
54−instance Writable Template where
55− -- Writing a template is impossible
56− write _ _ = return ()
57−
58−
59−--------------------------------------------------------------------------------
60−instance IsString Template where
61− fromString = readTemplate
62−
63−
64−--------------------------------------------------------------------------------
65−-- | Wrap the constructor to ensure trim is called.
66−template :: FilePath -> [TemplateElement] -> Template
67−template p = flip Template p . trim
68−
69−
70−--------------------------------------------------------------------------------
71−-- | Parse a string into a template.
72−-- You should prefer 'compileTemplateItem' over this.
73−readTemplate :: String -> Template
74−readTemplate = either error (template origin) . parseTemplateElemsFile origin
75− where
76− origin = "{literal}"
77−{-# DEPRECATED readTemplate "Use templateCompiler instead" #-}
78−
79−--------------------------------------------------------------------------------
80−-- | Parse an item body into a template.
81−-- Provides useful error messages in the 'Compiler' monad.
82−compileTemplateItem :: Item String -> Compiler Template
83−compileTemplateItem item = let file = itemIdentifier item
84− in compileTemplateFile file (itemBody item)
85−
86−--------------------------------------------------------------------------------
87−compileTemplateFile :: Identifier -> String -> Compiler Template
88−compileTemplateFile file = either fail (return . template origin)
89− . parseTemplateElemsFile origin
90− where
91− origin = show file
92−
93−--------------------------------------------------------------------------------
94−-- | Read a template, without metadata header
95−templateBodyCompiler :: Compiler (Item Template)
96−templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
97− item <- getResourceBody
98− file <- getUnderlying
99− withItemBody (compileTemplateFile file) item
100−
101−--------------------------------------------------------------------------------
102−-- | Read complete file contents as a template
103−templateCompiler :: Compiler (Item Template)
104−templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
105− item <- getResourceString
106− file <- getUnderlying
107− withItemBody (compileTemplateFile file) item
108−
109−
110−--------------------------------------------------------------------------------
111−-- | Interpolate template expressions from context values in a page
112−applyTemplate :: Template -- ^ Template
113− -> Context a -- ^ Context
114− -> Item a -- ^ Page
115− -> Compiler (Item String) -- ^ Resulting item
116−applyTemplate tpl context item = do
117− body <- applyTemplate' (tplElements tpl) context item `catchError` handler
118− return $ itemSetBody body item
119− where
120− tplName = tplOrigin tpl
121− itemName = show $ itemIdentifier item
122− handler es = fail $ "Hakyll.Web.Template.applyTemplate: Failed to " ++
123− (if tplName == itemName
124− then "interpolate template in item " ++ itemName
125− else "apply template " ++ tplName ++ " to item " ++ itemName) ++
126− ":\n" ++ intercalate ",\n" es
127−
128−
129−
130−--------------------------------------------------------------------------------
131−applyTemplate'
132− :: forall a.
133− [TemplateElement] -- ^ Unwrapped Template
134− -> Context a -- ^ Context
135− -> Item a -- ^ Page
136− -> Compiler String -- ^ Resulting item
137−applyTemplate' tes context x = go tes
138− where
139− context' :: String -> [String] -> Item a -> Compiler ContextField
140− context' = unContext (context `mappend` missingField)
141−
142− go = fmap concat . mapM applyElem
143−
144− ---------------------------------------------------------------------------
145−
146− applyElem :: TemplateElement -> Compiler String
147−
148− applyElem TrimL = trimError
149−
150− applyElem TrimR = trimError
151−
152− applyElem (Chunk c) = return c
153−
154− applyElem (Expr e) = withErrorMessage evalMsg (applyStringExpr typeMsg e)
155− where
156− evalMsg = "In expr '$" ++ show e ++ "$'"
157− typeMsg = "expr '$" ++ show e ++ "$'"
158−
159− applyElem Escaped = return "$"
160−
161− applyElem (If e t mf) = compilerTry (applyExpr e) >>= handle
162− where
163− f = maybe (return "") go mf
164− handle (Right _) = go t
165− handle (Left (CompilationNoResult _)) = f
166− handle (Left (CompilationFailure es)) = debug (NonEmpty.toList es) >> f
167− debug = compilerDebugEntries ("Hakyll.Web.Template.applyTemplate: " ++
168− "[ERROR] in 'if' condition on expr '" ++ show e ++ "':")
169−
170− applyElem (For e b s) = withErrorMessage headMsg (applyExpr e) >>= \cf -> case cf of
171− EmptyField -> expected "list" "boolean" typeMsg
172− StringField _ -> expected "list" "string" typeMsg
173− ListField c xs -> withErrorMessage bodyMsg $ do
174− sep <- maybe (return "") go s
175− bs <- forM xs $ applyTemplate' b $ c <> bindItem context x
176− return $ intercalate sep bs
177− where
178− headMsg = "In expr '$for(" ++ show e ++ ")$'"
179− typeMsg = "loop expr '" ++ show e ++ "'"
180− bodyMsg = "In loop context of '$for(" ++ show e ++ ")$'"
181−
182− applyElem (Partial e) = withErrorMessage headMsg $
183− applyStringExpr typeMsg e >>= \p ->
184− withErrorMessage inclMsg $ do
185− tpl' <- loadBody (fromFilePath p)
186− itemBody <$> applyTemplate tpl' context x
187− where
188− headMsg = "In expr '$partial(" ++ show e ++ ")$'"
189− typeMsg = "partial expr '" ++ show e ++ "'"
190− inclMsg = "In inclusion of '$partial(" ++ show e ++ ")$'"
191−
192− ---------------------------------------------------------------------------
193−
194− applyExpr :: TemplateExpr -> Compiler ContextField
195−
196− applyExpr (Ident (TemplateKey k)) = context' k [] x
197−
198− applyExpr (Call (TemplateKey k) args) = do
199− args' <- mapM (\e -> applyStringExpr (typeMsg e) e) args
200− context' k args' x
201− where
202− typeMsg e = "argument '" ++ show e ++ "'"
203−
204− applyExpr (StringLiteral s) = return (StringField s)
205−
206− ----------------------------------------------------------------------------
207−
208− applyStringExpr :: String -> TemplateExpr -> Compiler String
209− applyStringExpr msg expr =
210− applyExpr expr >>= getString
211− where
212− getString EmptyField = expected "string" "boolean" msg
213− getString (StringField s) = return s
214− getString (ListField _ _) = expected "string" "list" msg
215−
216− expected typ act expr = fail $ unwords ["Hakyll.Web.Template.applyTemplate:",
217− "expected", typ, "but got", act, "for", expr]
218−
219− -- expected to never happen with all templates constructed by 'template'
220− trimError = fail $
221− "Hakyll.Web.Template.applyTemplate: template not fully trimmed."
222−
223−
224−--------------------------------------------------------------------------------
225−-- | The following pattern is so common:
226−--
227−-- > tpl <- loadBody "templates/foo.html"
228−-- > someCompiler
229−-- > >>= applyTemplate tpl context
230−--
231−-- That we have a single function which does this:
232−--
233−-- > someCompiler
234−-- > >>= loadAndApplyTemplate "templates/foo.html" context
235−loadAndApplyTemplate :: Identifier -- ^ Template identifier
236− -> Context a -- ^ Context
237− -> Item a -- ^ Page
238− -> Compiler (Item String) -- ^ Resulting item
239−loadAndApplyTemplate identifier context item = do
240− tpl <- loadBody identifier
241− applyTemplate tpl context item
242−
243−
244−--------------------------------------------------------------------------------
245−-- | It is also possible that you want to substitute @$key$@s within the body of
246−-- an item. This function does that by interpreting the item body as a template,
247−-- and then applying it to itself.
248−applyAsTemplate :: Context String -- ^ Context
249− -> Item String -- ^ Item and template
250− -> Compiler (Item String) -- ^ Resulting item
251−applyAsTemplate context item = do
252− tpl <- compileTemplateItem item
253− applyTemplate tpl context item
254−
255−
256−--------------------------------------------------------------------------------
257−unsafeReadTemplateFile :: FilePath -> Compiler Template
258−unsafeReadTemplateFile file = do
259− tpl <- unsafeCompiler $ readFile file
260− compileTemplateFile (fromFilePath file) tpl
261−{-# DEPRECATED unsafeReadTemplateFile "Use templateCompiler" #-}
lib/Hakyll/Web/Template/Internal/Trim.hsdeleted−95
@@ -1,95 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Module for trimming whitespace from tempaltes.
3−module Hakyll.Web.Template.Internal.Trim
4− ( trim
5− ) where
6−
7−
8−--------------------------------------------------------------------------------
9−import Data.Char (isSpace)
10−import Data.List (dropWhileEnd)
11−
12−
13−--------------------------------------------------------------------------------
14−import Hakyll.Web.Template.Internal.Element
15−
16−
17−--------------------------------------------------------------------------------
18−trim :: [TemplateElement] -> [TemplateElement]
19−trim = cleanse . canonicalize
20−
21−
22−--------------------------------------------------------------------------------
23−-- | Apply the Trim nodes to the Chunks.
24−cleanse :: [TemplateElement] -> [TemplateElement]
25−cleanse = recurse cleanse . process
26− where process [] = []
27− process (TrimR:Chunk str:ts) = let str' = dropWhile isSpace str
28− in if null str'
29− then process ts
30− -- Might need to TrimL.
31− else process $ Chunk str':ts
32−
33− process (Chunk str:TrimL:ts) = let str' = dropWhileEnd isSpace str
34− in if null str'
35− then process ts
36− else Chunk str':process ts
37−
38− process (t:ts) = t:process ts
39−
40−--------------------------------------------------------------------------------
41−-- | Enforce the invariant that:
42−--
43−-- * Every 'TrimL' has a 'Chunk' to its left.
44−-- * Every 'TrimR' has a 'Chunk' to its right.
45−--
46−canonicalize :: [TemplateElement] -> [TemplateElement]
47−canonicalize = go
48− where go t = let t' = redundant . swap $ dedupe t
49− in if t == t' then t else go t'
50−
51−
52−--------------------------------------------------------------------------------
53−-- | Remove the 'TrimR' and 'TrimL's that are no-ops.
54−redundant :: [TemplateElement] -> [TemplateElement]
55−redundant = recurse redundant . process
56− where -- Remove the leading 'TrimL's.
57− process (TrimL:ts) = process ts
58− -- Remove trailing 'TrimR's.
59− process ts = foldr trailing [] ts
60− where trailing TrimR [] = []
61− trailing x xs = x:xs
62−
63−
64−--------------------------------------------------------------------------------
65−-- >>> swap $ [TrimR, TrimL]
66−-- [TrimL, TrimR]
67−swap :: [TemplateElement] -> [TemplateElement]
68−swap = recurse swap . process
69− where process [] = []
70− process (TrimR:TrimL:ts) = TrimL:process (TrimR:ts)
71− process (t:ts) = t:process ts
72−
73−
74−--------------------------------------------------------------------------------
75−-- | Remove 'TrimR' and 'TrimL' duplication.
76−dedupe :: [TemplateElement] -> [TemplateElement]
77−dedupe = recurse dedupe . process
78− where process [] = []
79− process (TrimR:TrimR:ts) = process (TrimR:ts)
80− process (TrimL:TrimL:ts) = process (TrimL:ts)
81− process (t:ts) = t:process ts
82−
83−
84−--------------------------------------------------------------------------------
85−-- | @'recurse' f t@ applies f to every '[TemplateElement]' in t.
86−recurse :: ([TemplateElement] -> [TemplateElement])
87− -> [TemplateElement]
88− -> [TemplateElement]
89−recurse _ [] = []
90−recurse f (x:xs) = process x:recurse f xs
91− where process y = case y of
92− If e tb eb -> If e (f tb) (f <$> eb)
93− For e t s -> For e (f t) (f <$> s)
94− _ -> y
95−
lib/Data/List/Extended.hs → src/Data/List/Extended.hsrenamed

The content is the same.

lib/Data/Yaml/Extended.hs → src/Data/Yaml/Extended.hsrenamed+1−5
@@ -7,16 +7,12 @@ module Data.Yaml.Extended
7import qualified Data.Text as T
7import qualified Data.Text as T
8import qualified Data.Vector as V
8import qualified Data.Vector as V
9import Data.Yaml
9import Data.Yaml
10−import Data.Scientific
11
10
12toString :: Value -> Maybe String
11toString :: Value -> Maybe String
13toString (String t) = Just (T.unpack t)
12toString (String t) = Just (T.unpack t)
14toString (Bool True) = Just "true"
13toString (Bool True) = Just "true"
15toString (Bool False) = Just "false"
14toString (Bool False) = Just "false"
16−-- | Make sure that numeric fields containing integer numbers are shown as
17−-- | integers (i.e., "42" instead of "42.0").
18−toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d)
19− | otherwise = Just (show d)
15+toString (Number d) = Just (show d)
20toString _ = Nothing
16toString _ = Nothing
21
17
22toList :: Value -> Maybe [Value]
18toList :: Value -> Maybe [Value]
lib/Hakyll.hs → src/Hakyll.hsrenamed+1−7
@@ -20,14 +20,11 @@ module Hakyll
20 , module Hakyll.Web.Feed
20 , module Hakyll.Web.Feed
21 , module Hakyll.Web.Html
21 , module Hakyll.Web.Html
22 , module Hakyll.Web.Html.RelativizeUrls
22 , module Hakyll.Web.Html.RelativizeUrls
23− , module Hakyll.Web.Paginate
24−#ifdef USE_PANDOC
25 , module Hakyll.Web.Pandoc
23 , module Hakyll.Web.Pandoc
26 , module Hakyll.Web.Pandoc.Biblio
24 , module Hakyll.Web.Pandoc.Biblio
27 , module Hakyll.Web.Pandoc.FileType
25 , module Hakyll.Web.Pandoc.FileType
28−#endif
29− , module Hakyll.Web.Redirect
30 , module Hakyll.Web.Tags
26 , module Hakyll.Web.Tags
27+ , module Hakyll.Web.Paginate
31 , module Hakyll.Web.Template
28 , module Hakyll.Web.Template
32 , module Hakyll.Web.Template.Context
29 , module Hakyll.Web.Template.Context
33 , module Hakyll.Web.Template.List
30 , module Hakyll.Web.Template.List
@@ -54,12 +51,9 @@ import Hakyll.Web.Feed
54import Hakyll.Web.Html
51import Hakyll.Web.Html
55import Hakyll.Web.Html.RelativizeUrls
52import Hakyll.Web.Html.RelativizeUrls
56import Hakyll.Web.Paginate
53import Hakyll.Web.Paginate
57−#ifdef USE_PANDOC
58import Hakyll.Web.Pandoc
54import Hakyll.Web.Pandoc
59import Hakyll.Web.Pandoc.Biblio
55import Hakyll.Web.Pandoc.Biblio
60import Hakyll.Web.Pandoc.FileType
56import Hakyll.Web.Pandoc.FileType
61−#endif
62−import Hakyll.Web.Redirect
63import Hakyll.Web.Tags
57import Hakyll.Web.Tags
64import Hakyll.Web.Template
58import Hakyll.Web.Template
65import Hakyll.Web.Template.Context
59import Hakyll.Web.Template.Context
lib/Hakyll/Check.hs → src/Hakyll/Check.hsrenamed+75−124
@@ -8,20 +8,15 @@ module Hakyll.Check
8
8
9
9
10--------------------------------------------------------------------------------
10--------------------------------------------------------------------------------
11−import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar,
11+import Control.Monad (forM_)
12− readMVar)
13−import Control.Exception (SomeAsyncException (..),
14− SomeException (..), throw, try)
15−import Control.Monad (foldM, forM_)
16−import Control.Monad.Reader (ReaderT, ask, runReaderT)
12+import Control.Monad.Reader (ask)
17−import Control.Monad.State (StateT, get, modify, runStateT)
13+import Control.Monad.RWS (RWST, runRWST)
18import Control.Monad.Trans (liftIO)
14import Control.Monad.Trans (liftIO)
19import Control.Monad.Trans.Resource (runResourceT)
15import Control.Monad.Trans.Resource (runResourceT)
16+import Control.Monad.Writer (tell)
20import Data.List (isPrefixOf)
17import Data.List (isPrefixOf)
18+import Data.Set (Set)
21−import qualified Data.Map.Lazy as Map
19+import qualified Data.Set as S
22−#if MIN_VERSION_base(4,9,0)
23−import Data.Semigroup (Semigroup (..))
24−#endif
25import Network.URI (unEscapeString)
20import Network.URI (unEscapeString)
26import System.Directory (doesDirectoryExist,
21import System.Directory (doesDirectoryExist,
27 doesFileExist)
22 doesFileExist)
@@ -33,6 +28,10 @@ import qualified Text.HTML.TagSoup as TS
33
28
34--------------------------------------------------------------------------------
29--------------------------------------------------------------------------------
35#ifdef CHECK_EXTERNAL
30#ifdef CHECK_EXTERNAL
31+import Control.Exception (AsyncException (..),
32+ SomeException (..), handle,
33+ throw)
34+import Control.Monad.State (get, modify)
36import Data.List (intercalate)
35import Data.List (intercalate)
37import Data.Typeable (cast)
36import Data.Typeable (cast)
38import Data.Version (versionBranch)
37import Data.Version (versionBranch)
@@ -59,17 +58,8 @@ data Check = All | InternalLinks
59--------------------------------------------------------------------------------
58--------------------------------------------------------------------------------
60check :: Configuration -> Logger -> Check -> IO ExitCode
59check :: Configuration -> Logger -> Check -> IO ExitCode
61check config logger check' = do
60check config logger check' = do
62− ((), state) <- runChecker checkDestination config logger check'
61+ ((), write) <- runChecker checkDestination config logger check'
63− failed <- countFailedLinks state
64− return $ if failed > 0 then ExitFailure 1 else ExitSuccess
62+ return $ if checkerFaulty write > 0 then ExitFailure 1 else ExitSuccess
65−
66−
67−--------------------------------------------------------------------------------
68−countFailedLinks :: CheckerState -> IO Int
69−countFailedLinks state = foldM addIfFailure 0 (Map.elems state)
70− where addIfFailure failures mvar = do
71− checkerWrite <- readMVar mvar
72− return $ failures + checkerFaulty checkerWrite
73
63
74
64
75--------------------------------------------------------------------------------
65--------------------------------------------------------------------------------
@@ -88,45 +78,33 @@ data CheckerWrite = CheckerWrite
88
78
89
79
90--------------------------------------------------------------------------------
80--------------------------------------------------------------------------------
91−#if MIN_VERSION_base(4,9,0)
92−instance Semigroup CheckerWrite where
93− (<>) (CheckerWrite f1 o1) (CheckerWrite f2 o2) =
94− CheckerWrite (f1 + f2) (o1 + o2)
95−
96−instance Monoid CheckerWrite where
97− mempty = CheckerWrite 0 0
98− mappend = (<>)
99−#else
100instance Monoid CheckerWrite where
81instance Monoid CheckerWrite where
101 mempty = CheckerWrite 0 0
82 mempty = CheckerWrite 0 0
102 mappend (CheckerWrite f1 o1) (CheckerWrite f2 o2) =
83 mappend (CheckerWrite f1 o1) (CheckerWrite f2 o2) =
103 CheckerWrite (f1 + f2) (o1 + o2)
84 CheckerWrite (f1 + f2) (o1 + o2)
104−#endif
105−
106−
107−--------------------------------------------------------------------------------
108−type CheckerState = Map.Map URL (MVar CheckerWrite)
109
85
110
86
111--------------------------------------------------------------------------------
87--------------------------------------------------------------------------------
112−type Checker a = ReaderT CheckerRead (StateT CheckerState IO) a
88+type CheckerState = Set String
113
89
114
90
115--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
116−type URL = String
92+type Checker a = RWST CheckerRead CheckerWrite CheckerState IO a
117
93
118
94
119--------------------------------------------------------------------------------
95--------------------------------------------------------------------------------
120runChecker :: Checker a -> Configuration -> Logger -> Check
96runChecker :: Checker a -> Configuration -> Logger -> Check
121− -> IO (a, CheckerState)
97+ -> IO (a, CheckerWrite)
122runChecker checker config logger check' = do
98runChecker checker config logger check' = do
123 let read' = CheckerRead
99 let read' = CheckerRead
124 { checkerConfig = config
100 { checkerConfig = config
125 , checkerLogger = logger
101 , checkerLogger = logger
126 , checkerCheck = check'
102 , checkerCheck = check'
127 }
103 }
104+
105+ (x, _, write) <- runRWST checker read' S.empty
128 Logger.flush logger
106 Logger.flush logger
129− runStateT (runReaderT checker read') Map.empty
107+ return (x, write)
130
108
131
109
132--------------------------------------------------------------------------------
110--------------------------------------------------------------------------------
@@ -155,31 +133,14 @@ checkFile filePath = do
155 let urls = getUrls $ TS.parseTags contents
133 let urls = getUrls $ TS.parseTags contents
156 forM_ urls $ \url -> do
134 forM_ urls $ \url -> do
157 Logger.debug logger $ "Checking link " ++ url
135 Logger.debug logger $ "Checking link " ++ url
158− m <- liftIO newEmptyMVar
136+ checkUrl filePath url
159− checkUrlIfNeeded filePath (canonicalizeUrl url) m
160− where
161− -- Check scheme-relative links
162− canonicalizeUrl url = if schemeRelative url then "http:" ++ url else url
163− schemeRelative = isPrefixOf "//"
164−
165−
166−--------------------------------------------------------------------------------
167−checkUrlIfNeeded :: FilePath -> URL -> MVar CheckerWrite -> Checker ()
168−checkUrlIfNeeded filepath url m = do
169− logger <- checkerLogger <$> ask
170− needsCheck <- (== All) . checkerCheck <$> ask
171− checked <- (url `Map.member`) <$> get
172− if not needsCheck || checked
173− then Logger.debug logger "Already checked, skipping"
174− else do modify $ Map.insert url m
175− checkUrl filepath url
176
137
177
138
178--------------------------------------------------------------------------------
139--------------------------------------------------------------------------------
179−checkUrl :: FilePath -> URL -> Checker ()
140+checkUrl :: FilePath -> String -> Checker ()
180checkUrl filePath url
141checkUrl filePath url
181 | isExternal url = checkExternalUrl url
142 | isExternal url = checkExternalUrl url
182− | hasProtocol url = skip url $ Just "Unknown protocol, skipping"
143+ | hasProtocol url = skip "Unknown protocol, skipping"
183 | otherwise = checkInternalUrl filePath url
144 | otherwise = checkInternalUrl filePath url
184 where
145 where
185 validProtoChars = ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "+-."
146 validProtoChars = ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "+-."
@@ -189,45 +150,27 @@ checkUrl filePath url
189
150
190
151
191--------------------------------------------------------------------------------
152--------------------------------------------------------------------------------
192−ok :: URL -> Checker ()
153+ok :: String -> Checker ()
193−ok url = putCheckResult url mempty {checkerOk = 1}
154+ok _ = tell $ mempty {checkerOk = 1}
194
155
195
156
196--------------------------------------------------------------------------------
157--------------------------------------------------------------------------------
197−skip :: URL -> Maybe String -> Checker ()
158+skip :: String -> Checker ()
198−skip url maybeReason = do
159+skip reason = do
199 logger <- checkerLogger <$> ask
160 logger <- checkerLogger <$> ask
200− case maybeReason of
201− Nothing -> return ()
202− Just reason -> Logger.debug logger reason
161+ Logger.debug logger $ reason
203− putCheckResult url mempty {checkerOk = 1}
162+ tell $ mempty {checkerOk = 1}
204−
205
163
206--------------------------------------------------------------------------------
164--------------------------------------------------------------------------------
207−faulty :: URL -> Maybe String -> Checker ()
165+faulty :: String -> Checker ()
208−faulty url reason = do
166+faulty url = do
209 logger <- checkerLogger <$> ask
167 logger <- checkerLogger <$> ask
210− Logger.error logger $ "Broken link to " ++ show url ++ explanation
168+ Logger.error logger $ "Broken link to " ++ show url
211− putCheckResult url mempty {checkerFaulty = 1}
169+ tell $ mempty {checkerFaulty = 1}
212− where
213− formatExplanation = (" (" ++) . (++ ")")
214− explanation = maybe "" formatExplanation reason
215−
216−
217−--------------------------------------------------------------------------------
218−putCheckResult :: URL -> CheckerWrite -> Checker ()
219−putCheckResult url result = do
220− state <- get
221− let maybeMVar = Map.lookup url state
222− case maybeMVar of
223− Just m -> liftIO $ putMVar m result
224− Nothing -> do
225− logger <- checkerLogger <$> ask
226− Logger.debug logger "Failed to find existing entry for checked URL"
227
170
228
171
229--------------------------------------------------------------------------------
172--------------------------------------------------------------------------------
230−checkInternalUrl :: FilePath -> URL -> Checker ()
173+checkInternalUrl :: FilePath -> String -> Checker ()
231checkInternalUrl base url = case url' of
174checkInternalUrl base url = case url' of
232 "" -> ok url
175 "" -> ok url
233 _ -> do
176 _ -> do
@@ -239,52 +182,60 @@ checkInternalUrl base url = case url' of
239 | otherwise = dir </> url'
182 | otherwise = dir </> url'
240
183
241 exists <- checkFileExists filePath
184 exists <- checkFileExists filePath
242− if exists then ok url else faulty url Nothing
185+ if exists then ok url else faulty url
243 where
186 where
244 url' = stripFragments $ unEscapeString url
187 url' = stripFragments $ unEscapeString url
245
188
246
189
247--------------------------------------------------------------------------------
190--------------------------------------------------------------------------------
248−checkExternalUrl :: URL -> Checker ()
191+checkExternalUrl :: String -> Checker ()
249#ifdef CHECK_EXTERNAL
192#ifdef CHECK_EXTERNAL
250checkExternalUrl url = do
193checkExternalUrl url = do
251− result <- requestExternalUrl url
194+ logger <- checkerLogger <$> ask
252− case result of
195+ needsCheck <- (== All) . checkerCheck <$> ask
253− Left (SomeException e) ->
196+ checked <- (url `S.member`) <$> get
254− case (cast e :: Maybe SomeAsyncException) of
197+
255− Just ae -> throw ae
198+ if not needsCheck || checked
256− _ -> faulty url (Just $ showException e)
199+ then Logger.debug logger "Already checked, skipping"
257− Right _ -> ok url
200+ else do
258− where
201+ isOk <- liftIO $ handle (failure logger) $ do
259− -- Convert exception to a concise form
260− showException e = case cast e of
261− Just (Http.HttpExceptionRequest _ e') -> show e'
262− _ -> head $ words $ show e
263−
264−requestExternalUrl :: URL -> Checker (Either SomeException Bool)
265−requestExternalUrl url = liftIO $ try $ do
266− mgr <- Http.newManager Http.tlsManagerSettings
202+ mgr <- Http.newManager Http.tlsManagerSettings
267− runResourceT $ do
203+ runResourceT $ do
268− request <- Http.parseRequest url
204+ request <- Http.parseUrl urlToCheck
269− response <- Http.http (settings request) mgr
205+ response <- Http.http (settings request) mgr
270− let code = Http.statusCode (Http.responseStatus response)
206+ let code = Http.statusCode (Http.responseStatus response)
271− return $ code >= 200 && code < 300
207+ return $ code >= 200 && code < 300
208+
209+ modify $ if schemeRelative url
210+ then S.insert urlToCheck . S.insert url
211+ else S.insert url
212+ if isOk then ok url else faulty url
272− where
213+ where
273− -- Add additional request info
214+ -- Add additional request info
274− settings r = r
215+ settings r = r
275− { Http.method = "HEAD"
216+ { Http.method = "HEAD"
276− , Http.redirectCount = 10
217+ , Http.redirectCount = 10
277− , Http.requestHeaders = ("User-Agent", ua) : Http.requestHeaders r
218+ , Http.requestHeaders = ("User-Agent", ua) : Http.requestHeaders r
278− }
219+ }
279−
220+
280− -- Nice user agent info
221+ -- Nice user agent info
281− ua = fromString $ "hakyll-check/" ++
222+ ua = fromString $ "hakyll-check/" ++
282− (intercalate "." $ map show $ versionBranch Paths_hakyll.version)
223+ (intercalate "." $ map show $ versionBranch $ Paths_hakyll.version)
224+
225+ -- Catch all the things except UserInterrupt
226+ failure logger (SomeException e) = case cast e of
227+ Just UserInterrupt -> throw UserInterrupt
228+ _ -> Logger.error logger (show e) >> return False
229+
230+ -- Check scheme-relative links
231+ schemeRelative = isPrefixOf "//"
232+ urlToCheck = if schemeRelative url then "http:" ++ url else url
283#else
233#else
284−checkExternalUrl url = skip url Nothing
234+checkExternalUrl _ = return ()
285#endif
235#endif
286
236
287
237
238+
288--------------------------------------------------------------------------------
239--------------------------------------------------------------------------------
289-- | Wraps doesFileExist, also checks for index.html
240-- | Wraps doesFileExist, also checks for index.html
290checkFileExists :: FilePath -> Checker Bool
241checkFileExists :: FilePath -> Checker Bool
lib/Hakyll/Commands.hs → src/Hakyll/Commands.hsrenamed+7−14
@@ -2,8 +2,7 @@
2-- | Implementation of Hakyll commands: build, preview...
2-- | Implementation of Hakyll commands: build, preview...
3{-# LANGUAGE CPP #-}
3{-# LANGUAGE CPP #-}
4module Hakyll.Commands
4module Hakyll.Commands
5− ( Check(..)
6− , build
5+ ( build
7 , check
6 , check
8 , clean
7 , clean
9 , preview
8 , preview
@@ -16,11 +15,9 @@ module Hakyll.Commands
16
15
17--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
18import Control.Concurrent
17import Control.Concurrent
19−import System.Exit (ExitCode)
18+import System.Exit (ExitCode, exitWith)
20−
21
19
22--------------------------------------------------------------------------------
20--------------------------------------------------------------------------------
23−import Hakyll.Check (Check(..))
24import qualified Hakyll.Check as Check
21import qualified Hakyll.Check as Check
25import Hakyll.Core.Configuration
22import Hakyll.Core.Configuration
26import Hakyll.Core.Logger (Logger)
23import Hakyll.Core.Logger (Logger)
@@ -30,7 +27,6 @@ import Hakyll.Core.Rules.Internal
30import Hakyll.Core.Runtime
27import Hakyll.Core.Runtime
31import Hakyll.Core.Util.File
28import Hakyll.Core.Util.File
32
29
33−
34--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
35#ifdef WATCH_SERVER
31#ifdef WATCH_SERVER
36import Hakyll.Preview.Poll (watchUpdates)
32import Hakyll.Preview.Poll (watchUpdates)
@@ -40,11 +36,6 @@ import Hakyll.Preview.Poll (watchUpdates)
40import Hakyll.Preview.Server
36import Hakyll.Preview.Server
41#endif
37#endif
42
38
43−#ifdef mingw32_HOST_OS
44−import Control.Monad (void)
45−import System.IO.Error (catchIOError)
46−#endif
47−
48
39
49--------------------------------------------------------------------------------
40--------------------------------------------------------------------------------
50-- | Build the site
41-- | Build the site
@@ -54,8 +45,8 @@ build conf logger rules = fst <$> run conf logger rules
54
45
55--------------------------------------------------------------------------------
46--------------------------------------------------------------------------------
56-- | Run the checker and exit
47-- | Run the checker and exit
57−check :: Configuration -> Logger -> Check.Check -> IO ExitCode
48+check :: Configuration -> Logger -> Check.Check -> IO ()
58−check = Check.check
49+check config logger check' = Check.check config logger check' >>= exitWith
59
50
60
51
61--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
@@ -125,7 +116,9 @@ server :: Configuration -> Logger -> String -> Int -> IO ()
125#ifdef PREVIEW_SERVER
116#ifdef PREVIEW_SERVER
126server conf logger host port = do
117server conf logger host port = do
127 let destination = destinationDirectory conf
118 let destination = destinationDirectory conf
128− staticServer logger destination host port
119+ staticServer logger destination preServeHook host port
120+ where
121+ preServeHook _ = return ()
129#else
122#else
130server _ _ _ _ = previewServerDisabled
123server _ _ _ _ = previewServerDisabled
131#endif
124#endif
lib/Hakyll/Core/Compiler.hs → src/Hakyll/Core/Compiler.hsrenamed+2−44
@@ -24,16 +24,13 @@ module Hakyll.Core.Compiler
24 , cached
24 , cached
25 , unsafeCompiler
25 , unsafeCompiler
26 , debugCompiler
26 , debugCompiler
27− , noResult
28− , withErrorMessage
29 ) where
27 ) where
30
28
31
29
32--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
33−import Control.Monad (unless, when, (>=>))
31+import Control.Monad (when)
34import Data.Binary (Binary)
32import Data.Binary (Binary)
35import Data.ByteString.Lazy (ByteString)
33import Data.ByteString.Lazy (ByteString)
36−import qualified Data.List.NonEmpty as NonEmpty
37import Data.Typeable (Typeable)
34import Data.Typeable (Typeable)
38import System.Environment (getProgName)
35import System.Environment (getProgName)
39import System.FilePath (takeExtension)
36import System.FilePath (takeExtension)
@@ -65,7 +62,6 @@ getUnderlyingExtension = takeExtension . toFilePath <$> getUnderlying
65
62
66
63
67--------------------------------------------------------------------------------
64--------------------------------------------------------------------------------
68−-- | Create an item from the underlying identifier and a given value.
69makeItem :: a -> Compiler (Item a)
65makeItem :: a -> Compiler (Item a)
70makeItem x = do
66makeItem x = do
71 identifier <- getUnderlying
67 identifier <- getUnderlying
@@ -145,10 +141,6 @@ saveSnapshot snapshot item = do
145
141
146
142
147--------------------------------------------------------------------------------
143--------------------------------------------------------------------------------
148−-- | Turn on caching for a compilation value to avoid recomputing it
149−-- on subsequent Hakyll runs.
150−-- The storage key consists of the underlying identifier of the compiled
151−-- ressource and the given name.
152cached :: (Binary a, Typeable a)
144cached :: (Binary a, Typeable a)
153 => String
145 => String
154 -> Compiler a
146 -> Compiler a
@@ -157,10 +149,6 @@ cached name compiler = do
157 id' <- compilerUnderlying <$> compilerAsk
149 id' <- compilerUnderlying <$> compilerAsk
158 store <- compilerStore <$> compilerAsk
150 store <- compilerStore <$> compilerAsk
159 provider <- compilerProvider <$> compilerAsk
151 provider <- compilerProvider <$> compilerAsk
160−
161− -- Give a better error message when the resource is not there at all.
162− unless (resourceExists provider id') $ fail $ itDoesntEvenExist id'
163−
164 let modified = resourceModified provider id'
152 let modified = resourceModified provider id'
165 if modified
153 if modified
166 then do
154 then do
@@ -178,44 +166,14 @@ cached name compiler = do
178 "Hakyll.Core.Compiler.cached: Cache corrupt! " ++
166 "Hakyll.Core.Compiler.cached: Cache corrupt! " ++
179 "Try running: " ++ progName ++ " clean"
167 "Try running: " ++ progName ++ " clean"
180
168
181− itDoesntEvenExist id' =
182− "Hakyll.Core.Compiler.cached: You are trying to (perhaps " ++
183− "indirectly) use `cached` on a non-existing resource: there " ++
184− "is no file backing " ++ show id'
185−
186
169
187--------------------------------------------------------------------------------
170--------------------------------------------------------------------------------
188−-- | Run an IO computation without dependencies in a Compiler
189unsafeCompiler :: IO a -> Compiler a
171unsafeCompiler :: IO a -> Compiler a
190unsafeCompiler = compilerUnsafeIO
172unsafeCompiler = compilerUnsafeIO
191
173
192
174
193--------------------------------------------------------------------------------
175--------------------------------------------------------------------------------
194−-- | Fail so that it is treated as non-defined in an @\$if()\$@ branching
195−-- "Hakyll.Web.Template" macro, and alternative
196−-- 'Hakyll.Web.Template.Context.Context's are tried
197−--
198−-- @since 4.13.0
199−noResult :: String -> Compiler a
200−noResult = compilerNoResult . return
201−
202−
203−--------------------------------------------------------------------------------
204−-- | Prepend an error line to the error, if there is one. This allows you to
205−-- add helpful context to error messages.
206−--
207−-- @since 4.13.0
208−withErrorMessage :: String -> Compiler a -> Compiler a
209−withErrorMessage x = do
210− compilerTry >=> either (compilerResult . CompilerError . prepend) return
211− where
212− prepend (CompilationFailure es) = CompilationFailure (x `NonEmpty.cons` es)
213− prepend (CompilationNoResult es) = CompilationNoResult (x : es)
214−
215−
216−--------------------------------------------------------------------------------
217−-- | Compiler for debugging purposes.
176+-- | Compiler for debugging purposes
218−-- Passes a message to the debug logger that is printed in verbose mode.
219debugCompiler :: String -> Compiler ()
177debugCompiler :: String -> Compiler ()
220debugCompiler msg = do
178debugCompiler msg = do
221 logger <- compilerLogger <$> compilerAsk
179 logger <- compilerLogger <$> compilerAsk
lib/Hakyll/Core/Compiler/Internal.hs → src/Hakyll/Core/Compiler/Internal.hsrenamed+41−140
@@ -1,7 +1,5 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2-- | Internally used compiler module
2-- | Internally used compiler module
3−{-# LANGUAGE CPP #-}
4−{-# LANGUAGE DeriveFunctor #-}
5{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
7{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -11,26 +9,19 @@ module Hakyll.Core.Compiler.Internal
11 Snapshot
9 Snapshot
12 , CompilerRead (..)
10 , CompilerRead (..)
13 , CompilerWrite (..)
11 , CompilerWrite (..)
14− , CompilerErrors (..)
15 , CompilerResult (..)
12 , CompilerResult (..)
16 , Compiler (..)
13 , Compiler (..)
17 , runCompiler
14 , runCompiler
18
15
19 -- * Core operations
16 -- * Core operations
20− , compilerResult
21 , compilerTell
17 , compilerTell
22 , compilerAsk
18 , compilerAsk
23− , compilerUnsafeIO
24−
25− -- * Error operations
26 , compilerThrow
19 , compilerThrow
27− , compilerNoResult
28 , compilerCatch
20 , compilerCatch
29− , compilerTry
21+ , compilerResult
30− , compilerErrorMessages
22+ , compilerUnsafeIO
31
23
32 -- * Utilities
24 -- * Utilities
33− , compilerDebugEntries
34 , compilerTellDependencies
25 , compilerTellDependencies
35 , compilerTellCacheHits
26 , compilerTellCacheHits
36 ) where
27 ) where
@@ -40,12 +31,7 @@ module Hakyll.Core.Compiler.Internal
40import Control.Applicative (Alternative (..))
31import Control.Applicative (Alternative (..))
41import Control.Exception (SomeException, handle)
32import Control.Exception (SomeException, handle)
42import Control.Monad (forM_)
33import Control.Monad (forM_)
43−import Control.Monad.Except (MonadError (..))
34+import Control.Monad.Except (MonadError (..))
44−import Data.List.NonEmpty (NonEmpty (..))
45−import qualified Data.List.NonEmpty as NonEmpty
46−#if MIN_VERSION_base(4,9,0)
47−import Data.Semigroup (Semigroup (..))
48−#endif
49import Data.Set (Set)
35import Data.Set (Set)
50import qualified Data.Set as S
36import qualified Data.Set as S
51
37
@@ -55,6 +41,7 @@ import Hakyll.Core.Configuration
55import Hakyll.Core.Dependencies
41import Hakyll.Core.Dependencies
56import Hakyll.Core.Identifier
42import Hakyll.Core.Identifier
57import Hakyll.Core.Identifier.Pattern
43import Hakyll.Core.Identifier.Pattern
44+import Hakyll.Core.Logger (Logger)
58import qualified Hakyll.Core.Logger as Logger
45import qualified Hakyll.Core.Logger as Logger
59import Hakyll.Core.Metadata
46import Hakyll.Core.Metadata
60import Hakyll.Core.Provider
47import Hakyll.Core.Provider
@@ -84,7 +71,7 @@ data CompilerRead = CompilerRead
84 , -- | Compiler store
71 , -- | Compiler store
85 compilerStore :: Store
72 compilerStore :: Store
86 , -- | Logger
73 , -- | Logger
87− compilerLogger :: Logger.Logger
74+ compilerLogger :: Logger
88 }
75 }
89
76
90
77
@@ -96,46 +83,18 @@ data CompilerWrite = CompilerWrite
96
83
97
84
98--------------------------------------------------------------------------------
85--------------------------------------------------------------------------------
99−#if MIN_VERSION_base(4,9,0)
100−instance Semigroup CompilerWrite where
101− (<>) (CompilerWrite d1 h1) (CompilerWrite d2 h2) =
102− CompilerWrite (d1 ++ d2) (h1 + h2)
103−
104−instance Monoid CompilerWrite where
105− mempty = CompilerWrite [] 0
106− mappend = (<>)
107−#else
108instance Monoid CompilerWrite where
86instance Monoid CompilerWrite where
109 mempty = CompilerWrite [] 0
87 mempty = CompilerWrite [] 0
110 mappend (CompilerWrite d1 h1) (CompilerWrite d2 h2) =
88 mappend (CompilerWrite d1 h1) (CompilerWrite d2 h2) =
111 CompilerWrite (d1 ++ d2) (h1 + h2)
89 CompilerWrite (d1 ++ d2) (h1 + h2)
112−#endif
113
90
114
91
115--------------------------------------------------------------------------------
92--------------------------------------------------------------------------------
116−-- | Distinguishes reasons in a 'CompilerError'
93+data CompilerResult a where
117−data CompilerErrors a
118− -- | One or more exceptions occured during compilation
119− = CompilationFailure (NonEmpty a)
120− -- | Absence of any result, most notably in template contexts. May still
121− -- have error messages.
122− | CompilationNoResult [a]
123− deriving Functor
124−
125−
126−-- | Unwrap a `CompilerErrors`
127−compilerErrorMessages :: CompilerErrors a -> [a]
128−compilerErrorMessages (CompilationFailure x) = NonEmpty.toList x
129−compilerErrorMessages (CompilationNoResult x) = x
130−
131−
132−--------------------------------------------------------------------------------
133−-- | An intermediate result of a compilation step
134−data CompilerResult a
135− = CompilerDone a CompilerWrite
94+ CompilerDone :: a -> CompilerWrite -> CompilerResult a
136− | CompilerSnapshot Snapshot (Compiler a)
95+ CompilerSnapshot :: Snapshot -> Compiler a -> CompilerResult a
96+ CompilerError :: [String] -> CompilerResult a
137− | CompilerRequire (Identifier, Snapshot) (Compiler a)
97+ CompilerRequire :: (Identifier, Snapshot) -> Compiler a -> CompilerResult a
138− | CompilerError (CompilerErrors String)
139
98
140
99
141--------------------------------------------------------------------------------
100--------------------------------------------------------------------------------
@@ -153,14 +112,14 @@ instance Functor Compiler where
153 return $ case res of
112 return $ case res of
154 CompilerDone x w -> CompilerDone (f x) w
113 CompilerDone x w -> CompilerDone (f x) w
155 CompilerSnapshot s c' -> CompilerSnapshot s (fmap f c')
114 CompilerSnapshot s c' -> CompilerSnapshot s (fmap f c')
156− CompilerRequire i c' -> CompilerRequire i (fmap f c')
157 CompilerError e -> CompilerError e
115 CompilerError e -> CompilerError e
116+ CompilerRequire i c' -> CompilerRequire i (fmap f c')
158 {-# INLINE fmap #-}
117 {-# INLINE fmap #-}
159
118
160
119
161--------------------------------------------------------------------------------
120--------------------------------------------------------------------------------
162instance Monad Compiler where
121instance Monad Compiler where
163− return x = compilerResult $ CompilerDone x mempty
122+ return x = Compiler $ \_ -> return $ CompilerDone x mempty
164 {-# INLINE return #-}
123 {-# INLINE return #-}
165
124
166 Compiler c >>= f = Compiler $ \r -> do
125 Compiler c >>= f = Compiler $ \r -> do
@@ -173,14 +132,14 @@ instance Monad Compiler where
173 CompilerSnapshot s c' -> CompilerSnapshot s $ do
132 CompilerSnapshot s c' -> CompilerSnapshot s $ do
174 compilerTell w -- Save dependencies!
133 compilerTell w -- Save dependencies!
175 c'
134 c'
135+ CompilerError e -> CompilerError e
176 CompilerRequire i c' -> CompilerRequire i $ do
136 CompilerRequire i c' -> CompilerRequire i $ do
177 compilerTell w -- Save dependencies!
137 compilerTell w -- Save dependencies!
178 c'
138 c'
179− CompilerError e -> CompilerError e
180
139
181 CompilerSnapshot s c' -> return $ CompilerSnapshot s (c' >>= f)
140 CompilerSnapshot s c' -> return $ CompilerSnapshot s (c' >>= f)
182− CompilerRequire i c' -> return $ CompilerRequire i (c' >>= f)
183 CompilerError e -> return $ CompilerError e
141 CompilerError e -> return $ CompilerError e
142+ CompilerRequire i c' -> return $ CompilerRequire i (c' >>= f)
184 {-# INLINE (>>=) #-}
143 {-# INLINE (>>=) #-}
185
144
186 fail = compilerThrow . return
145 fail = compilerThrow . return
@@ -197,145 +156,87 @@ instance Applicative Compiler where
197
156
198
157
199--------------------------------------------------------------------------------
158--------------------------------------------------------------------------------
200−-- | Access provided metadata from anywhere
201instance MonadMetadata Compiler where
159instance MonadMetadata Compiler where
202 getMetadata = compilerGetMetadata
160 getMetadata = compilerGetMetadata
203 getMatches = compilerGetMatches
161 getMatches = compilerGetMatches
204
162
205
163
206--------------------------------------------------------------------------------
164--------------------------------------------------------------------------------
207−-- | Compilation may fail with multiple error messages.
208−-- 'catchError' handles errors from 'throwError', 'fail' and 'Hakyll.Core.Compiler.noResult'
209instance MonadError [String] Compiler where
165instance MonadError [String] Compiler where
210− throwError = compilerThrow
166+ throwError = compilerThrow
211− catchError c = compilerCatch c . (. compilerErrorMessages)
167+ catchError = compilerCatch
212
168
213
169
214--------------------------------------------------------------------------------
170--------------------------------------------------------------------------------
215−-- | Like 'unCompiler' but treating IO exceptions as 'CompilerError's
216runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
171runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
217runCompiler compiler read' = handle handler $ unCompiler compiler read'
172runCompiler compiler read' = handle handler $ unCompiler compiler read'
218 where
173 where
219 handler :: SomeException -> IO (CompilerResult a)
174 handler :: SomeException -> IO (CompilerResult a)
220− handler e = return $ CompilerError $ CompilationFailure $ show e :| []
175+ handler e = return $ CompilerError [show e]
221
176
222
177
223--------------------------------------------------------------------------------
178--------------------------------------------------------------------------------
224−-- | Trying alternative compilers if the first fails, regardless whether through
225−-- 'fail', 'throwError' or 'Hakyll.Core.Compiler.noResult'.
226−-- Aggregates error messages if all fail.
227instance Alternative Compiler where
179instance Alternative Compiler where
228− empty = compilerNoResult []
180+ empty = compilerThrow []
229− x <|> y = x `compilerCatch` (\rx -> y `compilerCatch` (\ry ->
181+ x <|> y = compilerCatch x $ \es -> do
230− case (rx, ry) of
182+ logger <- compilerLogger <$> compilerAsk
231− (CompilationFailure xs, CompilationFailure ys) ->
183+ forM_ es $ \e -> compilerUnsafeIO $ Logger.debug logger $
232− compilerThrow $ NonEmpty.toList xs ++ NonEmpty.toList ys
233− (CompilationFailure xs, CompilationNoResult ys) ->
234− debug ys >> compilerThrow (NonEmpty.toList xs)
235− (CompilationNoResult xs, CompilationFailure ys) ->
236− debug xs >> compilerThrow (NonEmpty.toList ys)
237− (CompilationNoResult xs, CompilationNoResult ys) -> compilerNoResult $ xs ++ ys
238− ))
239− where
240− debug = compilerDebugEntries "Hakyll.Core.Compiler.Internal: Alternative fail suppressed"
184+ "Hakyll.Core.Compiler.Internal: Alternative failed: " ++ e
185+ y
241 {-# INLINE (<|>) #-}
186 {-# INLINE (<|>) #-}
242
187
243
188
244--------------------------------------------------------------------------------
189--------------------------------------------------------------------------------
245−-- | Put the result back in a compiler
246−compilerResult :: CompilerResult a -> Compiler a
247−compilerResult x = Compiler $ \_ -> return x
248−{-# INLINE compilerResult #-}
249−
250−
251−--------------------------------------------------------------------------------
252−-- | Get the current environment
253compilerAsk :: Compiler CompilerRead
190compilerAsk :: Compiler CompilerRead
254compilerAsk = Compiler $ \r -> return $ CompilerDone r mempty
191compilerAsk = Compiler $ \r -> return $ CompilerDone r mempty
255{-# INLINE compilerAsk #-}
192{-# INLINE compilerAsk #-}
256
193
257
194
258--------------------------------------------------------------------------------
195--------------------------------------------------------------------------------
259−-- | Put a 'CompilerWrite'
260compilerTell :: CompilerWrite -> Compiler ()
196compilerTell :: CompilerWrite -> Compiler ()
261−compilerTell = compilerResult . CompilerDone ()
197+compilerTell deps = Compiler $ \_ -> return $ CompilerDone () deps
262{-# INLINE compilerTell #-}
198{-# INLINE compilerTell #-}
263
199
264
200
265--------------------------------------------------------------------------------
201--------------------------------------------------------------------------------
266−-- | Run an IO computation without dependencies in a Compiler
267−compilerUnsafeIO :: IO a -> Compiler a
268−compilerUnsafeIO io = Compiler $ \_ -> do
269− x <- io
270− return $ CompilerDone x mempty
271−{-# INLINE compilerUnsafeIO #-}
272−
273−
274−--------------------------------------------------------------------------------
275−-- | Throw errors in the 'Compiler'.
276−--
277−-- If no messages are given, this is considered a 'CompilationNoResult' error.
278−-- Otherwise, it is treated as a proper compilation failure.
279compilerThrow :: [String] -> Compiler a
202compilerThrow :: [String] -> Compiler a
280−compilerThrow = compilerResult . CompilerError .
203+compilerThrow es = Compiler $ \_ -> return $ CompilerError es
281− maybe (CompilationNoResult []) CompilationFailure .
204+{-# INLINE compilerThrow #-}
282− NonEmpty.nonEmpty
283−
284−-- | Put a 'CompilerError' with multiple messages as 'CompilationNoResult'
285−compilerNoResult :: [String] -> Compiler a
286−compilerNoResult = compilerResult . CompilerError . CompilationNoResult
287
205
288
206
289--------------------------------------------------------------------------------
207--------------------------------------------------------------------------------
290−-- | Allows to distinguish 'CompilerError's and branch on them with 'Either'
291−--
292−-- prop> compilerTry = (`compilerCatch` return . Left) . fmap Right
293−compilerTry :: Compiler a -> Compiler (Either (CompilerErrors String) a)
294−compilerTry (Compiler x) = Compiler $ \r -> do
295− res <- x r
296− case res of
297− CompilerDone res' w -> return (CompilerDone (Right res') w)
298− CompilerSnapshot s c -> return (CompilerSnapshot s (compilerTry c))
299− CompilerRequire i c -> return (CompilerRequire i (compilerTry c))
300− CompilerError e -> return (CompilerDone (Left e) mempty)
301−{-# INLINE compilerTry #-}
302−
303−
304−--------------------------------------------------------------------------------
305−-- | Allows you to recover from 'CompilerError's.
306−-- Uses the same parameter order as 'catchError' so that it can be used infix.
307−--
308−-- prop> c `compilerCatch` f = compilerTry c >>= either f return
309−compilerCatch :: Compiler a -> (CompilerErrors String -> Compiler a) -> Compiler a
208+compilerCatch :: Compiler a -> ([String] -> Compiler a) -> Compiler a
310compilerCatch (Compiler x) f = Compiler $ \r -> do
209compilerCatch (Compiler x) f = Compiler $ \r -> do
311 res <- x r
210 res <- x r
312 case res of
211 case res of
313 CompilerDone res' w -> return (CompilerDone res' w)
212 CompilerDone res' w -> return (CompilerDone res' w)
314 CompilerSnapshot s c -> return (CompilerSnapshot s (compilerCatch c f))
213 CompilerSnapshot s c -> return (CompilerSnapshot s (compilerCatch c f))
315− CompilerRequire i c -> return (CompilerRequire i (compilerCatch c f))
316 CompilerError e -> unCompiler (f e) r
214 CompilerError e -> unCompiler (f e) r
215+ CompilerRequire i c -> return (CompilerRequire i (compilerCatch c f))
317{-# INLINE compilerCatch #-}
216{-# INLINE compilerCatch #-}
318
217
319
218
320--------------------------------------------------------------------------------
219--------------------------------------------------------------------------------
321−compilerDebugLog :: [String] -> Compiler ()
220+-- | Put the result back in a compiler
322−compilerDebugLog ms = do
221+compilerResult :: CompilerResult a -> Compiler a
323− logger <- compilerLogger <$> compilerAsk
222+compilerResult x = Compiler $ \_ -> return x
324− compilerUnsafeIO $ forM_ ms $ Logger.debug logger
223+{-# INLINE compilerResult #-}
224+
325
225
326--------------------------------------------------------------------------------
226--------------------------------------------------------------------------------
327−-- | Pass a list of messages with a heading to the debug logger
227+compilerUnsafeIO :: IO a -> Compiler a
328−compilerDebugEntries :: String -> [String] -> Compiler ()
228+compilerUnsafeIO io = Compiler $ \_ -> do
329−compilerDebugEntries msg = compilerDebugLog . (msg:) . map indent
229+ x <- io
330− where
230+ return $ CompilerDone x mempty
331− indent = unlines . map (" "++) . lines
231+{-# INLINE compilerUnsafeIO #-}
332
232
333
233
334--------------------------------------------------------------------------------
234--------------------------------------------------------------------------------
335compilerTellDependencies :: [Dependency] -> Compiler ()
235compilerTellDependencies :: [Dependency] -> Compiler ()
336compilerTellDependencies ds = do
236compilerTellDependencies ds = do
337− compilerDebugLog $ map (\d ->
237+ logger <- compilerLogger <$> compilerAsk
238+ forM_ ds $ \d -> compilerUnsafeIO $ Logger.debug logger $
338− "Hakyll.Core.Compiler.Internal: Adding dependency: " ++ show d) ds
239+ "Hakyll.Core.Compiler.Internal: Adding dependency: " ++ show d
339 compilerTell mempty {compilerDependencies = ds}
240 compilerTell mempty {compilerDependencies = ds}
340{-# INLINE compilerTellDependencies #-}
241{-# INLINE compilerTellDependencies #-}
341
242
lib/Hakyll/Core/Compiler/Require.hs → src/Hakyll/Core/Compiler/Require.hsrenamed−2
@@ -91,7 +91,6 @@ loadBody id' = loadSnapshotBody id' final
91
91
92
92
93--------------------------------------------------------------------------------
93--------------------------------------------------------------------------------
94−-- | A shortcut for only requiring the body for a specific snapshot of an item
95loadSnapshotBody :: (Binary a, Typeable a)
94loadSnapshotBody :: (Binary a, Typeable a)
96 => Identifier -> Snapshot -> Compiler a
95 => Identifier -> Snapshot -> Compiler a
97loadSnapshotBody id' snapshot = fmap itemBody $ loadSnapshot id' snapshot
96loadSnapshotBody id' snapshot = fmap itemBody $ loadSnapshot id' snapshot
@@ -104,7 +103,6 @@ loadAll pattern = loadAllSnapshots pattern final
104
103
105
104
106--------------------------------------------------------------------------------
105--------------------------------------------------------------------------------
107−-- | Load a specific snapshot for each of dynamic list of items
108loadAllSnapshots :: (Binary a, Typeable a)
106loadAllSnapshots :: (Binary a, Typeable a)
109 => Pattern -> Snapshot -> Compiler [Item a]
107 => Pattern -> Snapshot -> Compiler [Item a]
110loadAllSnapshots pattern snapshot = do
108loadAllSnapshots pattern snapshot = do
lib/Hakyll/Core/Configuration.hs → src/Hakyll/Core/Configuration.hsrenamed

The content is the same.

lib/Hakyll/Core/Dependencies.hs → src/Hakyll/Core/Dependencies.hsrenamed

The content is the same.

lib/Hakyll/Core/File.hs → src/Hakyll/Core/File.hsrenamed+3−11
@@ -1,6 +1,5 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2-- | Exports simple compilers to just copy files
2-- | Exports simple compilers to just copy files
3−{-# LANGUAGE CPP #-}
4{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveDataTypeable #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6module Hakyll.Core.File
5module Hakyll.Core.File
@@ -14,12 +13,7 @@ module Hakyll.Core.File
14--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
15import Data.Binary (Binary (..))
14import Data.Binary (Binary (..))
16import Data.Typeable (Typeable)
15import Data.Typeable (Typeable)
17−#if MIN_VERSION_directory(1,2,6)
18−import System.Directory (copyFileWithMetadata)
19−#else
20−import System.Directory (copyFile)
16+import System.Directory (copyFile, doesFileExist,
21−#endif
22−import System.Directory (doesFileExist,
23 renameFile)
17 renameFile)
24import System.FilePath ((</>))
18import System.FilePath ((</>))
25import System.Random (randomIO)
19import System.Random (randomIO)
@@ -44,11 +38,9 @@ newtype CopyFile = CopyFile FilePath
44
38
45--------------------------------------------------------------------------------
39--------------------------------------------------------------------------------
46instance Writable CopyFile where
40instance Writable CopyFile where
47−#if MIN_VERSION_directory(1,2,6)
48− write dst (Item _ (CopyFile src)) = copyFileWithMetadata src dst
49−#else
50 write dst (Item _ (CopyFile src)) = copyFile src dst
41 write dst (Item _ (CopyFile src)) = copyFile src dst
51−#endif
42+
43+
52--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
53copyFileCompiler :: Compiler (Item CopyFile)
45copyFileCompiler :: Compiler (Item CopyFile)
54copyFileCompiler = do
46copyFileCompiler = do
lib/Hakyll/Core/Identifier.hs → src/Hakyll/Core/Identifier.hsrenamed+1−1
@@ -62,7 +62,7 @@ instance Show Identifier where
62
62
63--------------------------------------------------------------------------------
63--------------------------------------------------------------------------------
64-- | Parse an identifier from a string
64-- | Parse an identifier from a string
65−fromFilePath :: FilePath -> Identifier
65+fromFilePath :: String -> Identifier
66fromFilePath = Identifier Nothing .
66fromFilePath = Identifier Nothing .
67 intercalate "/" . filter (not . null) . split'
67 intercalate "/" . filter (not . null) . split'
68 where
68 where
lib/Hakyll/Core/Identifier/Pattern.hs → src/Hakyll/Core/Identifier/Pattern.hsrenamed+72−14
@@ -27,8 +27,7 @@
27-- * @\"foo\/*.html\"@ will match all HTML files in the @\"foo\/\"@ directory.
27-- * @\"foo\/*.html\"@ will match all HTML files in the @\"foo\/\"@ directory.
28--
28--
29-- The 'capture' function allows the user to get access to the elements captured
29-- The 'capture' function allows the user to get access to the elements captured
30−-- by the capture elements in a glob or regex pattern.
30+-- by the capture elements in the pattern.
31−{-# OPTIONS_GHC -fno-warn-orphans #-}
32module Hakyll.Core.Identifier.Pattern
31module Hakyll.Core.Identifier.Pattern
33 ( -- * The pattern type
32 ( -- * The pattern type
34 Pattern
33 Pattern
@@ -58,22 +57,77 @@ module Hakyll.Core.Identifier.Pattern
58
57
59
58
60--------------------------------------------------------------------------------
59--------------------------------------------------------------------------------
61−import Control.Arrow ((&&&), (>>>))
60+import Control.Arrow ((&&&), (>>>))
62−import Control.Monad (msum)
61+import Control.Monad (msum)
62+import Data.Binary (Binary (..), getWord8, putWord8)
63−import Data.List (inits, isPrefixOf,
63+import Data.List (inits, isPrefixOf, tails)
64− tails)
65−import Data.Maybe (isJust)
64+import Data.Maybe (isJust)
65+import Data.Set (Set)
66−import qualified Data.Set as S
66+import qualified Data.Set as S
67
67
68
68
69--------------------------------------------------------------------------------
69--------------------------------------------------------------------------------
70−import GHC.Exts (IsString, fromString)
70+import GHC.Exts (IsString, fromString)
71−import Text.Regex.TDFA ((=~))
71+import Text.Regex.TDFA ((=~))
72
72
73
73
74--------------------------------------------------------------------------------
74--------------------------------------------------------------------------------
75import Hakyll.Core.Identifier
75import Hakyll.Core.Identifier
76−import Hakyll.Core.Identifier.Pattern.Internal
76+
77+
78+--------------------------------------------------------------------------------
79+-- | Elements of a glob pattern
80+data GlobComponent
81+ = Capture
82+ | CaptureMany
83+ | Literal String
84+ deriving (Eq, Show)
85+
86+
87+--------------------------------------------------------------------------------
88+instance Binary GlobComponent where
89+ put Capture = putWord8 0
90+ put CaptureMany = putWord8 1
91+ put (Literal s) = putWord8 2 >> put s
92+
93+ get = getWord8 >>= \t -> case t of
94+ 0 -> pure Capture
95+ 1 -> pure CaptureMany
96+ 2 -> Literal <$> get
97+ _ -> error "Data.Binary.get: Invalid GlobComponent"
98+
99+
100+--------------------------------------------------------------------------------
101+-- | Type that allows matching on identifiers
102+data Pattern
103+ = Everything
104+ | Complement Pattern
105+ | And Pattern Pattern
106+ | Glob [GlobComponent]
107+ | List (Set Identifier)
108+ | Regex String
109+ | Version (Maybe String)
110+ deriving (Show)
111+
112+
113+--------------------------------------------------------------------------------
114+instance Binary Pattern where
115+ put Everything = putWord8 0
116+ put (Complement p) = putWord8 1 >> put p
117+ put (And x y) = putWord8 2 >> put x >> put y
118+ put (Glob g) = putWord8 3 >> put g
119+ put (List is) = putWord8 4 >> put is
120+ put (Regex r) = putWord8 5 >> put r
121+ put (Version v) = putWord8 6 >> put v
122+
123+ get = getWord8 >>= \t -> case t of
124+ 0 -> pure Everything
125+ 1 -> Complement <$> get
126+ 2 -> And <$> get <*> get
127+ 3 -> Glob <$> get
128+ 4 -> List <$> get
129+ 5 -> Regex <$> get
130+ _ -> Version <$> get
77
131
78
132
79--------------------------------------------------------------------------------
133--------------------------------------------------------------------------------
@@ -81,6 +135,12 @@ instance IsString Pattern where
81 fromString = fromGlob
135 fromString = fromGlob
82
136
83
137
138+--------------------------------------------------------------------------------
139+instance Monoid Pattern where
140+ mempty = Everything
141+ mappend = (.&&.)
142+
143+
84--------------------------------------------------------------------------------
144--------------------------------------------------------------------------------
85-- | Parse a pattern from a string
145-- | Parse a pattern from a string
86fromGlob :: String -> Pattern
146fromGlob :: String -> Pattern
@@ -200,11 +260,9 @@ splits = inits &&& tails >>> uncurry zip >>> reverse
200
260
201
261
202--------------------------------------------------------------------------------
262--------------------------------------------------------------------------------
203−-- | Match a glob or regex pattern against an identifier, generating a list of captures
263+-- | Match a glob against a pattern, generating a list of captures
204capture :: Pattern -> Identifier -> Maybe [String]
264capture :: Pattern -> Identifier -> Maybe [String]
205capture (Glob p) i = capture' p (toFilePath i)
265capture (Glob p) i = capture' p (toFilePath i)
206−capture (Regex pat) i = Just groups
207− where (_, _, _, groups) = ((toFilePath i) =~ pat) :: (String, String, String, [String])
208capture _ _ = Nothing
266capture _ _ = Nothing
209
267
210
268
lib/Hakyll/Core/Item.hs → src/Hakyll/Core/Item.hsrenamed

The content is the same.

lib/Hakyll/Core/Item/SomeItem.hs → src/Hakyll/Core/Item/SomeItem.hsrenamed

The content is the same.

lib/Hakyll/Core/Logger.hs → src/Hakyll/Core/Logger.hsrenamed+3−9
@@ -18,7 +18,6 @@ import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
18import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
18import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
19import Control.Monad (forever)
19import Control.Monad (forever)
20import Control.Monad.Trans (MonadIO, liftIO)
20import Control.Monad.Trans (MonadIO, liftIO)
21−import Data.List (intercalate)
22import Prelude hiding (error)
21import Prelude hiding (error)
23
22
24
23
@@ -80,7 +79,7 @@ string l v m
80
79
81--------------------------------------------------------------------------------
80--------------------------------------------------------------------------------
82error :: MonadIO m => Logger -> String -> m ()
81error :: MonadIO m => Logger -> String -> m ()
83−error l m = string l Error $ " [ERROR] " ++ indent m
82+error l m = string l Error $ " [ERROR] " ++ m
84
83
85
84
86--------------------------------------------------------------------------------
85--------------------------------------------------------------------------------
@@ -90,14 +89,9 @@ header l = string l Message
90
89
91--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
92message :: MonadIO m => Logger -> String -> m ()
91message :: MonadIO m => Logger -> String -> m ()
93−message l m = string l Message $ " " ++ indent m
92+message l m = string l Message $ " " ++ m
94
93
95
94
96--------------------------------------------------------------------------------
95--------------------------------------------------------------------------------
97debug :: MonadIO m => Logger -> String -> m ()
96debug :: MonadIO m => Logger -> String -> m ()
98−debug l m = string l Debug $ " [DEBUG] " ++ indent m
97+debug l m = string l Debug $ " [DEBUG] " ++ m
99−
100−
101−--------------------------------------------------------------------------------
102−indent :: String -> String
103−indent = intercalate "\n " . lines
lib/Hakyll/Core/Metadata.hs → src/Hakyll/Core/Metadata.hsrenamed

The content is the same.

lib/Hakyll/Core/Provider.hs → src/Hakyll/Core/Provider.hsrenamed

The content is the same.

lib/Hakyll/Core/Provider/Internal.hs → src/Hakyll/Core/Provider/Internal.hsrenamed

The content is the same.

lib/Hakyll/Core/Provider/Metadata.hs → src/Hakyll/Core/Provider/Metadata.hsrenamed+2−5
@@ -14,7 +14,6 @@ module Hakyll.Core.Provider.Metadata
14import Control.Arrow (second)
14import Control.Arrow (second)
15import Control.Exception (Exception, throwIO)
15import Control.Exception (Exception, throwIO)
16import Control.Monad (guard)
16import Control.Monad (guard)
17−import qualified Data.ByteString as B
18import qualified Data.ByteString.Char8 as BC
17import qualified Data.ByteString.Char8 as BC
19import Data.List.Extended (breakWhen)
18import Data.List.Extended (breakWhen)
20import qualified Data.Map as M
19import qualified Data.Map as M
@@ -27,7 +26,6 @@ import Hakyll.Core.Identifier
27import Hakyll.Core.Metadata
26import Hakyll.Core.Metadata
28import Hakyll.Core.Provider.Internal
27import Hakyll.Core.Provider.Internal
29import System.IO as IO
28import System.IO as IO
30−import System.IO.Error (modifyIOError, ioeSetLocation)
31
29
32
30
33--------------------------------------------------------------------------------
31--------------------------------------------------------------------------------
@@ -52,7 +50,7 @@ loadMetadata p identifier = do
52--------------------------------------------------------------------------------
50--------------------------------------------------------------------------------
53loadMetadataHeader :: FilePath -> IO (Metadata, String)
51loadMetadataHeader :: FilePath -> IO (Metadata, String)
54loadMetadataHeader fp = do
52loadMetadataHeader fp = do
55− fileContent <- modifyIOError (`ioeSetLocation` "loadMetadataHeader") $ readFile fp
53+ fileContent <- readFile fp
56 case parsePage fileContent of
54 case parsePage fileContent of
57 Right x -> return x
55 Right x -> return x
58 Left err -> throwIO $ MetadataException fp err
56 Left err -> throwIO $ MetadataException fp err
@@ -61,8 +59,7 @@ loadMetadataHeader fp = do
61--------------------------------------------------------------------------------
59--------------------------------------------------------------------------------
62loadMetadataFile :: FilePath -> IO Metadata
60loadMetadataFile :: FilePath -> IO Metadata
63loadMetadataFile fp = do
61loadMetadataFile fp = do
64− fileContent <- modifyIOError (`ioeSetLocation` "loadMetadataFile") $ B.readFile fp
62+ errOrMeta <- Yaml.decodeFileEither fp
65− let errOrMeta = Yaml.decodeEither' fileContent
66 either (fail . show) return errOrMeta
63 either (fail . show) return errOrMeta
67
64
68
65
lib/Hakyll/Core/Provider/MetadataCache.hs → src/Hakyll/Core/Provider/MetadataCache.hsrenamed

The content is the same.

lib/Hakyll/Core/Routes.hs → src/Hakyll/Core/Routes.hsrenamed−17
@@ -25,7 +25,6 @@
25-- not appear in your site directory.
25-- not appear in your site directory.
26--
26--
27-- * If an item matches multiple routes, the first rule will be chosen.
27-- * If an item matches multiple routes, the first rule will be chosen.
28−{-# LANGUAGE CPP #-}
29{-# LANGUAGE Rank2Types #-}
28{-# LANGUAGE Rank2Types #-}
30module Hakyll.Core.Routes
29module Hakyll.Core.Routes
31 ( UsedMetadata
30 ( UsedMetadata
@@ -43,9 +42,6 @@ module Hakyll.Core.Routes
43
42
44
43
45--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
46−#if MIN_VERSION_base(4,9,0)
47−import Data.Semigroup (Semigroup (..))
48−#endif
49import System.FilePath (replaceExtension)
45import System.FilePath (replaceExtension)
50
46
51
47
@@ -78,18 +74,6 @@ newtype Routes = Routes
78
74
79
75
80--------------------------------------------------------------------------------
76--------------------------------------------------------------------------------
81−#if MIN_VERSION_base(4,9,0)
82−instance Semigroup Routes where
83− (<>) (Routes f) (Routes g) = Routes $ \p id' -> do
84− (mfp, um) <- f p id'
85− case mfp of
86− Nothing -> g p id'
87− Just _ -> return (mfp, um)
88−
89−instance Monoid Routes where
90− mempty = Routes $ \_ _ -> return (Nothing, False)
91− mappend = (<>)
92−#else
93instance Monoid Routes where
77instance Monoid Routes where
94 mempty = Routes $ \_ _ -> return (Nothing, False)
78 mempty = Routes $ \_ _ -> return (Nothing, False)
95 mappend (Routes f) (Routes g) = Routes $ \p id' -> do
79 mappend (Routes f) (Routes g) = Routes $ \p id' -> do
@@ -97,7 +81,6 @@ instance Monoid Routes where
97 case mfp of
81 case mfp of
98 Nothing -> g p id'
82 Nothing -> g p id'
99 Just _ -> return (mfp, um)
83 Just _ -> return (mfp, um)
100−#endif
101
84
102
85
103--------------------------------------------------------------------------------
86--------------------------------------------------------------------------------
lib/Hakyll/Core/Rules.hs → src/Hakyll/Core/Rules.hsrenamed

The content is the same.

lib/Hakyll/Core/Rules/Internal.hs → src/Hakyll/Core/Rules/Internal.hsrenamed−14
@@ -1,5 +1,4 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−{-# LANGUAGE CPP #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE Rank2Types #-}
3{-# LANGUAGE Rank2Types #-}
5module Hakyll.Core.Rules.Internal
4module Hakyll.Core.Rules.Internal
@@ -17,9 +16,6 @@ import Control.Monad.Reader (ask)
17import Control.Monad.RWS (RWST, runRWST)
16import Control.Monad.RWS (RWST, runRWST)
18import Control.Monad.Trans (liftIO)
17import Control.Monad.Trans (liftIO)
19import qualified Data.Map as M
18import qualified Data.Map as M
20−#if MIN_VERSION_base(4,9,0)
21−import Data.Semigroup (Semigroup (..))
22−#endif
23import Data.Set (Set)
19import Data.Set (Set)
24
20
25
21
@@ -56,20 +52,10 @@ data RuleSet = RuleSet
56
52
57
53
58--------------------------------------------------------------------------------
54--------------------------------------------------------------------------------
59−#if MIN_VERSION_base(4,9,0)
60−instance Semigroup RuleSet where
61− (<>) (RuleSet r1 c1 s1 p1) (RuleSet r2 c2 s2 p2) =
62− RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2) (p1 .||. p2)
63−
64−instance Monoid RuleSet where
65− mempty = RuleSet mempty mempty mempty mempty
66− mappend = (<>)
67−#else
68instance Monoid RuleSet where
55instance Monoid RuleSet where
69 mempty = RuleSet mempty mempty mempty mempty
56 mempty = RuleSet mempty mempty mempty mempty
70 mappend (RuleSet r1 c1 s1 p1) (RuleSet r2 c2 s2 p2) =
57 mappend (RuleSet r1 c1 s1 p1) (RuleSet r2 c2 s2 p2) =
71 RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2) (p1 .||. p2)
58 RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2) (p1 .||. p2)
72−#endif
73
59
74
60
75--------------------------------------------------------------------------------
61--------------------------------------------------------------------------------
lib/Hakyll/Core/Runtime.hs → src/Hakyll/Core/Runtime.hsrenamed+3−3
@@ -199,9 +199,9 @@ chase trail id'
199 result <- liftIO $ runCompiler compiler read'
199 result <- liftIO $ runCompiler compiler read'
200 case result of
200 case result of
201 -- Rethrow error
201 -- Rethrow error
202− CompilerError e -> throwError $ case compilerErrorMessages e of
202+ CompilerError [] -> throwError
203− [] -> "Compiler failed but no info given, try running with -v?"
203+ "Compiler failed but no info given, try running with -v?"
204− es -> intercalate "; " es
204+ CompilerError es -> throwError $ intercalate "; " es
205
205
206 -- Signal that a snapshot was saved ->
206 -- Signal that a snapshot was saved ->
207 CompilerSnapshot snapshot c -> do
207 CompilerSnapshot snapshot c -> do
lib/Hakyll/Core/Store.hs → src/Hakyll/Core/Store.hsrenamed+23−26
@@ -16,6 +16,7 @@ module Hakyll.Core.Store
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
19+import Control.Exception (IOException, handle)
19import qualified Crypto.Hash.MD5 as MD5
20import qualified Crypto.Hash.MD5 as MD5
20import Data.Binary (Binary, decode, encodeFile)
21import Data.Binary (Binary, decode, encodeFile)
21import qualified Data.ByteString as B
22import qualified Data.ByteString as B
@@ -26,13 +27,11 @@ import Data.Maybe (isJust)
26import qualified Data.Text as T
27import qualified Data.Text as T
27import qualified Data.Text.Encoding as T
28import qualified Data.Text.Encoding as T
28import Data.Typeable (TypeRep, Typeable, cast, typeOf)
29import Data.Typeable (TypeRep, Typeable, cast, typeOf)
29−import Numeric (showHex)
30import System.Directory (createDirectoryIfMissing)
30import System.Directory (createDirectoryIfMissing)
31import System.Directory (doesFileExist, removeFile)
31import System.Directory (doesFileExist, removeFile)
32import System.FilePath ((</>))
32import System.FilePath ((</>))
33import System.IO (IOMode (..), hClose, openFile)
33import System.IO (IOMode (..), hClose, openFile)
34−import System.IO.Error (catchIOError, ioeSetFileName,
34+import Text.Printf (printf)
35− ioeSetLocation, modifyIOError)
36
35
37
36
38--------------------------------------------------------------------------------
37--------------------------------------------------------------------------------
@@ -85,14 +84,6 @@ new inMemory directory = do
85 where
84 where
86 csize = Just 500
85 csize = Just 500
87
86
88−--------------------------------------------------------------------------------
89−withStore :: Store -> String -> (String -> FilePath -> IO a) -> [String] -> IO a
90−withStore store loc run identifier = modifyIOError handle $ run key path
91− where
92− key = hash identifier
93− path = storeDirectory store </> key
94− handle e = e `ioeSetFileName` (path ++ " for " ++ intercalate "/" identifier)
95− `ioeSetLocation` ("Store." ++ loc)
96
87
97--------------------------------------------------------------------------------
88--------------------------------------------------------------------------------
98-- | Auxiliary: add an item to the in-memory cache
89-- | Auxiliary: add an item to the in-memory cache
@@ -133,16 +124,17 @@ cacheDelete (Store _ (Just lru)) key = do
133--------------------------------------------------------------------------------
124--------------------------------------------------------------------------------
134-- | Store an item
125-- | Store an item
135set :: (Binary a, Typeable a) => Store -> [String] -> a -> IO ()
126set :: (Binary a, Typeable a) => Store -> [String] -> a -> IO ()
136−set store identifier value = withStore store "set" (\key path -> do
127+set store identifier value = do
137− encodeFile path value
128+ encodeFile (storeDirectory store </> key) value
138 cacheInsert store key value
129 cacheInsert store key value
130+ where
139− ) identifier
131+ key = hash identifier
140
132
141
133
142--------------------------------------------------------------------------------
134--------------------------------------------------------------------------------
143-- | Load an item
135-- | Load an item
144get :: (Binary a, Typeable a) => Store -> [String] -> IO (Result a)
136get :: (Binary a, Typeable a) => Store -> [String] -> IO (Result a)
145−get store = withStore store "get" $ \key path -> do
137+get store identifier = do
146 -- First check the in-memory map
138 -- First check the in-memory map
147 ref <- cacheLookup store key
139 ref <- cacheLookup store key
148 case ref of
140 case ref of
@@ -154,14 +146,17 @@ get store = withStore store "get" $ \key path -> do
154 then return NotFound
146 then return NotFound
155 -- Found in the filesystem
147 -- Found in the filesystem
156 else do
148 else do
157− v <- decodeClose path
149+ v <- decodeClose
158 cacheInsert store key v
150 cacheInsert store key v
159 return $ Found v
151 return $ Found v
160 -- Found in the in-memory map (or wrong type), just return
152 -- Found in the in-memory map (or wrong type), just return
161 s -> return s
153 s -> return s
162 where
154 where
155+ key = hash identifier
156+ path = storeDirectory store </> key
157+
163 -- 'decodeFile' from Data.Binary which closes the file ASAP
158 -- 'decodeFile' from Data.Binary which closes the file ASAP
164− decodeClose path = do
159+ decodeClose = do
165 h <- openFile path ReadMode
160 h <- openFile path ReadMode
166 lbs <- BL.hGetContents h
161 lbs <- BL.hGetContents h
167 BL.length lbs `seq` hClose h
162 BL.length lbs `seq` hClose h
@@ -171,30 +166,32 @@ get store = withStore store "get" $ \key path -> do
171--------------------------------------------------------------------------------
166--------------------------------------------------------------------------------
172-- | Strict function
167-- | Strict function
173isMember :: Store -> [String] -> IO Bool
168isMember :: Store -> [String] -> IO Bool
174−isMember store = withStore store "isMember" $ \key path -> do
169+isMember store identifier = do
175 inCache <- cacheIsMember store key
170 inCache <- cacheIsMember store key
176 if inCache then return True else doesFileExist path
171 if inCache then return True else doesFileExist path
172+ where
173+ key = hash identifier
174+ path = storeDirectory store </> key
177
175
178
176
179--------------------------------------------------------------------------------
177--------------------------------------------------------------------------------
180-- | Delete an item
178-- | Delete an item
181delete :: Store -> [String] -> IO ()
179delete :: Store -> [String] -> IO ()
182−delete store = withStore store "delete" $ \key path -> do
180+delete store identifier = do
183 cacheDelete store key
181 cacheDelete store key
184− deleteFile path
182+ deleteFile $ storeDirectory store </> key
183+ where
184+ key = hash identifier
185
185
186
186
187--------------------------------------------------------------------------------
187--------------------------------------------------------------------------------
188-- | Delete a file unless it doesn't exist...
188-- | Delete a file unless it doesn't exist...
189deleteFile :: FilePath -> IO ()
189deleteFile :: FilePath -> IO ()
190−deleteFile = (`catchIOError` \_ -> return ()) . removeFile
190+deleteFile = handle (\(_ :: IOException) -> return ()) . removeFile
191
191
192
192
193--------------------------------------------------------------------------------
193--------------------------------------------------------------------------------
194-- | Mostly meant for internal usage
194-- | Mostly meant for internal usage
195hash :: [String] -> String
195hash :: [String] -> String
196+hash = concatMap (printf "%02x") . B.unpack .
196−hash = toHex . B.unpack . MD5.hash . T.encodeUtf8 . T.pack . intercalate "/"
197+ MD5.hash . T.encodeUtf8 . T.pack . intercalate "/"
197− where
198− toHex [] = ""
199− toHex (x : xs) | x < 16 = '0' : showHex x (toHex xs)
200− | otherwise = showHex x (toHex xs)
lib/Hakyll/Core/UnixFilter.hs → src/Hakyll/Core/UnixFilter.hsrenamed+1−2
@@ -92,8 +92,7 @@ unixFilterWith writer reader programName args input = do
92 ExitSuccess -> return output
92 ExitSuccess -> return output
93 ExitFailure e -> fail $
93 ExitFailure e -> fail $
94 "Hakyll.Core.UnixFilter.unixFilterWith: " ++
94 "Hakyll.Core.UnixFilter.unixFilterWith: " ++
95− unwords (programName : args) ++ " gave exit code " ++ show e ++
95+ unwords (programName : args) ++ " gave exit code " ++ show e
96− ". (Error: " ++ err ++ ")"
97
96
98
97
99--------------------------------------------------------------------------------
98--------------------------------------------------------------------------------
lib/Hakyll/Core/Util/File.hs → src/Hakyll/Core/Util/File.hsrenamed

The content is the same.

lib/Hakyll/Core/Util/Parser.hs → src/Hakyll/Core/Util/Parser.hsrenamed+3−9
@@ -2,12 +2,13 @@
2-- | Parser utilities
2-- | Parser utilities
3module Hakyll.Core.Util.Parser
3module Hakyll.Core.Util.Parser
4 ( metadataKey
4 ( metadataKey
5+ , reservedKeys
5 ) where
6 ) where
6
7
7
8
8--------------------------------------------------------------------------------
9--------------------------------------------------------------------------------
9import Control.Applicative ((<|>))
10import Control.Applicative ((<|>))
10−import Control.Monad (guard, mzero, void)
11+import Control.Monad (mzero)
11import qualified Text.Parsec as P
12import qualified Text.Parsec as P
12import Text.Parsec.String (Parser)
13import Text.Parsec.String (Parser)
13
14
@@ -15,14 +16,7 @@ import Text.Parsec.String (Parser)
15--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
16metadataKey :: Parser String
17metadataKey :: Parser String
17metadataKey = do
18metadataKey = do
18− -- Ensure trailing '-' binds to '$' if present.
19− let hyphon = P.try $ do
20− void $ P.char '-'
21− x <- P.lookAhead P.anyChar
22− guard $ x /= '$'
23− pure '-'
24−
25− i <- (:) <$> P.letter <*> P.many (P.alphaNum <|> P.oneOf "_." <|> hyphon)
19+ i <- (:) <$> P.letter <*> (P.many $ P.alphaNum <|> P.oneOf "_-.")
26 if i `elem` reservedKeys then mzero else return i
20 if i `elem` reservedKeys then mzero else return i
27
21
28
22
lib/Hakyll/Core/Util/String.hs → src/Hakyll/Core/Util/String.hsrenamed+1−1
@@ -27,7 +27,7 @@ trim = reverse . trim' . reverse . trim'
27--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
28-- | A simple (but inefficient) regex replace funcion
28-- | A simple (but inefficient) regex replace funcion
29replaceAll :: String -- ^ Pattern
29replaceAll :: String -- ^ Pattern
30− -> (String -> String) -- ^ Replacement (called on match)
30+ -> (String -> String) -- ^ Replacement (called on capture)
31 -> String -- ^ Source string
31 -> String -- ^ Source string
32 -> String -- ^ Result
32 -> String -- ^ Result
33replaceAll pattern f source = replaceAll' source
33replaceAll pattern f source = replaceAll' source
lib/Hakyll/Core/Writable.hs → src/Hakyll/Core/Writable.hsrenamed

The content is the same.

src/Init.hs → src/Hakyll/Init.hsrenamed+17−44
@@ -6,12 +6,12 @@ module Main
6
6
7--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
8import Control.Arrow (first)
8import Control.Arrow (first)
9−import Control.Monad (forM, forM_)
9+import Control.Monad (forM_)
10import Data.Char (isAlphaNum, isNumber)
10import Data.Char (isAlphaNum, isNumber)
11−import Data.List (foldl', intercalate, isPrefixOf)
11+import Data.List (foldl')
12+import Data.List (intercalate, isPrefixOf)
12import Data.Version (Version (..))
13import Data.Version (Version (..))
13−import System.Directory (canonicalizePath, copyFile,
14+import System.Directory (canonicalizePath, copyFile)
14− doesFileExist)
15import System.Environment (getArgs, getProgName)
15import System.Environment (getArgs, getProgName)
16import System.Exit (exitFailure)
16import System.Exit (exitFailure)
17import System.FilePath (splitDirectories, (</>))
17import System.FilePath (splitDirectories, (</>))
@@ -22,10 +22,6 @@ import Hakyll.Core.Util.File
22import Paths_hakyll
22import Paths_hakyll
23
23
24
24
25−--------------------------------------------------------------------------------
26−import Prelude
27−
28−
29--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
30main :: IO ()
26main :: IO ()
31main = do
27main = do
@@ -41,44 +37,21 @@ main = do
41 -- If dstDir begins with hyphens, the guard will prevent it from creating
37 -- If dstDir begins with hyphens, the guard will prevent it from creating
42 -- directory with that name so we can fall to the second alternative
38 -- directory with that name so we can fall to the second alternative
43 -- which prints a usage info for user.
39 -- which prints a usage info for user.
44− [dstDir] | not ("-" `isPrefixOf` dstDir) ->
40+ [dstDir] | not ("-" `isPrefixOf` dstDir) -> do
45− createFiles False srcDir files dstDir
41+ forM_ files $ \file -> do
46− ["-f", dstDir] ->
42+ let dst = dstDir </> file
47− createFiles True srcDir files dstDir
43+ src = srcDir </> file
48− _ -> do
44+ putStrLn $ "Creating " ++ dst
49− putStrLn $ "Usage: " ++ progName ++ "[-f] <directory>"
45+ makeDirectories dst
50− exitFailure
46+ copyFile src dst
51
47
52− where
53− createFiles force srcDir files dstDir = do
54 name <- makeName dstDir
48 name <- makeName dstDir
55 let cabalPath = dstDir </> name ++ ".cabal"
49 let cabalPath = dstDir </> name ++ ".cabal"
56−
57− diff <- if force then return []
58− else existingFiles dstDir (cabalPath : files)
59−
60− case diff of
61− [] -> do
62− forM_ files $ \file -> do
63− let dst = dstDir </> file
64− src = srcDir </> file
65− putStrLn $ "Creating " ++ dst
50+ putStrLn $ "Creating " ++ cabalPath
66− makeDirectories dst
67− copyFile src dst
68−
69− putStrLn $ "Creating " ++ cabalPath
70− createCabal cabalPath name
51+ createCabal cabalPath name
71− fs -> do
52+ _ -> do
72− putStrLn $ "The following files will be overwritten:"
53+ putStrLn $ "Usage: " ++ progName ++ " <directory>"
73− mapM_ putStrLn fs
74− putStrLn $ "Use -f to overwrite them"
75− exitFailure
54+ exitFailure
76−
77−existingFiles :: FilePath -> [FilePath] -> IO [FilePath]
78−existingFiles dstDir files = fmap concat $ forM files $ \file -> do
79− let dst = dstDir </> file
80− exists <- doesFileExist dst
81− return $ if exists then [dst] else []
82
55
83-- | Figure out a good cabal package name from the given (existing) directory
56-- | Figure out a good cabal package name from the given (existing) directory
84-- name
57-- name
@@ -104,7 +77,7 @@ makeName dstDir = do
104 safeLast = foldl' (\_ x -> Just x) Nothing
77 safeLast = foldl' (\_ x -> Just x) Nothing
105
78
106createCabal :: FilePath -> String -> IO ()
79createCabal :: FilePath -> String -> IO ()
107−createCabal path name =
80+createCabal path name = do
108 writeFile path $ unlines [
81 writeFile path $ unlines [
109 "name: " ++ name
82 "name: " ++ name
110 , "version: 0.1.0.0"
83 , "version: 0.1.0.0"
src/Hakyll/Main.hsnew file+128
@@ -0,0 +1,128 @@
1+--------------------------------------------------------------------------------
2+-- | Module providing the main hakyll function and command-line argument parsing
3+{-# LANGUAGE CPP #-}
4+{-# LANGUAGE DeriveDataTypeable #-}
5+module Hakyll.Main
6+ ( hakyll
7+ , hakyllWith
8+ , hakyllWithExitCode
9+ ) where
10+
11+
12+--------------------------------------------------------------------------------
13+import System.Console.CmdArgs
14+import qualified System.Console.CmdArgs.Explicit as CA
15+import System.Environment (getProgName)
16+import System.IO.Unsafe (unsafePerformIO)
17+import System.Exit (ExitCode(ExitSuccess), exitWith)
18+
19+--------------------------------------------------------------------------------
20+import qualified Hakyll.Check as Check
21+import qualified Hakyll.Commands as Commands
22+import qualified Hakyll.Core.Configuration as Config
23+import qualified Hakyll.Core.Logger as Logger
24+import Hakyll.Core.Rules
25+
26+
27+--------------------------------------------------------------------------------
28+-- | This usualy is the function with which the user runs the hakyll compiler
29+hakyll :: Rules a -> IO ()
30+hakyll = hakyllWith Config.defaultConfiguration
31+
32+--------------------------------------------------------------------------------
33+-- | A variant of 'hakyll' which allows the user to specify a custom
34+-- configuration
35+hakyllWith :: Config.Configuration -> Rules a -> IO ()
36+hakyllWith conf rules = hakyllWithExitCode conf rules >>= exitWith
37+
38+hakyllWithExitCode :: Config.Configuration -> Rules a -> IO ExitCode
39+hakyllWithExitCode conf rules = do
40+ args' <- cmdArgs (hakyllArgs conf)
41+
42+ let verbosity' = if verbose args' then Logger.Debug else Logger.Message
43+ check' =
44+ if internal_links args' then Check.InternalLinks else Check.All
45+
46+ logger <- Logger.new verbosity'
47+ case args' of
48+ Build _ -> Commands.build conf logger rules
49+ Check _ _ -> Commands.check conf logger check' >> ok
50+ Clean _ -> Commands.clean conf logger >> ok
51+ Deploy _ -> Commands.deploy conf
52+ Help _ -> showHelp >> ok
53+ Preview _ p -> Commands.preview conf logger rules p >> ok
54+ Rebuild _ -> Commands.rebuild conf logger rules
55+ Server _ _ _ -> Commands.server conf logger (host args') (port args') >> ok
56+ Watch _ _ p s -> Commands.watch conf logger (host args') p (not s) rules >> ok
57+ where
58+ ok = return ExitSuccess
59+
60+
61+--------------------------------------------------------------------------------
62+-- | Show usage information.
63+showHelp :: IO ()
64+showHelp = print $ CA.helpText [] CA.HelpFormatOne $ cmdArgsMode (hakyllArgs Config.defaultConfiguration)
65+
66+
67+--------------------------------------------------------------------------------
68+data HakyllArgs
69+ = Build {verbose :: Bool}
70+ | Check {verbose :: Bool, internal_links :: Bool}
71+ | Clean {verbose :: Bool}
72+ | Deploy {verbose :: Bool}
73+ | Help {verbose :: Bool}
74+ | Preview {verbose :: Bool, port :: Int}
75+ | Rebuild {verbose :: Bool}
76+ | Server {verbose :: Bool, host :: String, port :: Int}
77+ | Watch {verbose :: Bool, host :: String, port :: Int, no_server :: Bool }
78+ deriving (Data, Typeable, Show)
79+
80+
81+--------------------------------------------------------------------------------
82+hakyllArgs :: Config.Configuration -> HakyllArgs
83+hakyllArgs conf = modes
84+ [ (Build $ verboseFlag def) &= help "Generate the site"
85+ , (Check (verboseFlag def) (False &= help "Check internal links only")) &=
86+ help "Validate the site output"
87+ , (Clean $ verboseFlag def) &= help "Clean up and remove cache"
88+ , (Deploy $ verboseFlag def) &= help "Upload/deploy your site"
89+ , (Help $ verboseFlag def) &= help "Show this message" &= auto
90+ , (Preview (verboseFlag def) (portFlag defaultPort)) &=
91+ help "[Deprecated] Please use the watch command"
92+ , (Rebuild $ verboseFlag def) &= help "Clean and build again"
93+ , (Server (verboseFlag def) (hostFlag defaultHost) (portFlag defaultPort)) &=
94+ help "Start a preview server"
95+ , (Watch (verboseFlag def) (hostFlag defaultHost) (portFlag defaultPort) (noServerFlag False) &=
96+ help "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server.")
97+ ] &= help "Hakyll static site compiler" &= program progName
98+ where
99+ defaultHost = Config.previewHost conf
100+ defaultPort = Config.previewPort conf
101+
102+--------------------------------------------------------------------------------
103+verboseFlag :: Data a => a -> a
104+verboseFlag x = x &= help "Run in verbose mode"
105+{-# INLINE verboseFlag #-}
106+
107+
108+--------------------------------------------------------------------------------
109+noServerFlag :: Data a => a -> a
110+noServerFlag x = x &= help "Disable the built-in web server"
111+{-# INLINE noServerFlag #-}
112+
113+--------------------------------------------------------------------------------
114+hostFlag :: Data a => a -> a
115+hostFlag x = x &= help "Host to bind on"
116+{-# INLINE hostFlag #-}
117+
118+--------------------------------------------------------------------------------
119+portFlag :: Data a => a -> a
120+portFlag x = x &= help "Port to listen on"
121+{-# INLINE portFlag #-}
122+
123+
124+--------------------------------------------------------------------------------
125+-- | This is necessary because not everyone calls their program the same...
126+progName :: String
127+progName = unsafePerformIO getProgName
128+{-# NOINLINE progName #-}
lib/Hakyll/Preview/Poll.hs → src/Hakyll/Preview/Poll.hsrenamed+18−8
@@ -14,7 +14,8 @@ import Control.Exception (AsyncException, fromException,
14import Control.Monad (forever, void, when)
14import Control.Monad (forever, void, when)
15import System.Directory (canonicalizePath)
15import System.Directory (canonicalizePath)
16import System.FilePath (pathSeparators)
16import System.FilePath (pathSeparators)
17−import qualified System.FSNotify as FSNotify
17+import System.FSNotify (Event (..), startManager,
18+ watchTree)
18
19
19#ifdef mingw32_HOST_OS
20#ifdef mingw32_HOST_OS
20import Control.Concurrent (threadDelay)
21import Control.Concurrent (threadDelay)
@@ -43,12 +44,12 @@ watchUpdates conf update = do
43 shouldBuild <- newEmptyMVar
44 shouldBuild <- newEmptyMVar
44 pattern <- update
45 pattern <- update
45 fullProviderDir <- canonicalizePath $ providerDirectory conf
46 fullProviderDir <- canonicalizePath $ providerDirectory conf
46− manager <- FSNotify.startManager
47+ manager <- startManager
47
48
48 let allowed event = do
49 let allowed event = do
49 -- Absolute path of the changed file. This must be inside provider
50 -- Absolute path of the changed file. This must be inside provider
50 -- dir, since that's the only dir we're watching.
51 -- dir, since that's the only dir we're watching.
51− let path = FSNotify.eventPath event
52+ let path = eventPath event
52 relative = dropWhile (`elem` pathSeparators) $
53 relative = dropWhile (`elem` pathSeparators) $
53 drop (length fullProviderDir) path
54 drop (length fullProviderDir) path
54 identifier = fromFilePath relative
55 identifier = fromFilePath relative
@@ -68,7 +69,7 @@ watchUpdates conf update = do
68
69
69 -- Send an event whenever something occurs so that the thread described
70 -- Send an event whenever something occurs so that the thread described
70 -- above will do a build.
71 -- above will do a build.
71− void $ FSNotify.watchTree manager providerDir (not . isRemove) $ \event -> do
72+ void $ watchTree manager providerDir (not . isRemove) $ \event -> do
72 allowed' <- allowed event
73 allowed' <- allowed event
73 when allowed' $ void $ tryPutMVar shouldBuild event
74 when allowed' $ void $ tryPutMVar shouldBuild event
74 where
75 where
@@ -76,7 +77,7 @@ watchUpdates conf update = do
76 update' _ _ = void update
77 update' _ _ = void update
77#else
78#else
78 update' event provider = do
79 update' event provider = do
79− let path = provider </> FSNotify.eventPath event
80+ let path = provider </> eventPath event
80 -- on windows, a 'Modified' event is also sent on file deletion
81 -- on windows, a 'Modified' event is also sent on file deletion
81 fileExists <- doesFileExist path
82 fileExists <- doesFileExist path
82
83
@@ -104,6 +105,15 @@ watchUpdates conf update = do
104
105
105
106
106--------------------------------------------------------------------------------
107--------------------------------------------------------------------------------
108+eventPath :: Event -> FilePath
109+eventPath evt = evtPath evt
110+ where
111+ evtPath (Added p _) = p
112+ evtPath (Modified p _) = p
113+ evtPath (Removed p _) = p
114+
115+
116+--------------------------------------------------------------------------------
107−isRemove :: FSNotify.Event -> Bool
117+isRemove :: Event -> Bool
108−isRemove (FSNotify.Removed {}) = True
118+isRemove (Removed _ _) = True
109−isRemove _ = False
119+isRemove _ = False
src/Hakyll/Preview/Server.hsnew file+54
@@ -0,0 +1,54 @@
1+--------------------------------------------------------------------------------
2+-- | Implements a basic static file server for previewing options
3+{-# LANGUAGE OverloadedStrings #-}
4+module Hakyll.Preview.Server
5+ ( staticServer
6+ ) where
7+
8+
9+--------------------------------------------------------------------------------
10+import Control.Monad.Trans (liftIO)
11+import qualified Data.ByteString.Char8 as B
12+import qualified Snap.Core as Snap
13+import qualified Snap.Http.Server as Snap
14+import qualified Snap.Util.FileServe as Snap
15+
16+
17+--------------------------------------------------------------------------------
18+import Hakyll.Core.Logger (Logger)
19+import qualified Hakyll.Core.Logger as Logger
20+
21+
22+--------------------------------------------------------------------------------
23+-- | Serve a given directory
24+static :: FilePath -- ^ Directory to serve
25+ -> (FilePath -> IO ()) -- ^ Pre-serve hook
26+ -> Snap.Snap ()
27+static directory preServe =
28+ Snap.serveDirectoryWith directoryConfig directory
29+ where
30+ directoryConfig :: Snap.DirectoryConfig Snap.Snap
31+ directoryConfig = Snap.fancyDirectoryConfig
32+ { Snap.preServeHook = liftIO . preServe
33+ }
34+
35+
36+--------------------------------------------------------------------------------
37+-- | Main method, runs a static server in the given directory
38+staticServer :: Logger -- ^ Logger
39+ -> FilePath -- ^ Directory to serve
40+ -> (FilePath -> IO ()) -- ^ Pre-serve hook
41+ -> String -- ^ Host to bind on
42+ -> Int -- ^ Port to listen on
43+ -> IO () -- ^ Blocks forever
44+staticServer logger directory preServe host port = do
45+ Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port
46+ Snap.httpServe config $ static directory preServe
47+ where
48+ -- Snap server config
49+ config = Snap.setBind (B.pack host)
50+ $ Snap.setPort port
51+ $ Snap.setAccessLog Snap.ConfigNoLog
52+ $ Snap.setErrorLog Snap.ConfigNoLog
53+ $ Snap.setVerbose False
54+ $ Snap.emptyConfig
src/Hakyll/Web/CompressCss.hsnew file+59
@@ -0,0 +1,59 @@
1+--------------------------------------------------------------------------------
2+-- | Module used for CSS compression. The compression is currently in a simple
3+-- state, but would typically reduce the number of bytes by about 25%.
4+module Hakyll.Web.CompressCss
5+ ( compressCssCompiler
6+ , compressCss
7+ ) where
8+
9+
10+--------------------------------------------------------------------------------
11+import Data.Char (isSpace)
12+import Data.List (isPrefixOf)
13+
14+
15+--------------------------------------------------------------------------------
16+import Hakyll.Core.Compiler
17+import Hakyll.Core.Item
18+import Hakyll.Core.Util.String
19+
20+
21+--------------------------------------------------------------------------------
22+-- | Compiler form of 'compressCss'
23+compressCssCompiler :: Compiler (Item String)
24+compressCssCompiler = fmap compressCss <$> getResourceString
25+
26+
27+--------------------------------------------------------------------------------
28+-- | Compress CSS to speed up your site.
29+compressCss :: String -> String
30+compressCss = compressSeparators . stripComments . compressWhitespace
31+
32+
33+--------------------------------------------------------------------------------
34+-- | Compresses certain forms of separators.
35+compressSeparators :: String -> String
36+compressSeparators =
37+ replaceAll "; *}" (const "}") .
38+ replaceAll " *([{};:]) *" (take 1 . dropWhile isSpace) .
39+ replaceAll ";+" (const ";")
40+
41+
42+--------------------------------------------------------------------------------
43+-- | Compresses all whitespace.
44+compressWhitespace :: String -> String
45+compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
46+
47+
48+--------------------------------------------------------------------------------
49+-- | Function that strips CSS comments away.
50+stripComments :: String -> String
51+stripComments [] = []
52+stripComments str
53+ | isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
54+ | otherwise = head str : stripComments (drop 1 str)
55+ where
56+ eatComments str'
57+ | null str' = []
58+ | isPrefixOf "*/" str' = drop 2 str'
59+ | otherwise = eatComments $ drop 1 str'
lib/Hakyll/Web/Feed.hs → src/Hakyll/Web/Feed.hsrenamed+23−65
@@ -1,6 +1,3 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
3−
4--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
5-- | A Module that allows easy rendering of RSS feeds.
2-- | A Module that allows easy rendering of RSS feeds.
6--
3--
@@ -23,40 +20,24 @@ module Hakyll.Web.Feed
23 ( FeedConfiguration (..)
20 ( FeedConfiguration (..)
24 , renderRss
21 , renderRss
25 , renderAtom
22 , renderAtom
26− , renderRssWithTemplates
27− , renderAtomWithTemplates
28 ) where
23 ) where
29
24
30
25
26+--------------------------------------------------------------------------------
27+import Control.Monad ((<=<))
28+
29+
31--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
32import Hakyll.Core.Compiler
31import Hakyll.Core.Compiler
32+import Hakyll.Core.Compiler.Internal
33import Hakyll.Core.Item
33import Hakyll.Core.Item
34−import Hakyll.Core.Util.String (replaceAll)
35import Hakyll.Web.Template
34import Hakyll.Web.Template
36import Hakyll.Web.Template.Context
35import Hakyll.Web.Template.Context
37import Hakyll.Web.Template.List
36import Hakyll.Web.Template.List
38
37
39
38
40--------------------------------------------------------------------------------
39--------------------------------------------------------------------------------
41−import Data.FileEmbed (makeRelativeToProject)
40+import Paths_hakyll
42−
43−
44−--------------------------------------------------------------------------------
45−rssTemplate :: Template
46−rssTemplate =
47− $(makeRelativeToProject "data/templates/rss.xml" >>= embedTemplate)
48−
49−rssItemTemplate :: Template
50−rssItemTemplate =
51− $(makeRelativeToProject "data/templates/rss-item.xml" >>= embedTemplate)
52−
53−atomTemplate :: Template
54−atomTemplate =
55− $(makeRelativeToProject "data/templates/atom.xml" >>= embedTemplate)
56−
57−atomItemTemplate :: Template
58−atomItemTemplate =
59− $(makeRelativeToProject "data/templates/atom-item.xml" >>= embedTemplate)
60
41
61
42
62--------------------------------------------------------------------------------
43--------------------------------------------------------------------------------
@@ -77,21 +58,21 @@ data FeedConfiguration = FeedConfiguration
77
58
78--------------------------------------------------------------------------------
59--------------------------------------------------------------------------------
79-- | Abstract function to render any feed.
60-- | Abstract function to render any feed.
80−renderFeed :: Template -- ^ Default feed template
61+renderFeed :: FilePath -- ^ Feed template
81− -> Template -- ^ Default item template
62+ -> FilePath -- ^ Item template
82 -> FeedConfiguration -- ^ Feed configuration
63 -> FeedConfiguration -- ^ Feed configuration
83 -> Context String -- ^ Context for the items
64 -> Context String -- ^ Context for the items
84 -> [Item String] -- ^ Input items
65 -> [Item String] -- ^ Input items
85 -> Compiler (Item String) -- ^ Resulting item
66 -> Compiler (Item String) -- ^ Resulting item
86−renderFeed feedTpl itemTpl config itemContext items = do
67+renderFeed feedPath itemPath config itemContext items = do
87− protectedItems <- mapM (applyFilter protectCDATA) items
68+ feedTpl <- compilerUnsafeIO $ loadTemplate feedPath
69+ itemTpl <- compilerUnsafeIO $ loadTemplate itemPath
70+
88− body <- makeItem =<< applyTemplateList itemTpl itemContext' protectedItems
71+ body <- makeItem =<< applyTemplateList itemTpl itemContext' items
89 applyTemplate feedTpl feedContext body
72 applyTemplate feedTpl feedContext body
90 where
73 where
91− applyFilter :: (Monad m,Functor f) => (String -> String) -> f String -> m (f String)
74+ -- Auxiliary: load a template from a datafile
92− applyFilter tr str = return $ fmap tr str
75+ loadTemplate = fmap readTemplate . readFile <=< getDataFileName
93− protectCDATA :: String -> String
94− protectCDATA = replaceAll "]]>" (const "]]&gt;")
95
76
96 itemContext' = mconcat
77 itemContext' = mconcat
97 [ itemContext
78 [ itemContext
@@ -117,35 +98,8 @@ renderFeed feedTpl itemTpl config itemContext items = do
117 updatedField = field "updated" $ \_ -> case items of
98 updatedField = field "updated" $ \_ -> case items of
118 [] -> return "Unknown"
99 [] -> return "Unknown"
119 (x : _) -> unContext itemContext' "updated" [] x >>= \cf -> case cf of
100 (x : _) -> unContext itemContext' "updated" [] x >>= \cf -> case cf of
101+ ListField _ _ -> fail "Hakyll.Web.Feed.renderFeed: Internal error"
120 StringField s -> return s
102 StringField s -> return s
121− _ -> fail "Hakyll.Web.Feed.renderFeed: Internal error"
122−
123−--------------------------------------------------------------------------------
124−-- | Render an RSS feed using given templates with a number of items.
125−renderRssWithTemplates ::
126− Template -- ^ Feed template
127− -> Template -- ^ Item template
128− -> FeedConfiguration -- ^ Feed configuration
129− -> Context String -- ^ Item context
130− -> [Item String] -- ^ Feed items
131− -> Compiler (Item String) -- ^ Resulting feed
132−renderRssWithTemplates feedTemplate itemTemplate config context = renderFeed
133− feedTemplate itemTemplate config
134− (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context)
135−
136−
137−--------------------------------------------------------------------------------
138−-- | Render an Atom feed using given templates with a number of items.
139−renderAtomWithTemplates ::
140− Template -- ^ Feed template
141− -> Template -- ^ Item template
142− -> FeedConfiguration -- ^ Feed configuration
143− -> Context String -- ^ Item context
144− -> [Item String] -- ^ Feed items
145− -> Compiler (Item String) -- ^ Resulting feed
146−renderAtomWithTemplates feedTemplate itemTemplate config context = renderFeed
147− feedTemplate itemTemplate config
148− (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context)
149
103
150
104
151--------------------------------------------------------------------------------
105--------------------------------------------------------------------------------
@@ -154,7 +108,9 @@ renderRss :: FeedConfiguration -- ^ Feed configuration
154 -> Context String -- ^ Item context
108 -> Context String -- ^ Item context
155 -> [Item String] -- ^ Feed items
109 -> [Item String] -- ^ Feed items
156 -> Compiler (Item String) -- ^ Resulting feed
110 -> Compiler (Item String) -- ^ Resulting feed
157−renderRss = renderRssWithTemplates rssTemplate rssItemTemplate
111+renderRss config context = renderFeed
112+ "templates/rss.xml" "templates/rss-item.xml" config
113+ (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context)
158
114
159
115
160--------------------------------------------------------------------------------
116--------------------------------------------------------------------------------
@@ -163,11 +119,13 @@ renderAtom :: FeedConfiguration -- ^ Feed configuration
163 -> Context String -- ^ Item context
119 -> Context String -- ^ Item context
164 -> [Item String] -- ^ Feed items
120 -> [Item String] -- ^ Feed items
165 -> Compiler (Item String) -- ^ Resulting feed
121 -> Compiler (Item String) -- ^ Resulting feed
166−renderAtom = renderAtomWithTemplates atomTemplate atomItemTemplate
122+renderAtom config context = renderFeed
123+ "templates/atom.xml" "templates/atom-item.xml" config
124+ (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context)
167
125
168
126
169--------------------------------------------------------------------------------
127--------------------------------------------------------------------------------
170-- | Copies @$updated$@ from @$published$@ if it is not already set.
128-- | Copies @$updated$@ from @$published$@ if it is not already set.
171makeItemContext :: String -> Context a -> Context a
129makeItemContext :: String -> Context a -> Context a
172makeItemContext fmt context = mconcat
130makeItemContext fmt context = mconcat
173− [context, dateField "published" fmt, dateField "updated" fmt]
131+ [dateField "published" fmt, context, dateField "updated" fmt]
lib/Hakyll/Web/Html.hs → src/Hakyll/Web/Html.hsrenamed+2−6
@@ -3,7 +3,6 @@
3module Hakyll.Web.Html
3module Hakyll.Web.Html
4 ( -- * Generic
4 ( -- * Generic
5 withTags
5 withTags
6− , withTagList
7
6
8 -- * Headers
7 -- * Headers
9 , demoteHeaders
8 , demoteHeaders
@@ -37,11 +36,8 @@ import Network.URI (isUnreserved, escapeURIString)
37--------------------------------------------------------------------------------
36--------------------------------------------------------------------------------
38-- | Map over all tags in the document
37-- | Map over all tags in the document
39withTags :: (TS.Tag String -> TS.Tag String) -> String -> String
38withTags :: (TS.Tag String -> TS.Tag String) -> String -> String
40−withTags = withTagList . map
39+withTags f = renderTags' . map f . parseTags'
41
40
42−-- | Map over all tags (as list) in the document
43−withTagList :: ([TS.Tag String] -> [TS.Tag String]) -> String -> String
44−withTagList f = renderTags' . f . parseTags'
45
41
46--------------------------------------------------------------------------------
42--------------------------------------------------------------------------------
47-- | Map every @h1@ to an @h2@, @h2@ to @h3@, etc.
43-- | Map every @h1@ to an @h2@, @h2@ to @h3@, etc.
@@ -59,7 +55,7 @@ demoteHeaders = withTags $ \tag -> case tag of
59
55
60--------------------------------------------------------------------------------
56--------------------------------------------------------------------------------
61isUrlAttribute :: String -> Bool
57isUrlAttribute :: String -> Bool
62−isUrlAttribute = (`elem` ["src", "href", "data", "poster", "srcset"])
58+isUrlAttribute = (`elem` ["src", "href", "data", "poster"])
63
59
64
60
65--------------------------------------------------------------------------------
61--------------------------------------------------------------------------------
lib/Hakyll/Web/Html/RelativizeUrls.hs → src/Hakyll/Web/Html/RelativizeUrls.hsrenamed

The content is the same.

lib/Hakyll/Web/Paginate.hs → src/Hakyll/Web/Paginate.hsrenamed+2−29
@@ -11,8 +11,7 @@ module Hakyll.Web.Paginate
11
11
12
12
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
14−import Control.Applicative (empty)
14+import Control.Monad (forM_)
15−import Control.Monad (forM_, forM)
16import qualified Data.Map as M
15import qualified Data.Map as M
17import qualified Data.Set as S
16import qualified Data.Set as S
18
17
@@ -38,7 +37,7 @@ data Paginate = Paginate
38 { paginateMap :: M.Map PageNumber [Identifier]
37 { paginateMap :: M.Map PageNumber [Identifier]
39 , paginateMakeId :: PageNumber -> Identifier
38 , paginateMakeId :: PageNumber -> Identifier
40 , paginateDependency :: Dependency
39 , paginateDependency :: Dependency
41− }
40+ } deriving (Show)
42
41
43
42
44--------------------------------------------------------------------------------
43--------------------------------------------------------------------------------
@@ -94,18 +93,6 @@ paginatePage pag pageNumber
94-- | A default paginate context which provides the following keys:
93-- | A default paginate context which provides the following keys:
95--
94--
96--
95--
97−-- * @firstPageNum@
98−-- * @firstPageUrl@
99−-- * @previousPageNum@
100−-- * @previousPageUrl@
101−-- * @nextPageNum@
102−-- * @nextPageUrl@
103−-- * @lastPageNum@
104−-- * @lastPageUrl@
105−-- * @currentPageNum@
106−-- * @currentPageUrl@
107−-- * @numPages@
108−-- * @allPages@
109paginateContext :: Paginate -> PageNumber -> Context a
96paginateContext :: Paginate -> PageNumber -> Context a
110paginateContext pag currentPage = mconcat
97paginateContext pag currentPage = mconcat
111 [ field "firstPageNum" $ \_ -> otherPage 1 >>= num
98 [ field "firstPageNum" $ \_ -> otherPage 1 >>= num
@@ -119,20 +106,6 @@ paginateContext pag currentPage = mconcat
119 , field "currentPageNum" $ \i -> thisPage i >>= num
106 , field "currentPageNum" $ \i -> thisPage i >>= num
120 , field "currentPageUrl" $ \i -> thisPage i >>= url
107 , field "currentPageUrl" $ \i -> thisPage i >>= url
121 , constField "numPages" $ show $ paginateNumPages pag
108 , constField "numPages" $ show $ paginateNumPages pag
122− , Context $ \k _ i -> case k of
123− "allPages" -> do
124− let ctx =
125− field "isCurrent" (\n -> if fst (itemBody n) == currentPage then return "true" else empty) `mappend`
126− field "num" (num . itemBody) `mappend`
127− field "url" (url . itemBody)
128−
129− list <- forM [1 .. lastPage] $
130− \n -> if n == currentPage then thisPage i else otherPage n
131− items <- mapM makeItem list
132− return $ ListField ctx items
133− _ -> do
134− empty
135−
136 ]
109 ]
137 where
110 where
138 lastPage = paginateNumPages pag
111 lastPage = paginateNumPages pag
lib/Hakyll/Web/Pandoc.hs → src/Hakyll/Web/Pandoc.hsrenamed+12−13
@@ -22,9 +22,9 @@ module Hakyll.Web.Pandoc
22
22
23
23
24--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
25−import qualified Data.Text as T
25+import qualified Data.Set as S
26import Text.Pandoc
26import Text.Pandoc
27−import Text.Pandoc.Highlighting (pygments)
27+import Text.Pandoc.Error (PandocError (..))
28
28
29
29
30--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
@@ -48,10 +48,12 @@ readPandocWith
48 -> Item String -- ^ String to read
48 -> Item String -- ^ String to read
49 -> Compiler (Item Pandoc) -- ^ Resulting document
49 -> Compiler (Item Pandoc) -- ^ Resulting document
50readPandocWith ropt item =
50readPandocWith ropt item =
51− case runPure $ traverse (reader ropt (itemFileType item)) (fmap T.pack item) of
51+ case traverse (reader ropt (itemFileType item)) item of
52− Left err -> fail $
52+ Left (ParseFailure err) -> fail $
53+ "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ err
54+ Left (ParsecError _ err) -> fail $
53 "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ show err
55 "Hakyll.Web.Pandoc.readPandocWith: parse failed: " ++ show err
54− Right item' -> return item'
56+ Right item' -> return item'
55 where
57 where
56 reader ro t = case t of
58 reader ro t = case t of
57 DocBook -> readDocBook ro
59 DocBook -> readDocBook ro
@@ -67,7 +69,7 @@ readPandocWith ropt item =
67 "Hakyll.Web.readPandocWith: I don't know how to read a file of " ++
69 "Hakyll.Web.readPandocWith: I don't know how to read a file of " ++
68 "the type " ++ show t ++ " for: " ++ show (itemIdentifier item)
70 "the type " ++ show t ++ " for: " ++ show (itemIdentifier item)
69
71
70− addExt ro e = ro {readerExtensions = enableExtension e $ readerExtensions ro}
72+ addExt ro e = ro {readerExtensions = S.insert e $ readerExtensions ro}
71
73
72
74
73--------------------------------------------------------------------------------
75--------------------------------------------------------------------------------
@@ -82,10 +84,7 @@ writePandoc = writePandocWith defaultHakyllWriterOptions
82writePandocWith :: WriterOptions -- ^ Writer options for pandoc
84writePandocWith :: WriterOptions -- ^ Writer options for pandoc
83 -> Item Pandoc -- ^ Document to write
85 -> Item Pandoc -- ^ Document to write
84 -> Item String -- ^ Resulting HTML
86 -> Item String -- ^ Resulting HTML
85−writePandocWith wopt (Item itemi doc) =
87+writePandocWith wopt = fmap $ writeHtmlString wopt
86− case runPure $ writeHtml5String wopt doc of
87− Left err -> error $ "Hakyll.Web.Pandoc.writePandocWith: " ++ show err
88− Right item' -> Item itemi $ T.unpack item'
89
88
90
89
91--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
@@ -148,7 +147,7 @@ defaultHakyllReaderOptions :: ReaderOptions
148defaultHakyllReaderOptions = def
147defaultHakyllReaderOptions = def
149 { -- The following option causes pandoc to read smart typography, a nice
148 { -- The following option causes pandoc to read smart typography, a nice
150 -- and free bonus.
149 -- and free bonus.
151− readerExtensions = enableExtension Ext_smart pandocExtensions
150+ readerSmart = True
152 }
151 }
153
152
154
153
@@ -158,8 +157,8 @@ defaultHakyllWriterOptions :: WriterOptions
158defaultHakyllWriterOptions = def
157defaultHakyllWriterOptions = def
159 { -- This option causes literate haskell to be written using '>' marks in
158 { -- This option causes literate haskell to be written using '>' marks in
160 -- html, which I think is a good default.
159 -- html, which I think is a good default.
161− writerExtensions = enableExtension Ext_smart pandocExtensions
160+ writerExtensions = S.insert Ext_literate_haskell (writerExtensions def)
162 , -- We want to have hightlighting by default, to be compatible with earlier
161 , -- We want to have hightlighting by default, to be compatible with earlier
163 -- Hakyll releases
162 -- Hakyll releases
164− writerHighlightStyle = Just pygments
163+ writerHighlight = True
165 }
164 }
lib/Hakyll/Web/Pandoc/Biblio.hs → src/Hakyll/Web/Pandoc/Biblio.hsrenamed+6−17
@@ -25,19 +25,17 @@ module Hakyll.Web.Pandoc.Biblio
25--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
26import Control.Monad (liftM, replicateM)
26import Control.Monad (liftM, replicateM)
27import Data.Binary (Binary (..))
27import Data.Binary (Binary (..))
28+import Data.Default (def)
28import Data.Typeable (Typeable)
29import Data.Typeable (Typeable)
29import Hakyll.Core.Compiler
30import Hakyll.Core.Compiler
30−import Hakyll.Core.Compiler.Internal
31import Hakyll.Core.Identifier
31import Hakyll.Core.Identifier
32import Hakyll.Core.Item
32import Hakyll.Core.Item
33−import Hakyll.Core.Provider
34import Hakyll.Core.Writable
33import Hakyll.Core.Writable
35import Hakyll.Web.Pandoc
34import Hakyll.Web.Pandoc
36import Hakyll.Web.Pandoc.Binary ()
35import Hakyll.Web.Pandoc.Binary ()
37import qualified Text.CSL as CSL
36import qualified Text.CSL as CSL
38import Text.CSL.Pandoc (processCites)
37import Text.CSL.Pandoc (processCites)
39−import Text.Pandoc (Pandoc, ReaderOptions (..),
38+import Text.Pandoc (Pandoc, ReaderOptions (..))
40− enableExtension, Extension (..))
41
39
42
40
43--------------------------------------------------------------------------------
41--------------------------------------------------------------------------------
@@ -85,11 +83,8 @@ instance Writable Biblio where
85--------------------------------------------------------------------------------
83--------------------------------------------------------------------------------
86biblioCompiler :: Compiler (Item Biblio)
84biblioCompiler :: Compiler (Item Biblio)
87biblioCompiler = do
85biblioCompiler = do
88− filePath <- getResourceFilePath
86+ filePath <- toFilePath <$> getUnderlying
89− makeItem =<< unsafeCompiler (Biblio <$> CSL.readBiblioFile idpred filePath)
87+ makeItem =<< unsafeCompiler (Biblio <$> CSL.readBiblioFile filePath)
90− where
91− -- This is a filter on citations. We include all citations.
92− idpred = const True
93
88
94
89
95--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
@@ -100,9 +95,7 @@ readPandocBiblio :: ReaderOptions
100 -> Compiler (Item Pandoc)
95 -> Compiler (Item Pandoc)
101readPandocBiblio ropt csl biblio item = do
96readPandocBiblio ropt csl biblio item = do
102 -- Parse CSL file, if given
97 -- Parse CSL file, if given
103− provider <- compilerProvider <$> compilerAsk
104− style <- unsafeCompiler $
105− CSL.readCSLFile Nothing . (resourceFilePath provider) . itemIdentifier $ csl
98+ style <- unsafeCompiler $ CSL.readCSLFile Nothing . toFilePath . itemIdentifier $ csl
106
99
107 -- We need to know the citation keys, add then *before* actually parsing the
100 -- We need to know the citation keys, add then *before* actually parsing the
108 -- actual page. If we don't do this, pandoc won't even consider them
101 -- actual page. If we don't do this, pandoc won't even consider them
@@ -119,8 +112,4 @@ pandocBiblioCompiler cslFileName bibFileName = do
119 csl <- load $ fromFilePath cslFileName
112 csl <- load $ fromFilePath cslFileName
120 bib <- load $ fromFilePath bibFileName
113 bib <- load $ fromFilePath bibFileName
121 liftM writePandoc
114 liftM writePandoc
122− (getResourceBody >>= readPandocBiblio ropt csl bib)
115+ (getResourceBody >>= readPandocBiblio def csl bib)
123− where ropt = defaultHakyllReaderOptions
124− { -- The following option enables citation rendering
125− readerExtensions = enableExtension Ext_citations $ readerExtensions defaultHakyllReaderOptions
126− }
lib/Hakyll/Web/Pandoc/Binary.hs → src/Hakyll/Web/Pandoc/Binary.hsrenamed+17−19
@@ -1,33 +1,31 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2−{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE DeriveGeneric #-}
3module Hakyll.Web.Pandoc.Binary where
3module Hakyll.Web.Pandoc.Binary where
4
4
5−import Data.Binary (Binary (..))
5+import Data.Binary (Binary (..))
6
6
7−import qualified Text.CSL as CSL
7+import qualified Text.CSL as CSL
8−import qualified Text.CSL.Reference as REF
8+import qualified Text.CSL.Reference as REF
9−import qualified Text.CSL.Style as STY
9+import qualified Text.CSL.Style as STY
10−import Text.Pandoc
10+import Text.Pandoc
11
11
12--------------------------------------------------------------------------------
12--------------------------------------------------------------------------------
13-- orphans
13-- orphans
14
14
15−instance Binary Alignment
16−instance Binary Block
17−instance Binary CSL.Reference
18−instance Binary Citation
19−instance Binary CitationMode
20−instance Binary Format
21−instance Binary Inline
22−instance Binary ListNumberDelim
23−instance Binary ListNumberStyle
24−instance Binary MathType
25−instance Binary QuoteType
26−instance Binary REF.CLabel
27instance Binary REF.CNum
15instance Binary REF.CNum
28instance Binary REF.Literal
16instance Binary REF.Literal
29instance Binary REF.RefDate
17instance Binary REF.RefDate
30instance Binary REF.RefType
18instance Binary REF.RefType
31−instance Binary REF.Season
32instance Binary STY.Agent
19instance Binary STY.Agent
33instance Binary STY.Formatted
20instance Binary STY.Formatted
21+instance Binary Inline
22+instance Binary Block
23+instance Binary Citation
24+instance Binary MathType
25+instance Binary Alignment
26+instance Binary CitationMode
27+instance Binary QuoteType
28+instance Binary Format
29+instance Binary ListNumberDelim
30+instance Binary ListNumberStyle
31+instance Binary CSL.Reference
lib/Hakyll/Web/Pandoc/FileType.hs → src/Hakyll/Web/Pandoc/FileType.hsrenamed

The content is the same.

lib/Hakyll/Web/Tags.hs → src/Hakyll/Web/Tags.hsrenamed+2−3
@@ -43,7 +43,6 @@
43module Hakyll.Web.Tags
43module Hakyll.Web.Tags
44 ( Tags (..)
44 ( Tags (..)
45 , getTags
45 , getTags
46− , getCategory
47 , buildTagsWith
46 , buildTagsWith
48 , buildTags
47 , buildTags
49 , buildCategories
48 , buildCategories
@@ -98,7 +97,7 @@ data Tags = Tags
98 { tagsMap :: [(String, [Identifier])]
97 { tagsMap :: [(String, [Identifier])]
99 , tagsMakeId :: String -> Identifier
98 , tagsMakeId :: String -> Identifier
100 , tagsDependency :: Dependency
99 , tagsDependency :: Dependency
101− }
100+ } deriving (Show)
102
101
103
102
104--------------------------------------------------------------------------------
103--------------------------------------------------------------------------------
@@ -113,7 +112,7 @@ getTags identifier = do
113
112
114
113
115--------------------------------------------------------------------------------
114--------------------------------------------------------------------------------
116−-- | Obtain category from a page.
115+-- | Obtain categories from a page.
117getCategory :: MonadMetadata m => Identifier -> m [String]
116getCategory :: MonadMetadata m => Identifier -> m [String]
118getCategory = return . return . takeBaseName . takeDirectory . toFilePath
117getCategory = return . return . takeBaseName . takeDirectory . toFilePath
119
118
src/Hakyll/Web/Template.hsnew file+263
@@ -0,0 +1,263 @@
1+-- | This module provides means for reading and applying 'Template's.
2+--
3+-- Templates are tools to convert items into a string. They are perfectly suited
4+-- for laying out your site.
5+--
6+-- Let's look at an example template:
7+--
8+-- > <html>
9+-- > <head>
10+-- > <title>My crazy homepage - $title$</title>
11+-- > </head>
12+-- > <body>
13+-- > <div id="header">
14+-- > <h1>My crazy homepage - $title$</h1>
15+-- > </div>
16+-- > <div id="content">
17+-- > $body$
18+-- > </div>
19+-- > <div id="footer">
20+-- > By reading this you agree that I now own your soul
21+-- > </div>
22+-- > </body>
23+-- > </html>
24+--
25+-- As you can see, the format is very simple -- @$key$@ is used to render the
26+-- @$key$@ field from the page, everything else is literally copied. If you want
27+-- to literally insert @\"$key$\"@ into your page (for example, when you're
28+-- writing a Hakyll tutorial) you can use
29+--
30+-- > <p>
31+-- > A literal $$key$$.
32+-- > </p>
33+--
34+-- Because of it's simplicity, these templates can be used for more than HTML:
35+-- you could make, for example, CSS or JS templates as well.
36+--
37+-- Apart from interpolating @$key$@s from the 'Context' you can also
38+-- use the following macros:
39+--
40+-- * @$if(key)$@
41+--
42+-- > $if(key)$
43+-- > <b> Defined </b>
44+-- > $else$
45+-- > <b> Non-defined </b>
46+-- > $endif$
47+--
48+-- This example will print @Defined@ if @key@ is defined in the
49+-- context and @Non-defined@ otherwise. The @$else$@ clause is
50+-- optional.
51+--
52+-- * @$for(key)$@
53+--
54+-- The @for@ macro is used for enumerating 'Context' elements that are
55+-- lists, i.e. constructed using the 'listField' function. Assume that
56+-- in a context we have an element @listField \"key\" c itms@. Then
57+-- the snippet
58+--
59+-- > $for(key)$
60+-- > $x$
61+-- > $sep$,
62+-- > $endfor$
63+--
64+-- would, for each item @i@ in 'itms', lookup @$x$@ in the context @c@
65+-- with item @i@, interpolate it, and join the resulting list with
66+-- @,@.
67+--
68+-- Another concrete example one may consider is the following. Given the
69+-- context
70+--
71+-- > listField "things" (field "thing" (return . itemBody))
72+-- > (sequence [makeItem "fruits", makeItem "vegetables"])
73+--
74+-- and a template
75+--
76+-- > I like
77+-- > $for(things)$
78+-- > fresh $thing$$sep$, and
79+-- > $endfor$
80+--
81+-- the resulting page would look like
82+--
83+-- > <p>
84+-- > I like
85+-- >
86+-- > fresh fruits, and
87+-- >
88+-- > fresh vegetables
89+-- > </p>
90+--
91+-- The @$sep$@ part can be omitted. Usually, you can get by using the
92+-- 'applyListTemplate' and 'applyJoinListTemplate' functions.
93+--
94+-- * @$partial(path)$@
95+--
96+-- Loads a template located in a separate file and interpolates it
97+-- under the current context.
98+--
99+-- Assuming that the file @test.html@ contains
100+--
101+-- > <b>$key$</b>
102+--
103+-- The result of rendering
104+--
105+-- > <p>
106+-- > $partial("test.html")$
107+-- > </p>
108+--
109+-- is the same as the result of rendering
110+--
111+-- > <p>
112+-- > <b>$key$</b>
113+-- > </p>
114+--
115+-- That is, calling @$partial$@ is equivalent to just copying and pasting
116+-- template code.
117+--
118+{-# LANGUAGE ScopedTypeVariables #-}
119+module Hakyll.Web.Template
120+ ( Template
121+ , templateBodyCompiler
122+ , templateCompiler
123+ , applyTemplate
124+ , loadAndApplyTemplate
125+ , applyAsTemplate
126+ , readTemplate
127+ ) where
128+
129+
130+--------------------------------------------------------------------------------
131+import Control.Monad (liftM)
132+import Control.Monad.Except (MonadError (..))
133+import Data.List (intercalate)
134+import Prelude hiding (id)
135+
136+
137+--------------------------------------------------------------------------------
138+import Hakyll.Core.Compiler
139+import Hakyll.Core.Identifier
140+import Hakyll.Core.Item
141+import Hakyll.Web.Template.Context
142+import Hakyll.Web.Template.Internal
143+
144+
145+--------------------------------------------------------------------------------
146+-- | Read a template, without metadata header
147+templateBodyCompiler :: Compiler (Item Template)
148+templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
149+ item <- getResourceBody
150+ return $ fmap readTemplate item
151+
152+--------------------------------------------------------------------------------
153+-- | Read complete file contents as a template
154+templateCompiler :: Compiler (Item Template)
155+templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
156+ item <- getResourceString
157+ return $ fmap readTemplate item
158+
159+
160+--------------------------------------------------------------------------------
161+applyTemplate :: Template -- ^ Template
162+ -> Context a -- ^ Context
163+ -> Item a -- ^ Page
164+ -> Compiler (Item String) -- ^ Resulting item
165+applyTemplate tpl context item = do
166+ body <- applyTemplate' tpl context item
167+ return $ itemSetBody body item
168+
169+
170+--------------------------------------------------------------------------------
171+applyTemplate'
172+ :: forall a.
173+ Template -- ^ Template
174+ -> Context a -- ^ Context
175+ -> Item a -- ^ Page
176+ -> Compiler String -- ^ Resulting item
177+applyTemplate' tpl context x = go tpl
178+ where
179+ context' :: String -> [String] -> Item a -> Compiler ContextField
180+ context' = unContext (context `mappend` missingField)
181+
182+ go = liftM concat . mapM applyElem . unTemplate
183+
184+ ---------------------------------------------------------------------------
185+
186+ applyElem :: TemplateElement -> Compiler String
187+
188+ applyElem (Chunk c) = return c
189+
190+ applyElem (Expr e) = applyExpr e >>= getString e
191+
192+ applyElem Escaped = return "$"
193+
194+ applyElem (If e t mf) = (applyExpr e >> go t) `catchError` handler
195+ where
196+ handler _ = case mf of
197+ Nothing -> return ""
198+ Just f -> go f
199+
200+ applyElem (For e b s) = applyExpr e >>= \cf -> case cf of
201+ StringField _ -> fail $
202+ "Hakyll.Web.Template.applyTemplateWith: expected ListField but " ++
203+ "got StringField for expr " ++ show e
204+ ListField c xs -> do
205+ sep <- maybe (return "") go s
206+ bs <- mapM (applyTemplate' b c) xs
207+ return $ intercalate sep bs
208+
209+ applyElem (Partial e) = do
210+ p <- applyExpr e >>= getString e
211+ tpl' <- loadBody (fromFilePath p)
212+ applyTemplate' tpl' context x
213+
214+ ---------------------------------------------------------------------------
215+
216+ applyExpr :: TemplateExpr -> Compiler ContextField
217+
218+ applyExpr (Ident (TemplateKey k)) = context' k [] x
219+
220+ applyExpr (Call (TemplateKey k) args) = do
221+ args' <- mapM (\e -> applyExpr e >>= getString e) args
222+ context' k args' x
223+
224+ applyExpr (StringLiteral s) = return (StringField s)
225+
226+ ----------------------------------------------------------------------------
227+
228+ getString _ (StringField s) = return s
229+ getString e (ListField _ _) = fail $
230+ "Hakyll.Web.Template.applyTemplateWith: expected StringField but " ++
231+ "got ListField for expr " ++ show e
232+
233+
234+--------------------------------------------------------------------------------
235+-- | The following pattern is so common:
236+--
237+-- > tpl <- loadBody "templates/foo.html"
238+-- > someCompiler
239+-- > >>= applyTemplate tpl context
240+--
241+-- That we have a single function which does this:
242+--
243+-- > someCompiler
244+-- > >>= loadAndApplyTemplate "templates/foo.html" context
245+loadAndApplyTemplate :: Identifier -- ^ Template identifier
246+ -> Context a -- ^ Context
247+ -> Item a -- ^ Page
248+ -> Compiler (Item String) -- ^ Resulting item
249+loadAndApplyTemplate identifier context item = do
250+ tpl <- loadBody identifier
251+ applyTemplate tpl context item
252+
253+
254+--------------------------------------------------------------------------------
255+-- | It is also possible that you want to substitute @$key$@s within the body of
256+-- an item. This function does that by interpreting the item body as a template,
257+-- and then applying it to itself.
258+applyAsTemplate :: Context String -- ^ Context
259+ -> Item String -- ^ Item and template
260+ -> Compiler (Item String) -- ^ Resulting item
261+applyAsTemplate context item =
262+ let tpl = readTemplate $ itemBody item
263+ in applyTemplate tpl context item
lib/Hakyll/Web/Template/Context.hs → src/Hakyll/Web/Template/Context.hsrenamed+33−135
@@ -1,27 +1,6 @@
1−-- | This module provides 'Context's which are used to expand expressions in
2−-- templates and allow for arbitrary customisation.
3−--
4−-- 'Template's define a small expression DSL which consists of strings,
5−-- identifiers and function application. There is no type system, every value is
6−-- a string and on the top level they get substituted verbatim into the page.
7−--
8−-- For example, you can build a context that contains
9−--
10−-- > … <> functionField "concat" (const . concat) <> …
11−--
12−-- which will allow you to use the @concat@ identifier as a function that takes
13−-- arbitrarily many stings and concatenates them to a new string:
14−--
15−-- > $partial(concat("templates/categories/", category))$
16−--
17−-- This will evaluate the @category@ field in the context, then prepend he path,
18−-- and include the referenced file as a template.
19−
20−
21--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
22{-# LANGUAGE CPP #-}
2{-# LANGUAGE CPP #-}
23{-# LANGUAGE ExistentialQuantification #-}
3{-# LANGUAGE ExistentialQuantification #-}
24−{-# LANGUAGE RankNTypes #-}
25module Hakyll.Web.Template.Context
4module Hakyll.Web.Template.Context
26 ( ContextField (..)
5 ( ContextField (..)
27 , Context (..)
6 , Context (..)
@@ -49,17 +28,13 @@ module Hakyll.Web.Template.Context
49 , teaserField
28 , teaserField
50 , teaserFieldWithSeparator
29 , teaserFieldWithSeparator
51 , missingField
30 , missingField
52− , bindItem
53 ) where
31 ) where
54
32
55
33
56--------------------------------------------------------------------------------
34--------------------------------------------------------------------------------
57import Control.Applicative (Alternative (..))
35import Control.Applicative (Alternative (..))
58import Control.Monad (msum)
36import Control.Monad (msum)
59−import Data.List (intercalate, tails)
37+import Data.List (intercalate)
60−#if MIN_VERSION_base(4,9,0)
61−import Data.Semigroup (Semigroup (..))
62−#endif
63import Data.Time.Clock (UTCTime (..))
38import Data.Time.Clock (UTCTime (..))
64import Data.Time.Format (formatTime)
39import Data.Time.Format (formatTime)
65import qualified Data.Time.Format as TF
40import qualified Data.Time.Format as TF
@@ -72,16 +47,13 @@ import Hakyll.Core.Metadata
72import Hakyll.Core.Provider
47import Hakyll.Core.Provider
73import Hakyll.Core.Util.String (needlePrefix, splitAll)
48import Hakyll.Core.Util.String (needlePrefix, splitAll)
74import Hakyll.Web.Html
49import Hakyll.Web.Html
75−import Prelude hiding (id)
76−import System.FilePath (dropExtension, splitDirectories,
50+import System.FilePath (splitDirectories, takeBaseName)
77− takeBaseName)
78
51
79
52
80--------------------------------------------------------------------------------
53--------------------------------------------------------------------------------
81-- | Mostly for internal usage
54-- | Mostly for internal usage
82data ContextField
55data ContextField
83− = EmptyField
84− | StringField String
56+ = StringField String
85 | forall a. ListField (Context a) [Item a]
57 | forall a. ListField (Context a) [Item a]
86
58
87
59
@@ -106,123 +78,71 @@ newtype Context a = Context
106
78
107
79
108--------------------------------------------------------------------------------
80--------------------------------------------------------------------------------
109−-- | Tries to find a key in the left context,
110−-- or when that fails in the right context.
111−#if MIN_VERSION_base(4,9,0)
112−instance Semigroup (Context a) where
113− (<>) (Context f) (Context g) = Context $ \k a i -> f k a i <|> g k a i
114−
115−instance Monoid (Context a) where
116− mempty = missingField
117− mappend = (<>)
118−#else
119instance Monoid (Context a) where
81instance Monoid (Context a) where
120 mempty = missingField
82 mempty = missingField
121 mappend (Context f) (Context g) = Context $ \k a i -> f k a i <|> g k a i
83 mappend (Context f) (Context g) = Context $ \k a i -> f k a i <|> g k a i
122−#endif
123
84
124
85
125--------------------------------------------------------------------------------
86--------------------------------------------------------------------------------
126field' :: String -> (Item a -> Compiler ContextField) -> Context a
87field' :: String -> (Item a -> Compiler ContextField) -> Context a
127−field' key value = Context $ \k _ i ->
88+field' key value = Context $ \k _ i -> if k == key then value i else empty
128− if k == key
129− then value i
130− else noResult $ "Tried field " ++ key
131
89
132
90
133--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
134−-- | Constructs a new field for a 'Context'.
92+-- | Constructs a new field in the 'Context.'
135−-- If the key matches, the compiler is run and its result is substituted in the
136−-- template.
137−--
138−-- If the compiler fails, the field will be considered non-existent
139−-- in an @$if()$@ macro or ultimately break the template application
140−-- (unless the key is found in another context when using '<>').
141−-- Use 'empty' or 'noResult' for intentional failures of fields used in
142−-- @$if()$@, to distinguish them from exceptions thrown with 'fail'.
143field
93field
144 :: String -- ^ Key
94 :: String -- ^ Key
145 -> (Item a -> Compiler String) -- ^ Function that constructs a value based
95 -> (Item a -> Compiler String) -- ^ Function that constructs a value based
146− -- on the item (e.g. accessing metadata)
96+ -- on the item
147 -> Context a
97 -> Context a
148field key value = field' key (fmap StringField . value)
98field key value = field' key (fmap StringField . value)
149
99
150
100
151--------------------------------------------------------------------------------
101--------------------------------------------------------------------------------
152-- | Creates a 'field' to use with the @$if()$@ template macro.
102-- | Creates a 'field' to use with the @$if()$@ template macro.
153−-- Attempting to substitute the field into the template will cause an error.
154boolField
103boolField
155 :: String
104 :: String
156 -> (Item a -> Bool)
105 -> (Item a -> Bool)
157 -> Context a
106 -> Context a
158−boolField name f = field' name (\i -> if f i
107+boolField name f = field name (\i -> if f i
159− then return EmptyField
108+ then pure (error $ unwords ["no string value for bool field:",name])
160− else noResult $ "Field " ++ name ++ " is false")
109+ else empty)
161
110
162
111
163--------------------------------------------------------------------------------
112--------------------------------------------------------------------------------
164−-- | Creates a 'field' that does not depend on the 'Item' but always yields
113+-- | Creates a 'field' that does not depend on the 'Item'
165−-- the same string
166−constField :: String -- ^ Key
114+constField :: String -> String -> Context a
167− -> String -- ^ Value
168− -> Context a
169constField key = field key . const . return
115constField key = field key . const . return
170
116
171
117
172--------------------------------------------------------------------------------
118--------------------------------------------------------------------------------
173−-- | Creates a list field to be consumed by a @$for(…)$@ expression.
174−-- The compiler returns multiple items which are rendered in the loop body
175−-- with the supplied context.
176listField :: String -> Context a -> Compiler [Item a] -> Context b
119listField :: String -> Context a -> Compiler [Item a] -> Context b
177listField key c xs = listFieldWith key c (const xs)
120listField key c xs = listFieldWith key c (const xs)
178
121
179
122
180--------------------------------------------------------------------------------
123--------------------------------------------------------------------------------
181−-- | Produces a new 'Context' which has list field 'key'. All fields from
182−-- 'c' are also accessible from the produced context.
183−-- Be careful when doing @listFieldWith k ca f <> cb@ as any fields in @ca@
184−-- will override fields in @cb@ with the same name.
185−-- Creates a list field like 'listField', but supplies the current page
186−-- to the compiler.
187listFieldWith
124listFieldWith
188 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
125 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
189listFieldWith key c f = field' key $ fmap (ListField c) . f
126listFieldWith key c f = field' key $ fmap (ListField c) . f
190
127
191
128
192--------------------------------------------------------------------------------
129--------------------------------------------------------------------------------
193−-- | Creates a variadic function field.
194−--
195−-- The function will be called with the dynamically evaluated string arguments
196−-- from the template as well as the page that is currently rendered.
197−functionField :: String -- ^ Key
198− -> ([String] -> Item a -> Compiler String) -- ^ Function
130+functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
199− -> Context a
200functionField name value = Context $ \k args i ->
131functionField name value = Context $ \k args i ->
201 if k == name
132 if k == name
202 then StringField <$> value args i
133 then StringField <$> value args i
203− else noResult $ "Tried function field " ++ name
134+ else empty
204
135
205
136
206--------------------------------------------------------------------------------
137--------------------------------------------------------------------------------
207−-- | Transform the respective string results of all fields in a context.
208−-- For example,
209−--
210−-- > mapContext (++"c") (constField "x" "a" <> constField "y" "b")
211−--
212−-- is equivalent to
213−--
214−-- > constField "x" "ac" <> constField "y" "bc"
215−--
216mapContext :: (String -> String) -> Context a -> Context a
138mapContext :: (String -> String) -> Context a -> Context a
217mapContext f (Context c) = Context $ \k a i -> do
139mapContext f (Context c) = Context $ \k a i -> do
218 fld <- c k a i
140 fld <- c k a i
219 case fld of
141 case fld of
220− EmptyField -> wrongType "boolField"
221 StringField str -> return $ StringField (f str)
142 StringField str -> return $ StringField (f str)
222− _ -> wrongType "ListField"
143+ ListField _ _ -> fail $
223− where
224− wrongType typ = fail $ "Hakyll.Web.Template.Context.mapContext: " ++
144+ "Hakyll.Web.Template.Context.mapContext: " ++
225− "can't map over a " ++ typ ++ "!"
145+ "can't map over a ListField!"
226
146
227--------------------------------------------------------------------------------
147--------------------------------------------------------------------------------
228-- | A context that allows snippet inclusion. In processed file, use as:
148-- | A context that allows snippet inclusion. In processed file, use as:
@@ -231,15 +151,15 @@ mapContext f (Context c) = Context $ \k a i -> do
231-- > $snippet("path/to/snippet/")$
151-- > $snippet("path/to/snippet/")$
232-- > ...
152-- > ...
233--
153--
234−-- The contents of the included file will not be interpolated like @partial@
154+-- The contents of the included file will not be interpolated.
235−-- does it.
236--
155--
237snippetField :: Context String
156snippetField :: Context String
238snippetField = functionField "snippet" f
157snippetField = functionField "snippet" f
239 where
158 where
240 f [contentsPath] _ = loadBody (fromFilePath contentsPath)
159 f [contentsPath] _ = loadBody (fromFilePath contentsPath)
241− f [] _ = fail "No argument to function 'snippet()'"
160+ f _ i = error $
242− f _ _ = fail "Too many arguments to function 'snippet()'"
161+ "Too many arguments to function 'snippet()' in item " ++
162+ show (itemIdentifier i)
243
163
244--------------------------------------------------------------------------------
164--------------------------------------------------------------------------------
245-- | A context that contains (in that order)
165-- | A context that contains (in that order)
@@ -259,7 +179,8 @@ defaultContext =
259 metadataField `mappend`
179 metadataField `mappend`
260 urlField "url" `mappend`
180 urlField "url" `mappend`
261 pathField "path" `mappend`
181 pathField "path" `mappend`
262− titleField "title"
182+ titleField "title" `mappend`
183+ missingField
263
184
264
185
265--------------------------------------------------------------------------------
186--------------------------------------------------------------------------------
@@ -277,20 +198,15 @@ bodyField key = field key $ return . itemBody
277-- | Map any field to its metadata value, if present
198-- | Map any field to its metadata value, if present
278metadataField :: Context a
199metadataField :: Context a
279metadataField = Context $ \k _ i -> do
200metadataField = Context $ \k _ i -> do
280− let id = itemIdentifier i
281− empty' = noResult $ "No '" ++ k ++ "' field in metadata " ++
282− "of item " ++ show id
283− value <- getMetadataField id k
201+ value <- getMetadataField (itemIdentifier i) k
284− maybe empty' (return . StringField) value
202+ maybe empty (return . StringField) value
285
203
286
204
287--------------------------------------------------------------------------------
205--------------------------------------------------------------------------------
288-- | Absolute url to the resulting item
206-- | Absolute url to the resulting item
289urlField :: String -> Context a
207urlField :: String -> Context a
290−urlField key = field key $ \i -> do
208+urlField key = field key $
291− let id = itemIdentifier i
292− empty' = fail $ "No route url found for item " ++ show id
293− fmap (maybe empty' toUrl) $ getRoute id
209+ fmap (maybe empty toUrl) . getRoute . itemIdentifier
294
210
295
211
296--------------------------------------------------------------------------------
212--------------------------------------------------------------------------------
@@ -341,12 +257,6 @@ titleField = mapContext takeBaseName . pathField
341-- that begins with @yyyy-mm-dd@ . For example:
257-- that begins with @yyyy-mm-dd@ . For example:
342-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
258-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
343-- In case of multiple matches, the rightmost one is used.
259-- In case of multiple matches, the rightmost one is used.
344−--
345−-- As another alternative, if none of the above matches, and the file has a
346−-- path which contains nested directories specifying a date, then that date
347−-- will be used. In other words, if the path is of the form
348−-- @**//yyyy//mm//dd//**//main.extension@ .
349−-- As above, in case of multiple matches, the rightmost one is used.
350
260
351dateField :: String -- ^ Key in which the rendered date should be placed
261dateField :: String -- ^ Key in which the rendered date should be placed
352 -> String -- ^ Format to use on the date
262 -> String -- ^ Format to use on the date
@@ -357,7 +267,7 @@ dateField = dateFieldWith defaultTimeLocale
357--------------------------------------------------------------------------------
267--------------------------------------------------------------------------------
358-- | This is an extended version of 'dateField' that allows you to
268-- | This is an extended version of 'dateField' that allows you to
359-- specify a time locale that is used for outputting the date. For more
269-- specify a time locale that is used for outputting the date. For more
360−-- details, see 'dateField' and 'formatTime'.
270+-- details, see 'dateField'.
361dateFieldWith :: TimeLocale -- ^ Output time locale
271dateFieldWith :: TimeLocale -- ^ Output time locale
362 -> String -- ^ Destination key
272 -> String -- ^ Destination key
363 -> String -- ^ Format to use on the date
273 -> String -- ^ Format to use on the date
@@ -378,13 +288,12 @@ getItemUTC :: MonadMetadata m
378getItemUTC locale id' = do
288getItemUTC locale id' = do
379 metadata <- getMetadata id'
289 metadata <- getMetadata id'
380 let tryField k fmt = lookupString k metadata >>= parseTime' fmt
290 let tryField k fmt = lookupString k metadata >>= parseTime' fmt
381− paths = splitDirectories $ (dropExtension . toFilePath) id'
291+ paths = splitDirectories $ toFilePath id'
382
292
383 maybe empty' return $ msum $
293 maybe empty' return $ msum $
384 [tryField "published" fmt | fmt <- formats] ++
294 [tryField "published" fmt | fmt <- formats] ++
385 [tryField "date" fmt | fmt <- formats] ++
295 [tryField "date" fmt | fmt <- formats] ++
386− [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths] ++
296+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths]
387− [parseTime' "%Y-%m-%d" $ intercalate "-" $ fnCand | fnCand <- map (take 3) $ reverse . tails $ paths]
388 where
297 where
389 empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
298 empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
390 "could not parse time for " ++ show id'
299 "could not parse time for " ++ show id'
@@ -412,16 +321,13 @@ getItemModificationTime identifier = do
412
321
413
322
414--------------------------------------------------------------------------------
323--------------------------------------------------------------------------------
415−-- | Creates a field with the last modification date of the underlying item.
416modificationTimeField :: String -- ^ Key
324modificationTimeField :: String -- ^ Key
417 -> String -- ^ Format
325 -> String -- ^ Format
418− -> Context a -- ^ Resulting context
326+ -> Context a -- ^ Resuting context
419modificationTimeField = modificationTimeFieldWith defaultTimeLocale
327modificationTimeField = modificationTimeFieldWith defaultTimeLocale
420
328
421
329
422--------------------------------------------------------------------------------
330--------------------------------------------------------------------------------
423−-- | Creates a field with the last modification date of the underlying item
424−-- in a custom localisation format (see 'formatTime').
425modificationTimeFieldWith :: TimeLocale -- ^ Time output locale
331modificationTimeFieldWith :: TimeLocale -- ^ Time output locale
426 -> String -- ^ Key
332 -> String -- ^ Key
427 -> String -- ^ Format
333 -> String -- ^ Format
@@ -460,11 +366,10 @@ teaserFieldWithSeparator separator key snapshot = field key $ \item -> do
460
366
461
367
462--------------------------------------------------------------------------------
368--------------------------------------------------------------------------------
463−-- | Constantly reports any field as missing. Mostly for internal usage,
464−-- it is the last choice in every context used in a template application.
465missingField :: Context a
369missingField :: Context a
466−missingField = Context $ \k _ _ -> noResult $
370+missingField = Context $ \k _ i -> fail $
467− "Missing field '" ++ k ++ "' in context"
371+ "Missing field $" ++ k ++ "$ in context for item " ++
372+ show (itemIdentifier i)
468
373
469parseTimeM :: Bool -> TimeLocale -> String -> String -> Maybe UTCTime
374parseTimeM :: Bool -> TimeLocale -> String -> String -> Maybe UTCTime
470#if MIN_VERSION_time(1,5,0)
375#if MIN_VERSION_time(1,5,0)
@@ -472,10 +377,3 @@ parseTimeM = TF.parseTimeM
472#else
377#else
473parseTimeM _ = TF.parseTime
378parseTimeM _ = TF.parseTime
474#endif
379#endif
475−
476−--------------------------------------------------------------------------------
477−
478−-- | Binds an 'Item' to a given 'Context', allowing it to be combined with any
479−-- other 'Context' of any type.
480−bindItem :: Context a -> Item a -> forall b. Context b
481−bindItem (Context ctx) ia = Context $ \k args _ -> ctx k args ia
lib/Hakyll/Web/Template/Internal/Element.hs → src/Hakyll/Web/Template/Internal.hsrenamed+68−138
@@ -1,24 +1,22 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−-- | Module containing the elements used in a template. A template is generally
2+-- | Module containing the template data structure
3−-- just a list of these elements.
3+{-# LANGUAGE DeriveDataTypeable #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−module Hakyll.Web.Template.Internal.Element
5+module Hakyll.Web.Template.Internal
6+ ( Template (..)
6− ( TemplateKey (..)
7+ , TemplateKey (..)
7 , TemplateExpr (..)
8 , TemplateExpr (..)
8 , TemplateElement (..)
9 , TemplateElement (..)
9− , templateElems
10+ , readTemplate
10− , parseTemplateElemsFile
11 ) where
11 ) where
12
12
13
13
14--------------------------------------------------------------------------------
14--------------------------------------------------------------------------------
15−import Control.Applicative ((<|>), (<*))
15+import Control.Applicative ((<|>))
16import Control.Monad (void)
16import Control.Monad (void)
17−import Control.Arrow (left)
18import Data.Binary (Binary, get, getWord8, put, putWord8)
17import Data.Binary (Binary, get, getWord8, put, putWord8)
19−import Data.List (intercalate)
20−import Data.Maybe (isJust)
21import Data.Typeable (Typeable)
18import Data.Typeable (Typeable)
19+import Data.List (intercalate)
22import GHC.Exts (IsString (..))
20import GHC.Exts (IsString (..))
23import qualified Text.Parsec as P
21import qualified Text.Parsec as P
24import qualified Text.Parsec.String as P
22import qualified Text.Parsec.String as P
@@ -26,6 +24,25 @@ import qualified Text.Parsec.String as P
26
24
27--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
28import Hakyll.Core.Util.Parser
26import Hakyll.Core.Util.Parser
27+import Hakyll.Core.Writable
28+
29+
30+--------------------------------------------------------------------------------
31+-- | Datatype used for template substitutions.
32+newtype Template = Template
33+ { unTemplate :: [TemplateElement]
34+ } deriving (Show, Eq, Binary, Typeable)
35+
36+
37+--------------------------------------------------------------------------------
38+instance Writable Template where
39+ -- Writing a template is impossible
40+ write _ _ = return ()
41+
42+
43+--------------------------------------------------------------------------------
44+instance IsString Template where
45+ fromString = readTemplate
29
46
30
47
31--------------------------------------------------------------------------------
48--------------------------------------------------------------------------------
@@ -44,14 +61,9 @@ data TemplateElement
44 = Chunk String
61 = Chunk String
45 | Expr TemplateExpr
62 | Expr TemplateExpr
46 | Escaped
63 | Escaped
47− -- expr, then, else
64+ | If TemplateExpr Template (Maybe Template) -- expr, then, else
48− | If TemplateExpr [TemplateElement] (Maybe [TemplateElement])
49− -- expr, body, separator
65+ | For TemplateExpr Template (Maybe Template) -- expr, body, separator
50− | For TemplateExpr [TemplateElement] (Maybe [TemplateElement])
51− -- filename
52− | Partial TemplateExpr
66+ | Partial TemplateExpr -- filename
53− | TrimL
54− | TrimR
55 deriving (Show, Eq, Typeable)
67 deriving (Show, Eq, Typeable)
56
68
57
69
@@ -59,12 +71,10 @@ data TemplateElement
59instance Binary TemplateElement where
71instance Binary TemplateElement where
60 put (Chunk string) = putWord8 0 >> put string
72 put (Chunk string) = putWord8 0 >> put string
61 put (Expr e) = putWord8 1 >> put e
73 put (Expr e) = putWord8 1 >> put e
62− put Escaped = putWord8 2
74+ put (Escaped) = putWord8 2
63− put (If e t f) = putWord8 3 >> put e >> put t >> put f
75+ put (If e t f ) = putWord8 3 >> put e >> put t >> put f
64 put (For e b s) = putWord8 4 >> put e >> put b >> put s
76 put (For e b s) = putWord8 4 >> put e >> put b >> put s
65 put (Partial e) = putWord8 5 >> put e
77 put (Partial e) = putWord8 5 >> put e
66− put TrimL = putWord8 6
67− put TrimR = putWord8 7
68
78
69 get = getWord8 >>= \tag -> case tag of
79 get = getWord8 >>= \tag -> case tag of
70 0 -> Chunk <$> get
80 0 -> Chunk <$> get
@@ -73,9 +83,8 @@ instance Binary TemplateElement where
73 3 -> If <$> get <*> get <*> get
83 3 -> If <$> get <*> get <*> get
74 4 -> For <$> get <*> get <*> get
84 4 -> For <$> get <*> get <*> get
75 5 -> Partial <$> get
85 5 -> Partial <$> get
76− 6 -> pure TrimL
86+ _ -> error $
77− 7 -> pure TrimR
78− _ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
87+ "Hakyll.Web.Template.Internal: Error reading cached template"
79
88
80
89
81--------------------------------------------------------------------------------
90--------------------------------------------------------------------------------
@@ -105,38 +114,35 @@ instance Binary TemplateExpr where
105 0 -> Ident <$> get
114 0 -> Ident <$> get
106 1 -> Call <$> get <*> get
115 1 -> Call <$> get <*> get
107 2 -> StringLiteral <$> get
116 2 -> StringLiteral <$> get
117+ _ -> error $
108− _ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
118+ "Hakyll.Web.Tamplte.Internal: Error reading cached template"
119+
109
120
110--------------------------------------------------------------------------------
121--------------------------------------------------------------------------------
111−parseTemplateElemsFile :: FilePath -> String -> Either String [TemplateElement]
122+readTemplate :: String -> Template
123+readTemplate input = case P.parse template "" input of
112−parseTemplateElemsFile file = left (\e -> "Cannot parse template " ++ show e)
124+ Left err -> error $ "Cannot parse template: " ++ show err
113− . P.parse (templateElems <* P.eof) file
125+ Right t -> t
114
126
115
127
116--------------------------------------------------------------------------------
128--------------------------------------------------------------------------------
117−templateElems :: P.Parser [TemplateElement]
129+template :: P.Parser Template
118−templateElems = mconcat <$> P.many (P.choice [ lift chunk
130+template = Template <$>
119− , lift escaped
120− , conditional
131+ (P.many $ chunk <|> escaped <|> conditional <|> for <|> partial <|> expr)
121− , for
122− , partial
123− , expr
124− ])
125− where lift = fmap (:[])
126
132
127
133
128--------------------------------------------------------------------------------
134--------------------------------------------------------------------------------
129chunk :: P.Parser TemplateElement
135chunk :: P.Parser TemplateElement
130−chunk = Chunk <$> P.many1 (P.noneOf "$")
136+chunk = Chunk <$> (P.many1 $ P.noneOf "$")
131
137
132
138
133--------------------------------------------------------------------------------
139--------------------------------------------------------------------------------
134−expr :: P.Parser [TemplateElement]
140+expr :: P.Parser TemplateElement
135expr = P.try $ do
141expr = P.try $ do
136− trimLExpr <- trimOpen
142+ void $ P.char '$'
137 e <- expr'
143 e <- expr'
138− trimRExpr <- trimClose
144+ void $ P.char '$'
139− return $ [TrimL | trimLExpr] ++ [Expr e] ++ [TrimR | trimRExpr]
145+ return $ Expr e
140
146
141
147
142--------------------------------------------------------------------------------
148--------------------------------------------------------------------------------
@@ -146,105 +152,40 @@ expr' = stringLiteral <|> call <|> ident
146
152
147--------------------------------------------------------------------------------
153--------------------------------------------------------------------------------
148escaped :: P.Parser TemplateElement
154escaped :: P.Parser TemplateElement
149−escaped = Escaped <$ P.try (P.string "$$")
155+escaped = Escaped <$ (P.try $ P.string "$$")
150−
151−
152−--------------------------------------------------------------------------------
153−trimOpen :: P.Parser Bool
154−trimOpen = do
155− void $ P.char '$'
156− trimLIf <- P.optionMaybe $ P.try (P.char '-')
157− pure $ isJust trimLIf
158−
159−
160−--------------------------------------------------------------------------------
161−trimClose :: P.Parser Bool
162−trimClose = do
163− trimIfR <- P.optionMaybe $ (P.char '-')
164− void $ P.char '$'
165− pure $ isJust trimIfR
166
156
167
157
168--------------------------------------------------------------------------------
158--------------------------------------------------------------------------------
169−conditional :: P.Parser [TemplateElement]
159+conditional :: P.Parser TemplateElement
170conditional = P.try $ do
160conditional = P.try $ do
171− -- if
172− trimLIf <- trimOpen
173− void $ P.string "if("
161+ void $ P.string "$if("
174 e <- expr'
162 e <- expr'
175− void $ P.char ')'
163+ void $ P.string ")$"
176− trimRIf <- trimClose
164+ thenBranch <- template
177− -- then
165+ elseBranch <- P.optionMaybe $ P.try (P.string "$else$") >> template
178− thenBranch <- templateElems
179− -- else
180− elseParse <- opt "else"
181− -- endif
182− trimLEnd <- trimOpen
183− void $ P.string "endif"
166+ void $ P.string "$endif$"
184− trimREnd <- trimClose
167+ return $ If e thenBranch elseBranch
185−
186− -- As else is optional we need to sort out where any Trim_s need to go.
187− let (thenBody, elseBody) = maybe (thenNoElse, Nothing) thenElse elseParse
188− where thenNoElse =
189− [TrimR | trimRIf] ++ thenBranch ++ [TrimL | trimLEnd]
190−
191− thenElse (trimLElse, elseBranch, trimRElse) = (thenB, elseB)
192− where thenB = [TrimR | trimRIf]
193− ++ thenBranch
194− ++ [TrimL | trimLElse]
195−
196− elseB = Just $ [TrimR | trimRElse]
197− ++ elseBranch
198− ++ [TrimL | trimLEnd]
199−
200− pure $ [TrimL | trimLIf] ++ [If e thenBody elseBody] ++ [TrimR | trimREnd]
201
168
202
169
203--------------------------------------------------------------------------------
170--------------------------------------------------------------------------------
204−for :: P.Parser [TemplateElement]
171+for :: P.Parser TemplateElement
205for = P.try $ do
172for = P.try $ do
206− -- for
207− trimLFor <- trimOpen
208− void $ P.string "for("
173+ void $ P.string "$for("
209 e <- expr'
174 e <- expr'
210− void $ P.char ')'
175+ void $ P.string ")$"
211− trimRFor <- trimClose
176+ body <- template
212− -- body
177+ sep <- P.optionMaybe $ P.try (P.string "$sep$") >> template
213− bodyBranch <- templateElems
214− -- sep
215− sepParse <- opt "sep"
216− -- endfor
217− trimLEnd <- trimOpen
218− void $ P.string "endfor"
178+ void $ P.string "$endfor$"
219− trimREnd <- trimClose
179+ return $ For e body sep
220−
221− -- As sep is optional we need to sort out where any Trim_s need to go.
222− let (forBody, sepBody) = maybe (forNoSep, Nothing) forSep sepParse
223− where forNoSep =
224− [TrimR | trimRFor] ++ bodyBranch ++ [TrimL | trimLEnd]
225−
226− forSep (trimLSep, sepBranch, trimRSep) = (forB, sepB)
227− where forB = [TrimR | trimRFor]
228− ++ bodyBranch
229− ++ [TrimL | trimLSep]
230−
231− sepB = Just $ [TrimR | trimRSep]
232− ++ sepBranch
233− ++ [TrimL | trimLEnd]
234−
235− pure $ [TrimL | trimLFor] ++ [For e forBody sepBody] ++ [TrimR | trimREnd]
236
180
237
181
238--------------------------------------------------------------------------------
182--------------------------------------------------------------------------------
239−partial :: P.Parser [TemplateElement]
183+partial :: P.Parser TemplateElement
240partial = P.try $ do
184partial = P.try $ do
241− trimLPart <- trimOpen
242− void $ P.string "partial("
185+ void $ P.string "$partial("
243 e <- expr'
186 e <- expr'
244− void $ P.char ')'
187+ void $ P.string ")$"
245− trimRPart <- trimClose
188+ return $ Partial e
246−
247− pure $ [TrimL | trimLPart] ++ [Partial e] ++ [TrimR | trimRPart]
248
189
249
190
250--------------------------------------------------------------------------------
191--------------------------------------------------------------------------------
@@ -278,14 +219,3 @@ stringLiteral = do
278--------------------------------------------------------------------------------
219--------------------------------------------------------------------------------
279key :: P.Parser TemplateKey
220key :: P.Parser TemplateKey
280key = TemplateKey <$> metadataKey
221key = TemplateKey <$> metadataKey
281−
282−
283−--------------------------------------------------------------------------------
284−opt :: String -> P.Parser (Maybe (Bool, [TemplateElement], Bool))
285−opt clause = P.optionMaybe $ P.try $ do
286− trimL <- trimOpen
287− void $ P.string clause
288− trimR <- trimClose
289− branch <- templateElems
290− pure (trimL, branch, trimR)
291−
lib/Hakyll/Web/Template/List.hs → src/Hakyll/Web/Template/List.hsrenamed

The content is the same.

stack.yaml+6−27
@@ -1,33 +1,12 @@
1−resolver: lts-13.29
1+resolver: lts-5.11
2−save-hackage-creds: false
2+extra-deps: []
3+extra-package-dbs: []
3
4
4flags:
5flags:
5 hakyll:
6 hakyll:
6− previewServer: true
7+ previewServer: True
7− watchServer: true
8+ watchServer: True
8− checkExternal: true
9+ checkExternal: True
9− usePandoc: true
10− buildWebsite: true
11
10
12packages:
11packages:
13 - '.'
12 - '.'
14−
15−nix:
16− enable: false
17− packages:
18− - zlib
19−
20−build:
21− haddock: true
22− haddock-hyperlink-source: true
23− haddock-deps: false
24−
25−extra-deps:
26−- 'cmark-gfm-0.2.0'
27−- 'hslua-module-system-0.2.1'
28−- 'ipynb-0.1'
29−- 'lrucache-1.2.0.1'
30−- 'pandoc-2.7.3'
31−- 'pandoc-citeproc-0.16.2'
32−- 'skylighting-0.8.2'
33−- 'skylighting-core-0.8.2'
test.hsdeleted−30
@@ -1,30 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−import Control.Monad (forM)
3−import qualified Crypto.Hash.SHA256 as SHA256
4−import qualified Data.ByteString.Base16 as Base16
5−import qualified Data.ByteString.Char8 as BS8
6−import qualified Data.ByteString.Lazy as BSL
7−import Data.Map (Map)
8−import qualified Data.Map as Map
9−import Hakyll
10−import System.FilePath ((</>))
11−
12−type FileHashes = Map Identifier String
13−
14−mkFileHashes :: FilePath -> IO FileHashes
15−mkFileHashes dir = do
16− allFiles <- getRecursiveContents (\_ -> return False) dir
17− fmap Map.fromList $ forM allFiles $ \path0 -> do
18− let path1 = dir </> path0
19− !h <- hash path1
20− return (fromFilePath path1, h)
21− where
22− hash :: FilePath -> IO String
23− hash fp = do
24− !h <- SHA256.hashlazy <$> BSL.readFile fp
25− return $! BS8.unpack $! Base16.encode h
26−
27−main :: IO ()
28−main = hakyll $ do
29− fileHashes <- preprocess (mkFileHashes "images")
30− undefined
tests/Hakyll/Core/Dependencies/Tests.hs+3−3
@@ -9,8 +9,8 @@ module Hakyll.Core.Dependencies.Tests
9import Data.List (delete)
9import Data.List (delete)
10import qualified Data.Map as M
10import qualified Data.Map as M
11import qualified Data.Set as S
11import qualified Data.Set as S
12−import Test.Tasty (TestTree, testGroup)
12+import Test.Framework (Test, testGroup)
13−import Test.Tasty.HUnit (Assertion, (@=?))
13+import Test.HUnit (Assertion, (@=?))
14
14
15
15
16--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
@@ -20,7 +20,7 @@ import TestSuite.Util
20
20
21
21
22--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
23−tests :: TestTree
23+tests :: Test
24tests = testGroup "Hakyll.Core.Dependencies.Tests" $
24tests = testGroup "Hakyll.Core.Dependencies.Tests" $
25 fromAssertions "analyze" [case01, case02, case03]
25 fromAssertions "analyze" [case01, case02, case03]
26
26
tests/Hakyll/Core/Identifier/Tests.hs+5−6
@@ -6,8 +6,8 @@ module Hakyll.Core.Identifier.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Test.Tasty (TestTree, testGroup)
9+import Test.Framework (Test, testGroup)
10−import Test.Tasty.HUnit ((@=?))
10+import Test.HUnit ((@=?))
11
11
12
12
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
@@ -17,7 +17,7 @@ import TestSuite.Util
17
17
18
18
19--------------------------------------------------------------------------------
19--------------------------------------------------------------------------------
20−tests :: TestTree
20+tests :: Test
21tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
21tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
22 [ captureTests
22 [ captureTests
23 , matchesTests
23 , matchesTests
@@ -25,7 +25,7 @@ tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
25
25
26
26
27--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
28−captureTests :: [TestTree]
28+captureTests :: [Test]
29captureTests = fromAssertions "capture"
29captureTests = fromAssertions "capture"
30 [ Just ["bar"] @=? capture "foo/**" "foo/bar"
30 [ Just ["bar"] @=? capture "foo/**" "foo/bar"
31 , Just ["foo/bar"] @=? capture "**" "foo/bar"
31 , Just ["foo/bar"] @=? capture "**" "foo/bar"
@@ -42,12 +42,11 @@ captureTests = fromAssertions "capture"
42 , Just ["lol", "fun/large"] @=? capture "*cat/**.jpg" "lolcat/fun/large.jpg"
42 , Just ["lol", "fun/large"] @=? capture "*cat/**.jpg" "lolcat/fun/large.jpg"
43 , Just [] @=? capture "\\*.jpg" "*.jpg"
43 , Just [] @=? capture "\\*.jpg" "*.jpg"
44 , Nothing @=? capture "\\*.jpg" "foo.jpg"
44 , Nothing @=? capture "\\*.jpg" "foo.jpg"
45− , Just ["xyz","42"] @=? capture (fromRegex "cat-([a-z]+)/foo([0-9]+).jpg") "cat-xyz/foo42.jpg"
46 ]
45 ]
47
46
48
47
49--------------------------------------------------------------------------------
48--------------------------------------------------------------------------------
50−matchesTests :: [TestTree]
49+matchesTests :: [Test]
51matchesTests = fromAssertions "matches"
50matchesTests = fromAssertions "matches"
52 [ True @=? matches (fromList ["foo.markdown"]) "foo.markdown"
51 [ True @=? matches (fromList ["foo.markdown"]) "foo.markdown"
53 , False @=? matches (fromList ["foo"]) (setVersion (Just "x") "foo")
52 , False @=? matches (fromList ["foo"]) (setVersion (Just "x") "foo")
tests/Hakyll/Core/Provider/Metadata/Tests.hs+5−13
@@ -10,13 +10,13 @@ import qualified Data.Text as T
10import qualified Data.Yaml as Yaml
10import qualified Data.Yaml as Yaml
11import Hakyll.Core.Metadata
11import Hakyll.Core.Metadata
12import Hakyll.Core.Provider.Metadata
12import Hakyll.Core.Provider.Metadata
13−import Test.Tasty (TestTree, testGroup)
13+import Test.Framework (Test, testGroup)
14−import Test.Tasty.HUnit (Assertion, assertFailure, (@=?))
14+import Test.HUnit (Assertion, (@=?))
15import TestSuite.Util
15import TestSuite.Util
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
19−tests :: TestTree
19+tests :: Test
20tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
20tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
21 fromAssertions "page" [testPage01, testPage02]
21 fromAssertions "page" [testPage01, testPage02]
22
22
@@ -25,7 +25,7 @@ tests = testGroup "Hakyll.Core.Provider.Metadata.Tests" $
25--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
26testPage01 :: Assertion
26testPage01 :: Assertion
27testPage01 =
27testPage01 =
28− (meta [("foo", "bar")], "qux\n") `expectRight` parsePage
28+ Right (meta [("foo", "bar")], "qux\n") @=? parsePage
29 "---\n\
29 "---\n\
30 \foo: bar\n\
30 \foo: bar\n\
31 \---\n\
31 \---\n\
@@ -35,7 +35,7 @@ testPage01 =
35--------------------------------------------------------------------------------
35--------------------------------------------------------------------------------
36testPage02 :: Assertion
36testPage02 :: Assertion
37testPage02 =
37testPage02 =
38− (meta [("description", descr)], "Hello I am dog\n") `expectRight`
38+ Right (meta [("description", descr)], "Hello I am dog\n") @=?
39 parsePage
39 parsePage
40 "---\n\
40 "---\n\
41 \description: A long description that would look better if it\n\
41 \description: A long description that would look better if it\n\
@@ -52,11 +52,3 @@ testPage02 =
52--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
53meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
53meta :: Yaml.ToJSON a => [(String, a)] -> Metadata
54meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
54meta pairs = HMS.fromList [(T.pack k, Yaml.toJSON v) | (k, v) <- pairs]
55−
56−
57−--------------------------------------------------------------------------------
58−-- | This is useful when the 'Left' side of 'Either' doesn't have an 'Eq'
59−-- instance.
60−expectRight :: (Eq b, Show a, Show b) => b -> Either a b -> Assertion
61−expectRight _ (Left err) = assertFailure (show err)
62−expectRight expected (Right res) = expected @=? res
tests/Hakyll/Core/Provider/Tests.hs+5−4
@@ -8,13 +8,14 @@ module Hakyll.Core.Provider.Tests
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9import Hakyll.Core.Metadata
9import Hakyll.Core.Metadata
10import Hakyll.Core.Provider
10import Hakyll.Core.Provider
11−import Test.Tasty (TestTree, testGroup)
11+import Test.Framework (Test, testGroup)
12+import Test.Framework.Providers.HUnit (testCase)
12−import Test.Tasty.HUnit (Assertion, testCase, (@=?))
13+import Test.HUnit (Assertion, assert, (@=?))
13import TestSuite.Util
14import TestSuite.Util
14
15
15
16
16--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
17−tests :: TestTree
18+tests :: Test
18tests = testGroup "Hakyll.Core.Provider.Tests"
19tests = testGroup "Hakyll.Core.Provider.Tests"
19 [ testCase "case01" case01
20 [ testCase "case01" case01
20 ]
21 ]
@@ -25,7 +26,7 @@ case01 :: Assertion
25case01 = do
26case01 = do
26 store <- newTestStore
27 store <- newTestStore
27 provider <- newTestProvider store
28 provider <- newTestProvider store
28− True @=? resourceExists provider "example.md"
29+ assert $ resourceExists provider "example.md"
29
30
30 metadata <- resourceMetadata provider "example.md"
31 metadata <- resourceMetadata provider "example.md"
31 Just "An example" @=? lookupString "title" metadata
32 Just "An example" @=? lookupString "title" metadata
tests/Hakyll/Core/Routes/Tests.hs+3−3
@@ -11,13 +11,13 @@ import Hakyll.Core.Identifier
11import Hakyll.Core.Metadata
11import Hakyll.Core.Metadata
12import Hakyll.Core.Routes
12import Hakyll.Core.Routes
13import System.FilePath ((</>))
13import System.FilePath ((</>))
14−import Test.Tasty (TestTree, testGroup)
14+import Test.Framework (Test, testGroup)
15−import Test.Tasty.HUnit (Assertion, (@=?))
15+import Test.HUnit (Assertion, (@=?))
16import TestSuite.Util
16import TestSuite.Util
17
17
18
18
19--------------------------------------------------------------------------------
19--------------------------------------------------------------------------------
20−tests :: TestTree
20+tests :: Test
21tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
21tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
22 [ testRoutes "foo.html" (setExtension "html") "foo"
22 [ testRoutes "foo.html" (setExtension "html") "foo"
23 , testRoutes "foo.html" (setExtension ".html") "foo"
23 , testRoutes "foo.html" (setExtension ".html") "foo"
tests/Hakyll/Core/Rules/Tests.hs+6−5
@@ -17,14 +17,15 @@ import Hakyll.Core.Metadata
17import Hakyll.Core.Routes
17import Hakyll.Core.Routes
18import Hakyll.Core.Rules
18import Hakyll.Core.Rules
19import Hakyll.Core.Rules.Internal
19import Hakyll.Core.Rules.Internal
20+import Hakyll.Web.Pandoc
20import System.FilePath ((</>))
21import System.FilePath ((</>))
21−import Test.Tasty (TestTree, testGroup)
22+import Test.Framework (Test, testGroup)
22−import Test.Tasty.HUnit (Assertion, (@=?))
23+import Test.HUnit (Assertion, assert, (@=?))
23import TestSuite.Util
24import TestSuite.Util
24
25
25
26
26--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
27−tests :: TestTree
28+tests :: Test
28tests = testGroup "Hakyll.Core.Rules.Tests" $ fromAssertions "runRules"
29tests = testGroup "Hakyll.Core.Rules.Tests" $ fromAssertions "runRules"
29 [case01]
30 [case01]
30
31
@@ -49,7 +50,7 @@ case01 = do
49 checkRoute "example.mv1" (sv "mv1" "example.md")
50 checkRoute "example.mv1" (sv "mv1" "example.md")
50 checkRoute "example.mv2" (sv "mv2" "example.md")
51 checkRoute "example.mv2" (sv "mv2" "example.md")
51 checkRoute "food/example.md" (sv "metadataMatch" "example.md")
52 checkRoute "food/example.md" (sv "metadataMatch" "example.md")
52− readIORef ioref >>= (True @=?)
53+ readIORef ioref >>= assert
53 cleanTestEnv
54 cleanTestEnv
54 where
55 where
55 sv g = setVersion (Just g)
56 sv g = setVersion (Just g)
@@ -74,7 +75,7 @@ rules01 ioref = do
74 -- Compile some posts
75 -- Compile some posts
75 match "*.md" $ do
76 match "*.md" $ do
76 route $ setExtension "html"
77 route $ setExtension "html"
77− compile copyFileCompiler
78+ compile pandocCompiler
78
79
79 -- Yeah. I don't know how else to test this stuff?
80 -- Yeah. I don't know how else to test this stuff?
80 preprocess $ writeIORef ioref True
81 preprocess $ writeIORef ioref True
tests/Hakyll/Core/Runtime/Tests.hs+4−17
@@ -8,8 +8,8 @@ module Hakyll.Core.Runtime.Tests
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9import qualified Data.ByteString as B
9import qualified Data.ByteString as B
10import System.FilePath ((</>))
10import System.FilePath ((</>))
11−import Test.Tasty (TestTree, testGroup)
11+import Test.Framework (Test, testGroup)
12−import Test.Tasty.HUnit (Assertion, (@?=))
12+import Test.HUnit (Assertion, (@?=))
13
13
14
14
15--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
@@ -20,7 +20,7 @@ import TestSuite.Util
20
20
21
21
22--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
23−tests :: TestTree
23+tests :: Test
24tests = testGroup "Hakyll.Core.Runtime.Tests" $
24tests = testGroup "Hakyll.Core.Runtime.Tests" $
25 fromAssertions "run" [case01, case02]
25 fromAssertions "run" [case01, case02]
26
26
@@ -39,16 +39,7 @@ case01 = do
39 compile $ do
39 compile $ do
40 getResourceBody
40 getResourceBody
41 >>= saveSnapshot "raw"
41 >>= saveSnapshot "raw"
42− >>= renderParagraphs
42+ >>= renderPandoc
43−
44− match (fromList ["partial.html", "partial-helper.html"]) $
45− compile templateCompiler
46− create ["partial.html.out"] $ do
47− route idRoute
48− compile $ do
49− example <- loadSnapshotBody "example.md" "raw"
50− makeItem example
51− >>= loadAndApplyTemplate "partial.html" defaultContext
52
43
53 create ["bodies.txt"] $ do
44 create ["bodies.txt"] $ do
54 route idRoute
45 route idRoute
@@ -69,10 +60,6 @@ case01 = do
69 bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
60 bodies <- readFile $ destinationDirectory testConfiguration </> "bodies.txt"
70 head (lines bodies) @?= "This is an example."
61 head (lines bodies) @?= "This is an example."
71
62
72− partial <- readFile $ providerDirectory testConfiguration </> "partial.html.out"
73− partial' <- readFile $ destinationDirectory testConfiguration </> "partial.html.out"
74− partial @?= partial'
75−
76 cleanTestEnv
63 cleanTestEnv
77
64
78
65
tests/Hakyll/Core/Store/Tests.hs+16−16
@@ -6,22 +6,22 @@ module Hakyll.Core.Store.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Data.Typeable (typeOf)
9+import Data.Typeable (typeOf)
10−import qualified Test.QuickCheck as Q
11−import qualified Test.QuickCheck.Monadic as Q
12−import Test.Tasty (TestTree, testGroup)
10+import Test.Framework (Test, testGroup)
13−import Test.Tasty.HUnit (testCase)
11+import Test.Framework.Providers.HUnit (testCase)
14−import qualified Test.Tasty.HUnit as H
12+import Test.Framework.Providers.QuickCheck2 (testProperty)
15−import Test.Tasty.QuickCheck (testProperty)
13+import qualified Test.HUnit as H
14+import qualified Test.QuickCheck as Q
15+import qualified Test.QuickCheck.Monadic as Q
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
19−import qualified Hakyll.Core.Store as Store
19+import qualified Hakyll.Core.Store as Store
20import TestSuite.Util
20import TestSuite.Util
21
21
22
22
23--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
24−tests :: TestTree
24+tests :: Test
25tests = testGroup "Hakyll.Core.Store.Tests"
25tests = testGroup "Hakyll.Core.Store.Tests"
26 [ testProperty "simple get . set" simpleSetGet
26 [ testProperty "simple get . set" simpleSetGet
27 , testProperty "persistent get . set" persistentSetGet
27 , testProperty "persistent get . set" persistentSetGet
@@ -63,11 +63,11 @@ wrongType = do
63 -- Store a string and try to fetch an int
63 -- Store a string and try to fetch an int
64 Store.set store ["foo", "bar"] ("qux" :: String)
64 Store.set store ["foo", "bar"] ("qux" :: String)
65 value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
65 value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
66− case value of
66+ H.assert $ case value of
67− Store.WrongType e t -> do
67+ Store.WrongType e t ->
68− typeOf (undefined :: Int) H.@=? e
68+ e == typeOf (undefined :: Int) &&
69− typeOf (undefined :: String) H.@=? t
69+ t == typeOf (undefined :: String)
70− _ -> H.assertFailure "Expecting WrongType"
70+ _ -> False
71 cleanTestEnv
71 cleanTestEnv
72
72
73
73
@@ -78,6 +78,6 @@ isMembertest = do
78 Store.set store ["foo", "bar"] ("qux" :: String)
78 Store.set store ["foo", "bar"] ("qux" :: String)
79 good <- Store.isMember store ["foo", "bar"]
79 good <- Store.isMember store ["foo", "bar"]
80 bad <- Store.isMember store ["foo", "baz"]
80 bad <- Store.isMember store ["foo", "baz"]
81− True H.@=? good
81+ H.assert good
82− False H.@=? bad
82+ H.assert (not bad)
83 cleanTestEnv
83 cleanTestEnv
tests/Hakyll/Core/UnixFilter/Tests.hs+13−23
@@ -6,38 +6,36 @@ module Hakyll.Core.UnixFilter.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9+import Data.List (isInfixOf)
9−import Test.Tasty (TestTree, testGroup)
10+import Test.Framework (Test, testGroup)
10−import Test.Tasty.HUnit (testCase)
11+import Test.Framework.Providers.HUnit (testCase)
11−import qualified Test.Tasty.HUnit as H
12+import qualified Test.HUnit as H
12
13
13
14
14--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
15import Hakyll.Core.Compiler
16import Hakyll.Core.Compiler
16−import Hakyll.Core.Identifier
17+import Hakyll.Core.Compiler.Internal
17import Hakyll.Core.Item
18import Hakyll.Core.Item
18import Hakyll.Core.UnixFilter
19import Hakyll.Core.UnixFilter
19import TestSuite.Util
20import TestSuite.Util
20
21
21
22
22--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
23−tests :: TestTree
24+tests :: Test
24tests = testGroup "Hakyll.Core.UnixFilter.Tests"
25tests = testGroup "Hakyll.Core.UnixFilter.Tests"
25 [ testCase "unixFilter rev" unixFilterRev
26 [ testCase "unixFilter rev" unixFilterRev
26 , testCase "unixFilter false" unixFilterFalse
27 , testCase "unixFilter false" unixFilterFalse
27− , testCase "unixFilter error" unixFilterError
28 ]
28 ]
29
29
30−testMarkdown :: Identifier
31−testMarkdown = "russian.md"
32
30
33--------------------------------------------------------------------------------
31--------------------------------------------------------------------------------
34unixFilterRev :: H.Assertion
32unixFilterRev :: H.Assertion
35unixFilterRev = do
33unixFilterRev = do
36 store <- newTestStore
34 store <- newTestStore
37 provider <- newTestProvider store
35 provider <- newTestProvider store
38− output <- testCompilerDone store provider testMarkdown compiler
36+ output <- testCompilerDone store provider "russian.md" compiler
39− expected <- testCompilerDone store provider testMarkdown getResourceString
37+ expected <- testCompilerDone store provider "russian.md" getResourceString
40− rev (itemBody expected) H.@=? lines (itemBody output)
38+ H.assert $ rev (itemBody expected) == lines (itemBody output)
41 cleanTestEnv
39 cleanTestEnv
42 where
40 where
43 compiler = getResourceString >>= withItemBody (unixFilter "rev" [])
41 compiler = getResourceString >>= withItemBody (unixFilter "rev" [])
@@ -49,18 +47,10 @@ unixFilterFalse :: H.Assertion
49unixFilterFalse = do
47unixFilterFalse = do
50 store <- newTestStore
48 store <- newTestStore
51 provider <- newTestProvider store
49 provider <- newTestProvider store
52− testCompilerError store provider testMarkdown compiler "exit code"
50+ result <- testCompiler store provider "russian.md" compiler
51+ H.assert $ case result of
52+ CompilerError es -> any ("exit code" `isInfixOf`) es
53+ _ -> False
53 cleanTestEnv
54 cleanTestEnv
54 where
55 where
55 compiler = getResourceString >>= withItemBody (unixFilter "false" [])
56 compiler = getResourceString >>= withItemBody (unixFilter "false" [])
56−
57−
58−--------------------------------------------------------------------------------
59−unixFilterError :: H.Assertion
60−unixFilterError = do
61− store <- newTestStore
62− provider <- newTestProvider store
63− testCompilerError store provider testMarkdown compiler "option"
64− cleanTestEnv
65− where
66− compiler = getResourceString >>= withItemBody (unixFilter "head" ["-#"])
tests/Hakyll/Core/Util/String/Tests.hs+3−3
@@ -5,8 +5,8 @@ module Hakyll.Core.Util.String.Tests
5
5
6
6
7--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
8−import Test.Tasty (TestTree, testGroup)
8+import Test.Framework (Test, testGroup)
9−import Test.Tasty.HUnit ((@=?))
9+import Test.HUnit ((@=?))
10
10
11
11
12--------------------------------------------------------------------------------
12--------------------------------------------------------------------------------
@@ -15,7 +15,7 @@ import TestSuite.Util
15
15
16
16
17--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
18−tests :: TestTree
18+tests :: Test
19tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
19tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
20 [ fromAssertions "trim"
20 [ fromAssertions "trim"
21 [ "foo" @=? trim " foo\n\t "
21 [ "foo" @=? trim " foo\n\t "
tests/Hakyll/Web/CompressCss/Tests.hsdeleted−64
@@ -1,64 +0,0 @@
1−--------------------------------------------------------------------------------
2−module Hakyll.Web.CompressCss.Tests
3− ( tests
4− ) where
5−
6−
7−--------------------------------------------------------------------------------
8−import Test.Tasty (TestTree, testGroup)
9−import Test.Tasty.HUnit ((@=?))
10−
11−
12−--------------------------------------------------------------------------------
13−import Hakyll.Web.CompressCss
14−import TestSuite.Util
15−
16−
17−--------------------------------------------------------------------------------
18−tests :: TestTree
19−tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
20− [ fromAssertions "compressCss"
21− [
22− -- compress whitespace
23− "something something" @=?
24− compressCss " something \n\t\r something "
25− -- do not compress whitespace in string tokens
26− , "abc \" \t\n\r \" xyz" @=?
27− compressCss "abc \" \t\n\r \" xyz"
28− , "abc ' \t\n\r ' xyz" @=?
29− compressCss "abc ' \t\n\r ' xyz"
30−
31− -- strip comments
32− , "before after" @=? compressCss "before /* abc { } ;; \n\t\r */ after"
33− -- don't strip comments inside string tokens
34− , "before \"/* abc { } ;; \n\t\r */\" after"
35− @=? compressCss "before \"/* abc { } ;; \n\t\r */\" after"
36−
37− -- compress separators
38− , "}" @=? compressCss "; }"
39− , ";{};" @=? compressCss " ; { } ; "
40− , "text," @=? compressCss "text , "
41− , "a>b" @=? compressCss "a > b"
42− , "a+b" @=? compressCss "a + b"
43− , "a!b" @=? compressCss "a ! b"
44− -- compress calc()
45− , "calc(1px + 100%/(5 + 3) - (3px + 2px)*5)" @=? compressCss "calc( 1px + 100% / ( 5 + 3) - calc( 3px + 2px ) * 5 )"
46− -- compress whitespace even after this curly brace
47− , "}" @=? compressCss "; } "
48− -- but do not compress separators inside string tokens
49− , "\" { } ; , \"" @=? compressCss "\" { } ; , \""
50− -- don't compress separators at the start or end of string tokens
51− , "\" }\"" @=? compressCss "\" }\""
52− , "\"{ \"" @=? compressCss "\"{ \""
53− -- don't get irritated by the wrong token delimiter
54− , "\" ' \"" @=? compressCss "\" ' \""
55− , "' \" '" @=? compressCss "' \" '"
56− -- don't compress whitespace in the middle of a string
57− , "abc '{ '" @=? compressCss "abc '{ '"
58− , "abc \"{ \"" @=? compressCss "abc \"{ \""
59− -- compress whitespace after colons (but not before)
60− , "abc :xyz" @=? compressCss "abc : xyz"
61− -- compress multiple semicolons
62− , ";" @=? compressCss ";;;;;;;"
63− ]
64− ]
tests/Hakyll/Web/Html/RelativizeUrls/Tests.hs+3−4
@@ -6,9 +6,8 @@ module Hakyll.Web.Html.RelativizeUrls.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Test.Tasty (TestTree, testGroup)
9+import Test.Framework (Test, testGroup)
10−import Test.Tasty.HUnit ((@=?))
10+import Test.HUnit ((@=?))
11−
12
11
13--------------------------------------------------------------------------------
12--------------------------------------------------------------------------------
14import Hakyll.Web.Html.RelativizeUrls
13import Hakyll.Web.Html.RelativizeUrls
@@ -16,7 +15,7 @@ import TestSuite.Util
16
15
17
16
18--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
19−tests :: TestTree
18+tests :: Test
20tests = testGroup "Hakyll.Web.Html.RelativizeUrls.Tests" $
19tests = testGroup "Hakyll.Web.Html.RelativizeUrls.Tests" $
21 fromAssertions "relativizeUrls"
20 fromAssertions "relativizeUrls"
22 [ "<a href=\"../foo\">bar</a>" @=?
21 [ "<a href=\"../foo\">bar</a>" @=?
tests/Hakyll/Web/Html/Tests.hs+9−9
@@ -5,9 +5,9 @@ module Hakyll.Web.Html.Tests
5
5
6
6
7--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
8−import Data.Char (toUpper)
8+import Data.Char (toUpper)
9−import Test.Tasty (TestTree, testGroup)
9+import Test.Framework (Test, testGroup)
10−import Test.Tasty.HUnit ((@=?))
10+import Test.HUnit (assert, (@=?))
11
11
12
12
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
@@ -16,7 +16,7 @@ import TestSuite.Util
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
19−tests :: TestTree
19+tests :: Test
20tests = testGroup "Hakyll.Web.Html.Tests" $ concat
20tests = testGroup "Hakyll.Web.Html.Tests" $ concat
21 [ fromAssertions "demoteHeaders"
21 [ fromAssertions "demoteHeaders"
22 [ "<h2>A h1 title</h2>" @=?
22 [ "<h2>A h1 title</h2>" @=?
@@ -64,11 +64,11 @@ tests = testGroup "Hakyll.Web.Html.Tests" $ concat
64 ]
64 ]
65
65
66 , fromAssertions "isExternal"
66 , fromAssertions "isExternal"
67− [ True @=? isExternal "http://reddit.com"
67+ [ assert (isExternal "http://reddit.com")
68− , True @=? isExternal "https://mail.google.com"
68+ , assert (isExternal "https://mail.google.com")
69− , True @=? isExternal "//ajax.googleapis.com"
69+ , assert (isExternal "//ajax.googleapis.com")
70− , False @=? isExternal "../header.png"
70+ , assert (not (isExternal "../header.png"))
71− , False @=? isExternal "/foo/index.html"
71+ , assert (not (isExternal "/foo/index.html"))
72 ]
72 ]
73
73
74 , fromAssertions "stripTags"
74 , fromAssertions "stripTags"
tests/Hakyll/Web/Pandoc/FileType/Tests.hs+3−3
@@ -6,8 +6,8 @@ module Hakyll.Web.Pandoc.FileType.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Test.Tasty (TestTree, testGroup)
9+import Test.Framework (Test, testGroup)
10−import Test.Tasty.HUnit ((@=?))
10+import Test.HUnit ((@=?))
11
11
12
12
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
@@ -16,7 +16,7 @@ import TestSuite.Util
16
16
17
17
18--------------------------------------------------------------------------------
18--------------------------------------------------------------------------------
19−tests :: TestTree
19+tests :: Test
20tests = testGroup "Hakyll.Web.Pandoc.FileType.Tests" $
20tests = testGroup "Hakyll.Web.Pandoc.FileType.Tests" $
21 fromAssertions "fileType"
21 fromAssertions "fileType"
22 [ Markdown @=? fileType "index.md"
22 [ Markdown @=? fileType "index.md"
tests/Hakyll/Web/Template/Context/Tests.hs+8−44
@@ -6,26 +6,24 @@ module Hakyll.Web.Template.Context.Tests
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Test.Tasty (TestTree, testGroup)
9+import Test.Framework (Test, testGroup)
10+import Test.Framework.Providers.HUnit (testCase)
10−import Test.Tasty.HUnit (Assertion, testCase, (@=?))
11+import Test.HUnit (Assertion, (@=?))
11
12
12
13
13--------------------------------------------------------------------------------
14--------------------------------------------------------------------------------
14import Hakyll.Core.Compiler
15import Hakyll.Core.Compiler
15import Hakyll.Core.Identifier
16import Hakyll.Core.Identifier
16−import Hakyll.Core.Item
17import Hakyll.Core.Provider
17import Hakyll.Core.Provider
18−import Hakyll.Core.Store (Store)
18+import Hakyll.Core.Store (Store)
19import Hakyll.Web.Template.Context
19import Hakyll.Web.Template.Context
20−import Hakyll.Web.Template.Internal
21import TestSuite.Util
20import TestSuite.Util
22
21
23
22
24--------------------------------------------------------------------------------
23--------------------------------------------------------------------------------
25−tests :: TestTree
24+tests :: Test
26−tests = testGroup "Hakyll.Web.Template.Context.Tests"
25+tests = testGroup "Hakyll.Core.Template.Context.Tests"
27 [ testCase "testDateField" testDateField
26 [ testCase "testDateField" testDateField
28− , testCase "testOuerLoopContextAccess" testOuerLoopContextAccess
29 ]
27 ]
30
28
31
29
@@ -44,15 +42,6 @@ testDateField = do
44 dateField "date" "%B %e, %Y"
42 dateField "date" "%B %e, %Y"
45 date2 @=? "August 26, 2010"
43 date2 @=? "August 26, 2010"
46
44
47− date3 <- testContextDone store provider
48− "posts/2018-09-26.md" "date" $
49− dateField "date" "%B %e, %Y"
50− date3 @=? "September 26, 2018"
51−
52− date4 <- testContextDone store provider
53− "posts/2019/05/10/tomorrow.md" "date" $
54− dateField "date" "%B %e, %Y"
55− date4 @=? "May 10, 2019"
56 cleanTestEnv
45 cleanTestEnv
57
46
58
47
@@ -65,31 +54,6 @@ testContextDone store provider identifier key context =
65 cf <- unContext context key [] item
54 cf <- unContext context key [] item
66 case cf of
55 case cf of
67 StringField str -> return str
56 StringField str -> return str
68− _ -> error $
57+ ListField _ _ -> error $
69 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
58 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
70− "expected StringField"
59+ "Didn't expect ListField"
71−
72−--------------------------------------------------------------------------------
73−
74−testOuerLoopContextAccess :: Assertion
75−testOuerLoopContextAccess = do
76− store <- newTestStore
77− provider <- newTestProvider store
78− test store provider ctx "baz"
79− test store provider (ctx' <> ctx) "not baz"
80− test store provider (ctx <> ctx') "baz"
81−
82− cleanTestEnv
83− where
84− tpl = readTemplate "$for(foo)$$for(bar)$$qux$$endfor$$endfor$"
85− ctx = mconcat [
86− field "qux" $ const $ return "baz"
87− , listField "foo" (listField "bar" mempty $ return [mockItem])
88− $ return [mockItem]
89− ]
90− ctx' = field "qux" $ const $ return "not baz"
91− mockItem = Item "" ()
92− test store provider context str = do
93− str' <- testCompilerDone store provider ""
94− $ applyTemplate tpl context mockItem
95− str @=? itemBody str'
tests/Hakyll/Web/Template/Tests.hs+25−93
@@ -1,23 +1,22 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
4module Hakyll.Web.Template.Tests
3module Hakyll.Web.Template.Tests
5 ( tests
4 ( tests
6 ) where
5 ) where
7
6
8
7
9--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9+import Data.Monoid (mconcat)
10−import Test.Tasty (TestTree, testGroup)
10+import Test.Framework (Test, testGroup)
11−import Test.Tasty.HUnit (Assertion, assertBool, testCase,
11+import Test.Framework.Providers.HUnit (testCase)
12− (@=?), (@?=))
12+import Test.HUnit (Assertion, (@=?), (@?=))
13
13
14−import Data.Either (isLeft)
15
14
16--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
17import Hakyll.Core.Compiler
16import Hakyll.Core.Compiler
18−import Hakyll.Core.Identifier
19import Hakyll.Core.Item
17import Hakyll.Core.Item
20import Hakyll.Core.Provider
18import Hakyll.Core.Provider
19+import Hakyll.Web.Pandoc
21import Hakyll.Web.Template
20import Hakyll.Web.Template
22import Hakyll.Web.Template.Context
21import Hakyll.Web.Template.Context
23import Hakyll.Web.Template.Internal
22import Hakyll.Web.Template.Internal
@@ -26,83 +25,35 @@ import TestSuite.Util
26
25
27
26
28--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
29−tests :: TestTree
28+tests :: Test
30−tests = testGroup "Hakyll.Web.Template.Tests" $ concat
29+tests = testGroup "Hakyll.Core.Template.Tests" $ concat
31− [ [ testCase "case01" $ test ("template.html.out", "template.html", "example.md")
30+ [ [ testCase "case01" case01
32− , testCase "case02" $ test ("strip.html.out", "strip.html", "example.md")
33− , testCase "case03" $ test ("just-meta.html.out", "just-meta.html", "example.md")
34 , testCase "applyJoinTemplateList" testApplyJoinTemplateList
31 , testCase "applyJoinTemplateList" testApplyJoinTemplateList
35 ]
32 ]
36
33
37− , fromAssertions "parseTemplate"
34+ , fromAssertions "readTemplate"
38− [ Right [Chunk "Hello ", Expr (Call "guest" [])]
35+ [ Template [Chunk "Hello ", Expr (Call "guest" [])]
39− @=? parse "Hello $guest()$"
36+ @=? readTemplate "Hello $guest()$"
37+ , Template
40− , Right [If (Call "a" [StringLiteral "bar"]) [Chunk "foo"] Nothing]
38+ [If (Call "a" [StringLiteral "bar"])
39+ (Template [Chunk "foo"])
40+ Nothing]
41− @=? parse "$if(a(\"bar\"))$foo$endif$"
41+ @=? readTemplate "$if(a(\"bar\"))$foo$endif$"
42− -- 'If' trim check.
43− , Right [ TrimL
44− , If (Ident (TemplateKey "body"))
45− [ TrimR
46− , Chunk "\n"
47− , Expr (Ident (TemplateKey "body"))
48− , Chunk "\n"
49− , TrimL
50− ]
51− (Just [ TrimR
52− , Chunk "\n"
53− , Expr (Ident (TemplateKey "body"))
54− , Chunk "\n"
55− , TrimL
56− ])
57− , TrimR
58− ]
59− @=? parse "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
60− -- 'For' trim check.
61− , Right [ TrimL
62− , For (Ident (TemplateKey "authors"))
63− [TrimR, Chunk "\n body \n", TrimL]
64− Nothing
65− , TrimR
66− ]
67− @=? parse "$-for(authors)-$\n body \n$-endfor-$"
68− -- 'Partial' trim check.
69− , Right [ TrimL
70− , Partial (StringLiteral "path")
71− , TrimR
72− ]
73− @=? parse "$-partial(\"path\")-$"
74− -- 'Expr' trim check.
75− , Right [ TrimL
76− , Expr (Ident (TemplateKey "foo"))
77− , TrimR
78− ]
79− @=? parse "$-foo-$"
80− -- fail on incomplete template.
81− , assertBool "did not yield error" $ isLeft $
82− parse "a$b"
83− -- fail on mismatched template syntax.
84− , assertBool "did not fail to parse" $ isLeft $
85− parse "$for(xs)$\n <p>foo</p>\n$endif$"
86 ]
42 ]
87−
88− , [testCase "embeddedTemplate" testEmbeddedTemplate]
89 ]
43 ]
90− where
91− parse = parseTemplateElemsFile ""
92
44
93
45
94--------------------------------------------------------------------------------
46--------------------------------------------------------------------------------
95−test :: (Identifier, Identifier, Identifier) -> Assertion
47+case01 :: Assertion
96−test (outf, tplf, itemf) = do
48+case01 = do
97 store <- newTestStore
49 store <- newTestStore
98 provider <- newTestProvider store
50 provider <- newTestProvider store
99
51
100− out <- resourceString provider outf
52+ out <- resourceString provider "template.html.out"
101− tpl <- testCompilerDone store provider tplf templateBodyCompiler
53+ tpl <- testCompilerDone store provider "template.html" $
54+ templateBodyCompiler
102− item <- testCompilerDone store provider itemf $
55+ item <- testCompilerDone store provider "example.md" $
103− getResourceBody
104− >>= renderParagraphs
105− >>= applyTemplate (itemBody tpl) testContext
56+ pandocCompiler >>= applyTemplate (itemBody tpl) testContext
106
57
107 out @=? itemBody item
58 out @=? itemBody item
108 cleanTestEnv
59 cleanTestEnv
@@ -118,6 +69,7 @@ testContext = mconcat
118 return [n1, n2]
69 return [n1, n2]
119 , functionField "rev" $ \args _ -> return $ unwords $ map reverse args
70 , functionField "rev" $ \args _ -> return $ unwords $ map reverse args
120 ]
71 ]
72+ where
121
73
122
74
123--------------------------------------------------------------------------------
75--------------------------------------------------------------------------------
@@ -125,8 +77,6 @@ testApplyJoinTemplateList :: Assertion
125testApplyJoinTemplateList = do
77testApplyJoinTemplateList = do
126 store <- newTestStore
78 store <- newTestStore
127 provider <- newTestProvider store
79 provider <- newTestProvider store
128− tpl <- testCompilerDone store provider "tpl" $
129− compileTemplateItem (Item "tpl" "<b>$body$</b>")
130 str <- testCompilerDone store provider "item3" $
80 str <- testCompilerDone store provider "item3" $
131 applyJoinTemplateList ", " tpl defaultContext [i1, i2]
81 applyJoinTemplateList ", " tpl defaultContext [i1, i2]
132
82
@@ -135,22 +85,4 @@ testApplyJoinTemplateList = do
135 where
85 where
136 i1 = Item "item1" "Hello"
86 i1 = Item "item1" "Hello"
137 i2 = Item "item2" "World"
87 i2 = Item "item2" "World"
138−
88+ tpl = Template [Chunk "<b>", Expr (Ident "body"), Chunk "</b>"]
139−
140−--------------------------------------------------------------------------------
141−embeddedTemplate :: Template
142−embeddedTemplate = $(embedTemplate "tests/data/embed.html")
143−
144−--------------------------------------------------------------------------------
145−testEmbeddedTemplate :: Assertion
146−testEmbeddedTemplate = do
147− store <- newTestStore
148− provider <- newTestProvider store
149− str <- testCompilerDone store provider "item3" $
150− applyTemplate embeddedTemplate defaultContext item
151−
152− itemBody str @?= "<p>Hello, world</p>\n"
153− cleanTestEnv
154− where
155− item = Item "item1" "Hello, world"
156−
tests/TestSuite.hs+2−11
@@ -1,12 +1,11 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−{-# LANGUAGE CPP #-}
3module Main
2module Main
4 ( main
3 ( main
5 ) where
4 ) where
6
5
7
6
8--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
9−import Test.Tasty (defaultMain, testGroup)
8+import Test.Framework (defaultMain)
10
9
11
10
12--------------------------------------------------------------------------------
11--------------------------------------------------------------------------------
@@ -20,20 +19,16 @@ import qualified Hakyll.Core.Runtime.Tests
20import qualified Hakyll.Core.Store.Tests
19import qualified Hakyll.Core.Store.Tests
21import qualified Hakyll.Core.UnixFilter.Tests
20import qualified Hakyll.Core.UnixFilter.Tests
22import qualified Hakyll.Core.Util.String.Tests
21import qualified Hakyll.Core.Util.String.Tests
23−import qualified Hakyll.Web.CompressCss.Tests
24import qualified Hakyll.Web.Html.RelativizeUrls.Tests
22import qualified Hakyll.Web.Html.RelativizeUrls.Tests
25import qualified Hakyll.Web.Html.Tests
23import qualified Hakyll.Web.Html.Tests
26−#ifdef USE_PANDOC
27import qualified Hakyll.Web.Pandoc.FileType.Tests
24import qualified Hakyll.Web.Pandoc.FileType.Tests
28−#endif
29import qualified Hakyll.Web.Template.Context.Tests
25import qualified Hakyll.Web.Template.Context.Tests
30import qualified Hakyll.Web.Template.Tests
26import qualified Hakyll.Web.Template.Tests
31−import qualified Hakyll.Web.Tags.Tests
32
27
33
28
34--------------------------------------------------------------------------------
29--------------------------------------------------------------------------------
35main :: IO ()
30main :: IO ()
36−main = defaultMain $ testGroup "Hakyll"
31+main = defaultMain
37 [ Hakyll.Core.Dependencies.Tests.tests
32 [ Hakyll.Core.Dependencies.Tests.tests
38 , Hakyll.Core.Identifier.Tests.tests
33 , Hakyll.Core.Identifier.Tests.tests
39 , Hakyll.Core.Provider.Metadata.Tests.tests
34 , Hakyll.Core.Provider.Metadata.Tests.tests
@@ -44,13 +39,9 @@ main = defaultMain $ testGroup "Hakyll"
44 , Hakyll.Core.Store.Tests.tests
39 , Hakyll.Core.Store.Tests.tests
45 , Hakyll.Core.UnixFilter.Tests.tests
40 , Hakyll.Core.UnixFilter.Tests.tests
46 , Hakyll.Core.Util.String.Tests.tests
41 , Hakyll.Core.Util.String.Tests.tests
47− , Hakyll.Web.CompressCss.Tests.tests
48 , Hakyll.Web.Html.RelativizeUrls.Tests.tests
42 , Hakyll.Web.Html.RelativizeUrls.Tests.tests
49 , Hakyll.Web.Html.Tests.tests
43 , Hakyll.Web.Html.Tests.tests
50−#ifdef USE_PANDOC
51 , Hakyll.Web.Pandoc.FileType.Tests.tests
44 , Hakyll.Web.Pandoc.FileType.Tests.tests
52−#endif
53− , Hakyll.Web.Tags.Tests.tests
54 , Hakyll.Web.Template.Context.Tests.tests
45 , Hakyll.Web.Template.Context.Tests.tests
55 , Hakyll.Web.Template.Tests.tests
46 , Hakyll.Web.Template.Tests.tests
56 ]
47 ]
tests/TestSuite/Util.hs+15−36
@@ -6,38 +6,36 @@ module TestSuite.Util
6 , newTestProvider
6 , newTestProvider
7 , testCompiler
7 , testCompiler
8 , testCompilerDone
8 , testCompilerDone
9− , testCompilerError
10 , testConfiguration
9 , testConfiguration
11 , cleanTestEnv
10 , cleanTestEnv
12− , renderParagraphs
13 ) where
11 ) where
14
12
15
13
16--------------------------------------------------------------------------------
14--------------------------------------------------------------------------------
17−import Data.List (intercalate, isInfixOf)
15+import Data.List (intercalate)
18−import Data.Monoid (mempty)
16+import Data.Monoid (mempty)
19−import qualified Data.Set as S
17+import qualified Data.Set as S
20−import Test.Tasty
18+import Test.Framework
21−import Test.Tasty.HUnit
19+import Test.Framework.Providers.HUnit
20+import Test.HUnit hiding (Test)
22−import Text.Printf (printf)
21+import Text.Printf (printf)
23
22
24
23
25--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
26import Hakyll.Core.Compiler.Internal
25import Hakyll.Core.Compiler.Internal
27import Hakyll.Core.Configuration
26import Hakyll.Core.Configuration
28import Hakyll.Core.Identifier
27import Hakyll.Core.Identifier
29−import qualified Hakyll.Core.Logger as Logger
28+import qualified Hakyll.Core.Logger as Logger
30import Hakyll.Core.Provider
29import Hakyll.Core.Provider
31−import Hakyll.Core.Store (Store)
30+import Hakyll.Core.Store (Store)
32−import qualified Hakyll.Core.Store as Store
31+import qualified Hakyll.Core.Store as Store
33import Hakyll.Core.Util.File
32import Hakyll.Core.Util.File
34−import Hakyll.Core.Item
35
33
36
34
37--------------------------------------------------------------------------------
35--------------------------------------------------------------------------------
38fromAssertions :: String -- ^ Name
36fromAssertions :: String -- ^ Name
39 -> [Assertion] -- ^ Cases
37 -> [Assertion] -- ^ Cases
40− -> [TestTree] -- ^ Result tests
38+ -> [Test] -- ^ Result tests
41fromAssertions name =
39fromAssertions name =
42 zipWith testCase [printf "[%2d] %s" n name | n <- [1 :: Int ..]]
40 zipWith testCase [printf "[%2d] %s" n name | n <- [1 :: Int ..]]
43
41
@@ -79,23 +77,14 @@ testCompilerDone store provider underlying compiler = do
79 result <- testCompiler store provider underlying compiler
77 result <- testCompiler store provider underlying compiler
80 case result of
78 case result of
81 CompilerDone x _ -> return x
79 CompilerDone x _ -> return x
82− CompilerError e -> fail $
80+ CompilerError e -> error $
83 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
81 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
84− " threw: " ++ intercalate "; " (compilerErrorMessages e)
82+ " threw: " ++ intercalate "; " e
85− CompilerRequire i _ -> fail $
83+ CompilerRequire i _ -> error $
86 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
84 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
87 " requires: " ++ show i
85 " requires: " ++ show i
88− CompilerSnapshot _ _ -> fail
89− "TestSuite.Util.testCompilerDone: unexpected CompilerSnapshot"
90
86
91−testCompilerError :: Store -> Provider -> Identifier -> Compiler a -> String -> IO ()
87+
92−testCompilerError store provider underlying compiler expectedMessage = do
93− result <- testCompiler store provider underlying compiler
94− case result of
95− CompilerError e ->
96− any (expectedMessage `isInfixOf`) (compilerErrorMessages e) @?
97− "Expecting '" ++ expectedMessage ++ "' error"
98− _ -> assertFailure "Expecting CompilerError"
99
88
100--------------------------------------------------------------------------------
89--------------------------------------------------------------------------------
101testConfiguration :: Configuration
90testConfiguration :: Configuration
@@ -113,13 +102,3 @@ cleanTestEnv = do
113 removeDirectory $ destinationDirectory testConfiguration
102 removeDirectory $ destinationDirectory testConfiguration
114 removeDirectory $ storeDirectory testConfiguration
103 removeDirectory $ storeDirectory testConfiguration
115 removeDirectory $ tmpDirectory testConfiguration
104 removeDirectory $ tmpDirectory testConfiguration
116−
117−
118−--------------------------------------------------------------------------------
119−-- | like 'Hakyll.Web.Pandoc.renderPandoc'
120−-- | but allowing to test without the @usePandoc@ flag
121−renderParagraphs :: Item String -> Compiler (Item String)
122−renderParagraphs = withItemBody (return
123− . intercalate "\n" -- no trailing line
124− . map (("<p>"++) . (++"</p>"))
125− . lines)
tests/data/embed.htmldeleted−1
@@ -1 +0,0 @@
1−<p>$body$</p>
tests/data/example.md.metadata−2
@@ -1,5 +1,3 @@
1external: External data
1external: External data
2date: 2012-10-22 14:35:24
2date: 2012-10-22 14:35:24
3subblog: food
3subblog: food
4−intfield: 42
5−numfield: 3.14
tests/data/just-meta.htmldeleted−7
@@ -1,7 +0,0 @@
1−<pre>
2−external: {$external$}
3−date: {$date$}
4−subblog: {$subblog$}
5−intfield: {$intfield$}
6−numfield: {$numfield$}
7−</pre>
tests/data/just-meta.html.outdeleted−7
@@ -1,7 +0,0 @@
1−<pre>
2−external: {External data}
3−date: {2012-10-22 14:35:24}
4−subblog: {food}
5−intfield: {42}
6−numfield: {3.14}
7−</pre>
tests/data/partial-helper.htmldeleted−3
@@ -1,3 +0,0 @@
1−<p>This is an included partial.</p>
2−
3−$body$
tests/data/partial.htmldeleted−3
@@ -1,3 +0,0 @@
1−<p>This is a file that includes a partial.</p>
2−
3−$partial("partial-helper.html")$
tests/data/partial.html.outdeleted−7
@@ -1,7 +0,0 @@
1−<p>This is a file that includes a partial.</p>
2−
3−<p>This is an included partial.</p>
4−
5−This is an example.
6−
7−
tests/data/posts/2018-09-26.mddeleted−1
@@ -1 +0,0 @@
1−Something happened today.
tests/data/posts/2019/05/10/tomorrow.mddeleted−1
@@ -1 +0,0 @@
1−This day hasn't happened yet (as of writing this).
tests/data/strip.htmldeleted−34
@@ -1,34 +0,0 @@
1−<div>
2− I'm so rich I have $$3.
3−
4− $rev("foo")$
5− $-rev(rev("foo"))$
6−
7− $if(body)-$
8− I have body
9− $else-$
10− or no
11− $-endif-$
12−
13− $if(unbound)$
14− should not be printed
15− $endif$
16−
17− $-if(body)-$
18− should be printed
19− $-endif$
20−
21− <ul>
22− $for(authors)-$
23− <li>$name$</li>
24− $endfor-$
25− </ul>
26−
27− $for(authors)-$
28− $name-$
29− $sep$,
30− $-endfor$
31−
32− $body$
33−</div>
34−
tests/data/strip.html.outdeleted−18
@@ -1,18 +0,0 @@
1−<div>
2− I'm so rich I have $3.
3−
4− ooffoo
5−
6− I have body
7− should be printed
8−
9− <ul>
10− <li>Jan</li>
11− <li>Piet</li>
12− </ul>
13−
14− Jan,Piet
15−
16− <p>This is an example.</p>
17−</div>
18−
web/css/syntax.css+18−61
@@ -1,61 +1,18 @@
1−a.sourceLine { display: inline-block; line-height: 1.25; }
1+/* Generated by pandoc. */
2−a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
2+table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre
3−a.sourceLine:empty { height: 1.2em; }
3+ { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
4−.sourceCode { overflow: visible; }
4+td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
5−code.sourceCode { white-space: pre; position: relative; }
5+td.sourceCode { padding-left: 5px; }
6−div.sourceCode { margin: 1em 0; }
7−pre.sourceCode { margin: 0; }
8−@media screen {
9−div.sourceCode { overflow: auto; }
10−}
11−@media print {
12−code.sourceCode { white-space: pre-wrap; }
13−a.sourceLine { text-indent: -1em; padding-left: 1em; }
14−}
15−pre.numberSource a.sourceLine
16− { position: relative; left: -4em; }
17−pre.numberSource a.sourceLine::before
18− { content: attr(title);
19− position: relative; left: -1em; text-align: right; vertical-align: baseline;
20− border: none; pointer-events: all; display: inline-block;
21− -webkit-touch-callout: none; -webkit-user-select: none;
22− -khtml-user-select: none; -moz-user-select: none;
23− -ms-user-select: none; user-select: none;
24− padding: 0 4px; width: 4em;
25− color: #aaaaaa;
26− }
27−pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
28−div.sourceCode
29− { }
30−@media screen {
31−a.sourceLine::before { text-decoration: underline; }
32−}
33−code span.al { color: #ff0000; font-weight: bold; } /* Alert */
34−code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
35−code span.at { color: #7d9029; } /* Attribute */
36−code span.bn { color: #40a070; } /* BaseN */
37−code span.bu { } /* BuiltIn */
38−code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
6+.sourceCode span.kw { color: #007020; font-weight: bold; }
39−code span.ch { color: #4070a0; } /* Char */
40−code span.cn { color: #880000; } /* Constant */
41−code span.co { color: #60a0b0; font-style: italic; } /* Comment */
42−code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
43−code span.do { color: #ba2121; font-style: italic; } /* Documentation */
44−code span.dt { color: #902000; } /* DataType */
7+.sourceCode span.dt { color: #902000; }
45−code span.dv { color: #40a070; } /* DecVal */
8+.sourceCode span.dv { color: #40a070; }
46−code span.er { color: #ff0000; font-weight: bold; } /* Error */
9+.sourceCode span.bn { color: #40a070; }
47−code span.ex { } /* Extension */
48−code span.fl { color: #40a070; } /* Float */
10+.sourceCode span.fl { color: #40a070; }
11+.sourceCode span.ch { color: #4070a0; }
12+.sourceCode span.st { color: #4070a0; }
13+.sourceCode span.co { color: #60a0b0; font-style: italic; }
14+.sourceCode span.ot { color: #007020; }
15+.sourceCode span.al { color: red; font-weight: bold; }
49−code span.fu { color: #06287e; } /* Function */
16+.sourceCode span.fu { color: #06287e; }
50−code span.im { } /* Import */
17+.sourceCode span.re { }
51−code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
18+.sourceCode span.er { color: red; font-weight: bold; }
52−code span.kw { color: #007020; font-weight: bold; } /* Keyword */
53−code span.op { color: #666666; } /* Operator */
54−code span.ot { color: #007020; } /* Other */
55−code span.pp { color: #bc7a00; } /* Preprocessor */
56−code span.sc { color: #4070a0; } /* SpecialChar */
57−code span.ss { color: #bb6688; } /* SpecialString */
58−code span.st { color: #4070a0; } /* String */
59−code span.va { color: #19177c; } /* Variable */
60−code span.vs { color: #4070a0; } /* VerbatimString */
61−code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
web/examples.markdown+30−66
@@ -20,8 +20,6 @@ directly with the default Hakyll site.
20 [source](https://github.com/jaspervdj/jaspervdj)
20 [source](https://github.com/jaspervdj/jaspervdj)
21- <http://www.imagination-land.org/>,
21- <http://www.imagination-land.org/>,
22 [source](https://github.com/Keruspe/blog/)
22 [source](https://github.com/Keruspe/blog/)
23−- <https://bananasandlenses.net/>,
24− [source](https://github.com/denisshevchenko/bananasandlenses)
25- <http://blog.clement.delafargue.name/>,
23- <http://blog.clement.delafargue.name/>,
26 [source](https://github.com/divarvel/blog)
24 [source](https://github.com/divarvel/blog)
27- <http://bneijt.nl>,
25- <http://bneijt.nl>,
@@ -36,6 +34,8 @@ directly with the default Hakyll site.
36 [source](https://github.com/dannysu/hakyll-blog)
34 [source](https://github.com/dannysu/hakyll-blog)
37- <http://meta.plasm.us/>,
35- <http://meta.plasm.us/>,
38 [source](https://github.com/travisbrown/metaplasm)
36 [source](https://github.com/travisbrown/metaplasm)
37+- <http://www.web2day-nantes.org/>,
38+ [source](https://github.com/CompanyCampus/web2day2013)
39- <http://workforpizza.com/>,
39- <http://workforpizza.com/>,
40 [source](https://github.com/irneh/workforpizza)
40 [source](https://github.com/irneh/workforpizza)
41- <http://poleiro.info/>,
41- <http://poleiro.info/>,
@@ -45,7 +45,9 @@ directly with the default Hakyll site.
45- <http://www.regisfoucault.com/>,
45- <http://www.regisfoucault.com/>,
46 [source](https://github.com/regisfoucault/blog)
46 [source](https://github.com/regisfoucault/blog)
47- <http://www.chaoxuprime.com/>,
47- <http://www.chaoxuprime.com/>,
48− [source](https://github.com/chaoxu/chaoxu.github.io/tree/develop)
48+ [source](https://github.com/Mgccl/blog)
49+- <https://benjeffrey.com/>,
50+ [source](https://github.com/jeffbr13/benjeffrey.com)
49- <http://www.skybluetrades.net/>,
51- <http://www.skybluetrades.net/>,
50 [source](https://github.com/ian-ross/blog)
52 [source](https://github.com/ian-ross/blog)
51- <http://chromaticleaves.com/>,
53- <http://chromaticleaves.com/>,
@@ -56,22 +58,32 @@ directly with the default Hakyll site.
56 [source](https://github.com/blaenk/blaenk.github.io)
58 [source](https://github.com/blaenk/blaenk.github.io)
57- <https://xinitrc.de/>,
59- <https://xinitrc.de/>,
58 [source](https://github.com/xinitrc/xinitrc.de)
60 [source](https://github.com/xinitrc/xinitrc.de)
61+- <http://blog.darkfox.id.au/>,
62+ [source](http://hub.darcs.net/DarkFox/DarkFox-blog)
59- <http://nickcharlton.net/>,
63- <http://nickcharlton.net/>,
60 [source](https://github.com/nickcharlton/nickcharlton.net)
64 [source](https://github.com/nickcharlton/nickcharlton.net)
61- <http://scr.stunts.hu/>,
65- <http://scr.stunts.hu/>,
62 [literate source](http://scr.stunts.hu/hakyll.html)
66 [literate source](http://scr.stunts.hu/hakyll.html)
63- <http://www.eanalytica.com/>,
67- <http://www.eanalytica.com/>,
64 [literate source](http://www.eanalytica.com/site/)
68 [literate source](http://www.eanalytica.com/site/)
69+- <http://dikmax.name/>,
70+ [source](https://github.com/dikmax/dikmax.name)
65- <http://cse.iitk.ac.in/users/ppk>,
71- <http://cse.iitk.ac.in/users/ppk>,
66 [source](https://github.com/piyush-kurur-pages/website)
72 [source](https://github.com/piyush-kurur-pages/website)
67- <http://web.engr.oregonstate.edu/~walkiner/>,
73- <http://web.engr.oregonstate.edu/~walkiner/>,
68 [source](https://github.com/walkie/WebPage)
74 [source](https://github.com/walkie/WebPage)
69- <http://techblog.rosedu.org/>,
75- <http://techblog.rosedu.org/>,
70 [source](https://github.com/rosedu/techblog)
76 [source](https://github.com/rosedu/techblog)
77+- <http://abizern.org>,
78+ [source](https://github.com/Abizern/hblog)
71- <http://freizl.github.io>,
79- <http://freizl.github.io>,
72 [source](https://github.com/freizl/freizl.github.com/tree/master/build)
80 [source](https://github.com/freizl/freizl.github.com/tree/master/build)
81+- <http://covariant.me>,
82+ [source](http://hub.darcs.net/co-dan/website)
73- <http://www.gwern.net/>,
83- <http://www.gwern.net/>,
74 [source](https://github.com/gwern/gwern.net)
84 [source](https://github.com/gwern/gwern.net)
85+- <http://www.rohanjain.in/>,
86+ [source](https://github.com/crodjer/rohanjain.in)
75- <http://www.corentindupont.info/>,
87- <http://www.corentindupont.info/>,
76 [source](https://github.com/cdupont/CorentinDupont-WebPage)
88 [source](https://github.com/cdupont/CorentinDupont-WebPage)
77- <http://jelv.is>,
89- <http://jelv.is>,
@@ -80,8 +92,8 @@ directly with the default Hakyll site.
80 [source](https://github.com/plaimi/www)
92 [source](https://github.com/plaimi/www)
81- <http://duplode.github.io/>,
93- <http://duplode.github.io/>,
82 [source](https://github.com/duplode/duplode.github.io/tree/sources)
94 [source](https://github.com/duplode/duplode.github.io/tree/sources)
83−- <http://tzemanovic.github.io/>,
95+- <http://maseek.codes>,
84− [source](https://github.com/tzemanovic/tzemanovic)
96+ [source](https://github.com/maseek/maseek-codes)
85- <http://listx.github.io>,
97- <http://listx.github.io>,
86 [source](https://github.com/listx/listx_blog)
98 [source](https://github.com/listx/listx_blog)
87- <http://kyle.marek-spartz.org>,
99- <http://kyle.marek-spartz.org>,
@@ -92,20 +104,26 @@ directly with the default Hakyll site.
92 [source](https://github.com/rbros/reichertbrothers.com)
104 [source](https://github.com/rbros/reichertbrothers.com)
93- <http://alemedeiros.sdf.org>,
105- <http://alemedeiros.sdf.org>,
94 [source](https://github.com/alemedeiros/homepage)
106 [source](https://github.com/alemedeiros/homepage)
107+- <https://ruudvanasseldonk.com/>,
108+ [source](https://github.com/ruud-v-a/ruudvanasseldonk.com)
95- <http://www.haskell.mn>,
109- <http://www.haskell.mn>,
96 [source](https://github.com/HaskellMN/www.haskell.mn)
110 [source](https://github.com/HaskellMN/www.haskell.mn)
97- <https://axiomatic.neophilus.net/>,
111- <https://axiomatic.neophilus.net/>,
98 [source](https://github.com/Libbum/AxiomaticSemantics)
112 [source](https://github.com/Libbum/AxiomaticSemantics)
99−- [https://tesser.org/](http://web.archive.org/web/20161022221713/https://tesser.org/),
113+- <https://tesser.org/>,
100 [source](https://github.com/fractalcat/tesser.org)
114 [source](https://github.com/fractalcat/tesser.org)
101−- <https://weien.io/>,
115+- <https://wei2912.github.io/>,
102−  [source](https://github.com/wei2912/blog-src)
116+ [source](https://github.com/wei2912/blog_src)
103- <http://www.metasepi.org/>,
117- <http://www.metasepi.org/>,
104 [source](https://github.com/metasepi/metasepi-website)
118 [source](https://github.com/metasepi/metasepi-website)
105- <http://gisli.hamstur.is/>,
119- <http://gisli.hamstur.is/>,
106 [source](https://github.com/gislik/gisli.hamstur.is)
120 [source](https://github.com/gislik/gisli.hamstur.is)
107- <http://blog.ssanj.net/>,
121- <http://blog.ssanj.net/>,
108 [source](https://github.com/ssanj/babyloncandle)
122 [source](https://github.com/ssanj/babyloncandle)
123+- <https://rockymadden.com/>,
124+ [source](https://github.com/rockymadden/rockymadden-web)
125+- <http://blog.dshevchenko.biz/>,
126+ [source](https://github.com/denisshevchenko/blog)
109- <http://ruhaskell.org/>,
127- <http://ruhaskell.org/>,
110 [source](https://github.com/ruHaskell/ruhaskell)
128 [source](https://github.com/ruHaskell/ruhaskell)
111- <http://www.haskell.od.ua/>,
129- <http://www.haskell.od.ua/>,
@@ -126,64 +144,8 @@ directly with the default Hakyll site.
126 [source](https://github.com/ismailmustafa/ismailmustafa.github.io/tree/hakyll)
144 [source](https://github.com/ismailmustafa/ismailmustafa.github.io/tree/hakyll)
127- <http://lettier.github.io/>,
145- <http://lettier.github.io/>,
128 [source](https://github.com/lettier/lettier.github.io)
146 [source](https://github.com/lettier/lettier.github.io)
129−- <http://raindev.io>,
147+- <http://jozefg.bitbucket.org/>,
130− [source](https://github.com/raindev/raindev.github.io)
131−- <http://hal2016.haskell.org/>,
132− [source](https://github.com/nomeata/hal2016-website/)
148+ [source](https://github.com/jozefg/blog)
133−- <http://acehack.org/>,
134− [source](https://github.com/sakshamsharma/acehack/)
135−- <https://nek0.eu/>,
136− [source](https://github.com/nek0/nek0.eu)
137−- <http://static-dust.klpn.se/>,
138− [source](https://github.com/klpn/static-dust)
139−- <http://www.kuznero.com/>,
140− [source](https://github.com/kuznero/kuznero.github.io)
141−- <http://nicolerauch.de/>,
142− [source](https://github.com/NicoleRauch/BusinessWebsite)
143−- <http://johnduhamel.io/>,
144− [source](https://github.com/jjduhamel/blog)
145−- <http://alexanderlobov.ru/>,
146− [source](https://github.com/alexanderlobov/homepage)
147−- <http://www.rosanbo.com/>,
148− [source](https://github.com/polo2ro/blog)
149−- <http://limansky.me/>,
150− [source](https://github.com/limansky/limansky_me)
151−- <http://rahul.nu/>,
152− [source](https://github.com/rp/rp.github.io/tree/dev)
153−- <http://haskanything.com/>,
154− [source](https://github.com/beerendlauwers/HaskAnything)
155−- <https://anler.me/>,
156− [source](https://github.com/anler/anler.me)
157−- <http://argumatronic.com/>,
158− [source](https://gitlab.com/GinBaby/argumatronic/tree/master)
159−- <http://sillybytes.net/>,
160− [source](https://github.com/sillybytes/sillybytes)
161−- <https://falconpilot.github.io/>,
162− [source](https://github.com/FalconPilot/falconpilot.github.io)
163−- <http://spyhop.cafe/>,
164− [source](https://github.com/thunky-monk/spyhop-cafe)
165−- <https://bendo.github.io/>,
166− [source](https://github.com/bendo/bendo.github.io)
167−- <http://adarsh.cc/>,
168− [source](https://github.com/adarshp/adarsh.cc)
169−- <http://0a.io>,
170− [source](https://github.com/arrchyy/0a.io)
171−- <https://nasy.moe/>,
172− [source](https://github.com/nasyxx/NasyMoe)
173−- <http://uniprocess.org/>,
174− [source](https://gitlab.com/uniprocess/uniprocess.org)
175−- <https://regularflolloping.com/>,
176− [source](https://github.com/techieAgnostic/rf)
177−- <http://enter-haken.github.io/>,
178− [source](https://github.com/enter-haken/blog)
179−- <https://modular.blind.guru/>,
180− [source](https://github.com/mlang/eurorack-metadata)
181−- <http://www.jonashietala.se/>,
182− [source](https://github.com/treeman/jonashietala)
183−- <https://abhinavsarkar.net/>,
184− [source](https://github.com/abhin4v/abhin4v.github.io)
185−- <https://dailyreadingnotes.com/>,
186− [source](https://github.com/hackeryarn/daily-reading-notes)
187
149
188## Hakyll 3.X
150## Hakyll 3.X
189
151
@@ -211,5 +173,7 @@ directly with the default Hakyll site.
211 [source](http://gitorious.org/shakthimaan-blog)
173 [source](http://gitorious.org/shakthimaan-blog)
212- <http://www.alfredodinapoli.com/>,
174- <http://www.alfredodinapoli.com/>,
213 [source](https://github.com/CharlesStain/alfredodinapoli.com)
175 [source](https://github.com/CharlesStain/alfredodinapoli.com)
176+- <http://datahackermd.com>,
177+ [source](http://github.com/akshayjshah/datahackermd)
214- <http://michaelxavier.net>,
178- <http://michaelxavier.net>,
215 [source](https://github.com/michaelxavier/michaelxavier.net)
179 [source](https://github.com/michaelxavier/michaelxavier.net)
web/libraries.markdown−1
@@ -18,4 +18,3 @@ Here is a list of the ones I know of (I would be happy to hear about others).
18 a conversion tool from other blog engines to Hakyll.
18 a conversion tool from other blog engines to Hakyll.
19- [hakyll-elm](https://hackage.haskell.org/package/hakyll-elm),
19- [hakyll-elm](https://hackage.haskell.org/package/hakyll-elm),
20 Hakyll wrapper for the Elm compiler.
20 Hakyll wrapper for the Elm compiler.
21−- [hakyll-sass](http://hackage.haskell.org/package/hakyll-sass), a compiler for SASS templates.
CHANGELOG.md → web/releases.markdownrenamed−230
@@ -4,236 +4,6 @@ title: Releases
4
4
5# Releases
5# Releases
6
6
7−## Hakyll 4.13.0.0 (2019-08-30)
8−
9−- Improved documentation in many places (contribution by Bergi)
10−- Significantly improve error messages when reading and applying templates
11− (contribution by Bergi)
12− * `empty` and `fail` for `Compiler` now fail without or with a message,
13− allowing for much better debug output
14− * `renderFeed`, `renderRssWithTemplates` and `renderAtomWithTemplates` now
15− take `Template` rather than `String` arguments
16−- Add option to specify date in directory structure,e.g.
17− `posts/2019/05/10/tomorrow.md` (contribution by Taeer Bar-Ya)
18−- Bump QuickCheck to 2.13
19−
20−## Hakyll 4.12.5.2 (2019-05-09)
21−
22−- Bump pandoc to 2.7
23−- Add `srcset` to the list of URL attributes (contribution by c50a326)
24−- Expose `getCategory` in `Hakyll.Web.Tags` (contribution by Ng Wei En)
25−- Fix issue where `published` overwrites the user's context (contribution by
26− ncaq)
27−
28−## Hakyll 4.12.5.1 (2019-02-03)
29−
30−- Bump pandoc to 2.6
31−- Bump pandoc-citeproc to 0.16
32−
33−## Hakyll 4.12.5.0 (2019-01-12)
34−
35−- Update dependencies (contribution by Hexirp):
36− * Bump containers to 0.6
37− * Bump yaml to 0.11
38− * Bump pandoc to 2.5
39− * Bump pandoc-citeproc to 0.15
40− * Bump tasty to 1.2
41−- Correct assertion in unixFilterError test
42− (contribution by Jim McStanton)
43−- Add renderRssWithTemplates, renderAtomWithTemplates
44− (contribution by Abhinav Sarkar)
45−- Speed up hashing in cache (contribution by 0xd34df00d)
46−- Update type of fromFilePath to use FilePath instead of String
47− (contribution by Jim McStanton)
48−- Drop extension when parsing dates in filepaths (contribution by
49− Gabriel Aumala)
50−
51−## Hakyll 4.12.4.0 (2018-08-13)
52−
53−- Bump yaml to 0.10
54−- Bump file-embed to 0.0.11
55−- Bump QuickCheck to 2.12
56−- Use makeRelativeToProject with embedFile for stack ghci (contribution by
57− Michael Sloan)
58−
59−## Hakyll 4.12.3.0 (2018-05-29)
60−
61−- Bump tasty to 1.1
62−- Bump fsnotify to 0.3
63−
64−## Hakyll 4.12.2.0
65−
66−- Bump pandoc to 2.2
67−- Fix path resolution in Pandoc.Biblio (contribution by knih)
68−
69−## Hakyll 4.12.1.0
70−
71−- Fix hakyll-init on older GHC versions
72−- Make the Pandoc dependency optional
73−
74−## Hakyll 4.12.0.1
75−
76−- Bump resourcet to 1.2 in test section
77−
78−## Hakyll 4.12.0.0
79−
80−- Add Semigroup instances for existing Monoids (contribution by
81− Christian Barcenas)
82−- Fix issue with CPP and comment containing `/*`
83−- Add `withTagList` (contribution by Oleg Grenrus)
84−- Improve CSS compression (contribution by Bergi)
85−- Bump pandoc-citeproc to 0.14
86−- Bump resourcet to 1.2
87−- Bump time to 1.9
88−- Bump http-types to 0.12
89−- Bump http-conduit to 2.3
90−- Bump tasty-quickcheck to 0.10
91−
92−## Hakyll 4.11.0.0
93−
94−- Bump binary to 0.9
95−- Bump pandoc to 2.1
96−- Bump pandoc-citeproc to 0.13
97−- Bump http-types to 0.11
98−- Bump QuickCheck to 2.11
99−- Bump tasty to 1.0
100−- Bump tasty-hunit to 0.10
101−- Remove system-filepath dependency
102−- Embed feed templates rather than using data-files (contribution by Roman
103− Kuznetsov)
104−- Fix pthread link error on GHC-8.2.2 (contribution by Shinya Yamaguchi)
105−- Extend capture with Regex handling (contribution by frederik-h)
106−
107−## Hakyll 4.10.0.0
108−
109−- Bump Pandoc to 2.0 (contribution by Vaibhav Sagar)
110−- Fix compression of calc() in CSS (contribution by Krzysztof Jurewicz)
111−- Make unixFilter output stderr when failing (contribution by Nick Boultbee)
112−- Export Check type from `Hakyll.Commands` (contribution by Futtetennista)
113−- Add overwritten files check to `hakyll-init` (contribution by Ilya Murzinov)
114−- Expose & document `hakyllWithExitCodeAndArgs`, `Options`, and `Command`
115− (contribution by Michael Walker)
116−- Add check for non-overlapping redirects (contribution by gwern)
117−- Fix early exit when calling check as a library
118−
119−## Hakyll 4.9.8.0
120−
121−- Bump pandoc-citeproc to 0.10.5
122−- Bump optparse-applicative to 0.14
123−- Bump QuickCheck to 2.10
124−- Bump tasty-quickcheck to 0.9
125−- Restructure .cabal to avoid redundant compilation (contribution by
126− Christopher League)
127−
128−## Hakyll 4.9.7.0
129−
130−- Fix compilation trouble with `Options.Applicative`
131−- Some small CSS compression improvements (contribution by Nicole Rauch)
132−
133−## Hakyll 4.9.6.0
134−
135−- Tighten dependency on `pandoc-citeproc` (contribution by Mikhail Glushenkov)
136−- Enable using a custom parser for command line arguments (contribution by
137− Alberto)
138−- Update examples to semantic HTML (contribution by Elie Génard)
139−- Better error for `cached` on non-existing file
140−- Provide an `$allPages$` key when doing pagination
141−- Preserve file metadata in `copyFileCompiler` (contribution by frederik-h)
142−
143−## Hakyll 4.9.5.1
144−
145−- Bump blaze-html dependency to 0.9
146−- Bump blaze-markup dependency to 0.8
147−- Bump process dependency to 1.5
148−
149−## Hakyll 4.9.5.0
150−
151−- Fix compilation issue with `Hakyll.Check` if `checkExternal` is disabled
152− (Fix by Magnus Therning)
153−
154−## Hakyll 4.9.4.0
155−
156−- Make `./site check` concurrent
157−- Bump directory dependency to 1.3
158−- Bump time dependency to 1.7
159−- Bump vector dependency to 0.12
160−
161−## Hakyll 4.9.3.0
162−
163−- Add a `Hakyll.Web.Redirect` module (contribution by gwern)
164−- Expose `Hakyll.Commands`
165−- Fix the exit code behaviour of `./site check`
166−
167−## Hakyll 4.9.2.0
168−
169−- Fix integer fields in YAML metadata (Fix by Nikolaos S. Papaspyrou)
170−- Bump pandoc dependency to 1.19
171−
172−## Hakyll 4.9.1.0
173−
174−- Allow optparse-applicative 0.13, QuickCheck 2.9, and pandoc 1.18
175− (contributions by Chris Wong and Felix Yan)
176−- Fix extra test files for packaging source files (contribution by Julien
177− Langlois)
178−
179−## Hakyll 4.9.0.0
180−
181−This release switches over some dependencies to alternatives, in order to clean
182−up some stuff and build on a wider variety of setups (stack/cabal).
183−
184−- Move from `test-framework` to `tasty`
185−- Fix feed generator when item contains CDATA (contribution by Yann Esposito)
186−- Fix CompressCSS to not modify string constants (contribution by Nicole Rauch)
187−- Fix YAML dependency issue (contribution by Jens Peterson)
188−- Move from `cmdargs` to `optparse-applicative` (contribution by sk3r)
189−- Allow for trimming whitespace in templates (contribution by Sam Davis)
190−- Improve error messages for template parsing (contribution by Lorenzo
191− Tabacchini)
192−- Improvements to the installation instructions (contribution by Thomas Koch)
193−- Move from `snap` to `warp` for preview servier (contribution by Arguggi)
194−- Fix error in CompressCSS (contribution by Luca Molteni)
195−- Move example from XHTML to HTML5 (contribution by Peter Doherty)
196−- Make errors in check less verbose (contribution by Jan Tojnar)
197−- Work on building with GHC 8.0.1 (contribution by Rohan Jain)
198−
199−## Hakyll 4.8.3.2
200−
201−This release is compatible with GHC 8.0.1, although `previewServer` might not
202−work yet on some setups.
203−
204−- Allow data-default 0.7, pandoc-citeproc 0.10, and tagsoup 0.14 (contributions
205− by Paul van der Walt and Felix Yan)
206−- Allow binary 0.8, process 1.4, time 1.6 (contribution by Sergei Trofimovich)
207−- Fix issue with `.metadata` file reading
208−
209−## Hakyll 4.8.3.1
210−
211−- Bump scientific dependency to 0.3.4
212−
213−## Hakyll 4.8.3.0
214−
215−- Fix another compilation issue wrt. orphan `Show` instance from regex-tdfa
216− (contribution by Sergei Trofimovich)
217−
218−## Hakyll 4.8.2.0
219−
220−- Fix compilation issue wrt. orphan `Show` instance from regex-tdfa
221−
222−## Hakyll 4.8.1.0
223−
224−- Fix compilation on windows
225−
226−## Hakyll 4.8.0.1
227−
228−- Fix issue with test suite
229−
230−## Hakyll 4.8.0.0
231−
232−- Support full YAML in page metadata
233−- Bump data-default dependency to 0.6
234−- Add snippet field for literal includes in templates (contribution by Nicolas
235− Mattia)
236−
237## Hakyll 4.7.5.2
7## Hakyll 4.7.5.2
238
8
239- Bump pandoc dependency to 1.17 (contribution by Felix Yan)
9- Bump pandoc dependency to 1.17 (contribution by Felix Yan)
web/site.hs+39−25
@@ -1,23 +1,19 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−import Control.Arrow (second)
3+import Control.Arrow (second)
4−import Control.Monad (filterM, forM_)
4+import Control.Monad (forM_)
5+import Data.Char (isDigit)
5−import Data.List (isPrefixOf, sortBy)
6+import Data.List (isPrefixOf, sortBy)
6−import Data.Monoid ((<>))
7+import Data.Monoid ((<>))
7−import Data.Ord (comparing)
8+import Data.Ord (comparing)
8import Hakyll
9import Hakyll
9−import System.Directory (copyFile)
10−import System.FilePath (dropTrailingPathSeparator, splitPath)
10+import System.FilePath (dropTrailingPathSeparator, splitPath)
11import Text.Pandoc
11import Text.Pandoc
12
12
13
13
14--------------------------------------------------------------------------------
14--------------------------------------------------------------------------------
15main :: IO ()
15main :: IO ()
16main = hakyllWith config $ do
16main = hakyllWith config $ do
17− -- Copy CHANGELOG.md here.
18− preprocess $ copyFile "../CHANGELOG.md" "releases.markdown"
19−
20− -- CSS
21 match "css/*" $ do
17 match "css/*" $ do
22 route idRoute
18 route idRoute
23 compile compressCssCompiler
19 compile compressCssCompiler
@@ -56,11 +52,17 @@ main = hakyllWith config $ do
56 create ["tutorials.html"] $ do
52 create ["tutorials.html"] $ do
57 route idRoute
53 route idRoute
58 compile $ do
54 compile $ do
59− ctx <- tutorialsCtx <$>
55+ tuts <-
60 sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
56 sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
57+
58+ let tutorialsCtx =
59+ constField "title" "Tutorials" `mappend`
60+ listField "tutorials" tutorialCtx (return tuts) `mappend`
61+ defaultContext
62+
61 makeItem ""
63 makeItem ""
62− >>= loadAndApplyTemplate "templates/tutorials.html" ctx
64+ >>= loadAndApplyTemplate "templates/tutorials.html" tutorialsCtx
63− >>= loadAndApplyTemplate "templates/default.html" ctx
65+ >>= loadAndApplyTemplate "templates/default.html" tutorialsCtx
64 >>= relativizeUrls
66 >>= relativizeUrls
65
67
66 -- Templates
68 -- Templates
@@ -68,7 +70,8 @@ main = hakyllWith config $ do
68 where
70 where
69 withToc = defaultHakyllWriterOptions
71 withToc = defaultHakyllWriterOptions
70 { writerTableOfContents = True
72 { writerTableOfContents = True
71− , writerTemplate = Just "$toc$\n$body$"
73+ , writerTemplate = "$toc$\n$body$"
74+ , writerStandalone = True
72 }
75 }
73
76
74
77
@@ -101,17 +104,28 @@ hackage url
101 reverse $ splitPath url
104 reverse $ splitPath url
102
105
103
106
107+--------------------------------------------------------------------------------
108+data TutorialType = SeriesTutorial | ArticlesTutorial | ExternalTutorial
109+ deriving (Eq)
110+
111+
104--------------------------------------------------------------------------------
112--------------------------------------------------------------------------------
105-- | Partition tutorials into tutorial series, other articles, external articles
113-- | Partition tutorials into tutorial series, other articles, external articles
106−tutorialsCtx :: [Item String] -> Context String
114+tutorialCtx :: Context String
107−tutorialsCtx tuts =
115+tutorialCtx =
108− constField "title" "Tutorials" <>
116+ field "isSeries" (isTutorialType SeriesTutorial) <>
109− listField "main" defaultContext (ofType "main") <>
117+ field "isArticle" (isTutorialType ArticlesTutorial) <>
110− listField "articles" defaultContext (ofType "article") <>
118+ field "isExternal" (isTutorialType ExternalTutorial) <>
111− listField "externals" defaultContext (ofType "external") <>
112− listField "robertwpearce" defaultContext (ofType "robertwpearce") <>
113 defaultContext
119 defaultContext
114 where
120 where
115− ofType ty = filterM (\item -> do
121+ getTutorialType item = do
116− mbType <- getMetadataField (itemIdentifier item) "type"
122+ mbExternal <- getMetadataField (itemIdentifier item) "external"
117− return $ Just ty == mbType) tuts
123+ return $ case mbExternal of
124+ Just _ -> ExternalTutorial
125+ _ -> case splitPath (toFilePath $ itemIdentifier item) of
126+ [_, (x : _)] -> if isDigit x then SeriesTutorial else ArticlesTutorial
127+ _ -> ArticlesTutorial
128+
129+ isTutorialType ty0 item = do
130+ ty1 <- getTutorialType item
131+ if ty0 == ty1 then return "yes" else fail "no"
web/templates/default.html+6−1
@@ -35,7 +35,12 @@
35 <a href="/tutorials/faq.html">faq</a>
35 <a href="/tutorials/faq.html">faq</a>
36 <a href="/examples.html">examples</a>
36 <a href="/examples.html">examples</a>
37 <a href="/releases.html">releases</a>
37 <a href="/releases.html">releases</a>
38+
39+ <!-- Flattr button -->
40+ <h1>Donate</h1>
38− <a href="https://jaspervdj.be/contact.html#donate" target="_blank">donate</a>
41+ <a href="https://flattr.com/thing/291889/Hakyll" target="_blank">
42+ <img src="https://api.flattr.com/button/flattr-badge-large.png"
43+ alt="Flattr this" title="Flattr this" border="0" /></a>
39 </div>
44 </div>
40
45
41 <div id="content">
46 <div id="content">
web/templates/tutorials.html+18−24
@@ -1,19 +1,23 @@
1<h1>Tutorials about Hakyll</h1>
1<h1>Tutorials about Hakyll</h1>
2<h2 id="series">Tutorial series</h2>
2<h2 id="series">Tutorial series</h2>
3<ul>
3<ul>
4− $for(main)$
4+ $for(tutorials)$
5+ $if(isSeries)$
5− <li>
6+ <li>
6− <a href="$url$">$title$</a>
7+ <a href="$url$">$title$</a>
7− </li>
8+ </li>
9+ $endif$
8 $endfor$
10 $endfor$
9</ul>
11</ul>
10<h2 id="articles">Other articles</h2>
12<h2 id="articles">Other articles</h2>
11<p>In no particular order:</p>
13<p>In no particular order:</p>
12<ul>
14<ul>
13− $for(articles)$
15+ $for(tutorials)$
16+ $if(isArticle)$
14− <li>
17+ <li>
15− <a href="$url$">$title$</a> by <em>$author$</em>
18+ <a href="$url$">$title$</a> by <em>$author$</em>
16− </li>
19+ </li>
20+ $endif$
17 $endfor$
21 $endfor$
18</ul>
22</ul>
19<h2 id="external-articles">External articles</h2>
23<h2 id="external-articles">External articles</h2>
@@ -24,22 +28,12 @@
24</p>
28</p>
25<p>In no particular order:</p>
29<p>In no particular order:</p>
26<ul>
30<ul>
27− $for(externals)$
31+ $for(tutorials)$
32+ $if(isExternal)$
28− <li>
33+ <li>
29− <a href="$url$">$title$</a> by <em>$author$</em>
34+ <a href="$url$">$title$</a> by <em>$author$</em>
30− </li>
35+ </li>
31− $endfor$
36+ $endif$
32−</ul>
33−<h2 id="robertwpearce">Robert Pearce's series</h2>
34−<p>
35− <a href="https://robertwpearce.com/">Robert Pearce</a> has been writing an
36− excellent tutorial-style series on Hakyll as well. You can find those here:
37−</p>
38−<ul>
39− $for(robertwpearce)$
40− <li>
41− <a href="$url$">$title$</a>
42− </li>
43 $endfor$
37 $endfor$
44</ul>
38</ul>
45<p>
39<p>
web/tutorials/01-installation.markdown+2−6
@@ -1,7 +1,6 @@
1---
1---
2title: Installation
2title: Installation
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Installation
6Installation
@@ -18,8 +17,6 @@ different distributions. For installation from source (i.e. via Hackage),
18Linux distro packages:
17Linux distro packages:
19
18
20- [Debian unstable](http://packages.debian.org/source/sid/haskell-hakyll)
19- [Debian unstable](http://packages.debian.org/source/sid/haskell-hakyll)
21−- [Fedora](https://apps.fedoraproject.org/packages/ghc-hakyll)
22−- [Nix](https://nixos.org/nixos/packages.html#hakyll): `$ nix-env -i hakyll`
23
20
24Building the example site
21Building the example site
25-------------------------
22-------------------------
@@ -28,20 +25,19 @@ Apart from the main Hakyll library, the cabal package also provides you with an
28executable `hakyll-init` to create an example site. This is an easy way to get
25executable `hakyll-init` to create an example site. This is an easy way to get
29started:
26started:
30
27
31− $ stack exec hakyll-init my-site
28+ $ hakyll-init my-site
32
29
33This creates a folder `my-site` in the current directory, with some example
30This creates a folder `my-site` in the current directory, with some example
34content and a generic configuration.
31content and a generic configuration.
35
32
36If `hakyll-init` is not found, you should make sure your stack bin path
33If `hakyll-init` is not found, you should make sure your stack bin path
37(usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local
34(usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local
38−bin path by running `stack path --local-bin`.
35+bin path by running `stack path --local-bin-path`.
39
36
40The file `site.hs` holds the configuration of your site, as an executable
37The file `site.hs` holds the configuration of your site, as an executable
41haskell program. We can compile and run it like this:
38haskell program. We can compile and run it like this:
42
39
43 $ cd my-site
40 $ cd my-site
44− $ stack init # creates stack.yaml file based on my-site.cabal
45 $ stack build
41 $ stack build
46 $ stack exec site build
42 $ stack exec site build
47
43
web/tutorials/02-basics.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: The basics
2title: The basics
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Building and cleaning
6Building and cleaning
web/tutorials/03-rules-routes-compilers.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Rules, routes and compilers
2title: Rules, routes and compilers
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Basic rules
6Basic rules
web/tutorials/04-compilers.markdown+3−18
@@ -1,7 +1,6 @@
1---
1---
2title: 'More on compilers: load, and templates'
2title: 'More on compilers: load, and templates'
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Loading items
6Loading items
@@ -93,7 +92,7 @@ And `$title$` like this:
93titleContext :: Context a
92titleContext :: Context a
94titleContext = field "title" $ \item -> do
93titleContext = field "title" $ \item -> do
95 metadata <- getMetadata (itemIdentifier item)
94 metadata <- getMetadata (itemIdentifier item)
96− return $ fromMaybe "No title" $ lookupString "title" metadata
95+ return $ fromMaybe "No title" $ M.lookup "title" metadata
97```
96```
98
97
99And compose them using the `Monoid` instance:
98And compose them using the `Monoid` instance:
@@ -131,7 +130,7 @@ postCtx =
131### Loading and applying templates
130### Loading and applying templates
132
131
133Now we know about templates, context and how to load arbitrary items. This gives
132Now we know about templates, context and how to load arbitrary items. This gives
134−us enough background information in order to understand how you can apply a
133+us enough background information in order to understand you can apply a
135template:
134template:
136
135
137```haskell
136```haskell
@@ -152,7 +151,7 @@ Control flow in templates
152-------------------------
151-------------------------
153
152
154Sometimes string interpolation does not suffice, and you want a little more
153Sometimes string interpolation does not suffice, and you want a little more
155−control over how your templates are laid out. Hakyll provides a few control
154+control over how your templates are layed out. Hakyll provides a few control
156structures for this. The syntax for these structures was based on the syntax
155structures for this. The syntax for these structures was based on the syntax
157used in pandoc templates, since Hakyll already has tight integration with
156used in pandoc templates, since Hakyll already has tight integration with
158pandoc.
157pandoc.
@@ -237,20 +236,6 @@ This uses the `$for(foo)$` construct. This construct allows you loop over a
237list, in this case, `$posts$`. Inside the body of this for loop, all fields
236list, in this case, `$posts$`. Inside the body of this for loop, all fields
238refer to the current post, e.g.: `$url$`, `$title$` and `$date$`.
237refer to the current post, e.g.: `$url$`, `$title$` and `$date$`.
239
238
240−You can also add a simple separator with the special `$sep$` field.
241−Everything between `$sep$` and `$endfor$` will be regarded as a separator
242−that will only be shown if there is more than one item in the list.
243−
244−```html
245−<ul>
246− $for(posts)$
247− $x$
248− $sep$,
249− $endfor$
250−</ul>
251−```
252−
253−
254Of course, $posts$ does not magically appear. We have to specify this in
239Of course, $posts$ does not magically appear. We have to specify this in
255`site.hs`. Let's look at how `archive.html` is generated:
240`site.hs`. Let's look at how `archive.html` is generated:
256
241
web/tutorials/05-snapshots-feeds.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Snapshots, and how to produce an RSS/Atom feed
2title: Snapshots, and how to produce an RSS/Atom feed
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Basic feed configuration
6Basic feed configuration
web/tutorials/06-versions.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Producing multiple versions of a single file
2title: Producing multiple versions of a single file
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: main
5---
4---
6
5
7Basics
6Basics
web/tutorials/a-guide-to-the-hakyll-module-zoo.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: A Guide to the Hakyll Module Zoo
2title: A Guide to the Hakyll Module Zoo
3author: Brent Yorgey
3author: Brent Yorgey
4−type: article
5---
4---
6
5
7The hakyll package [contains a bewildering array](/reference/) of modules, and
6The hakyll package [contains a bewildering array](/reference/) of modules, and
web/tutorials/external-add-tags-to-your-hakyll-blog.md+1−1
@@ -2,5 +2,5 @@
2title: Add tags to your Hakyll blog
2title: Add tags to your Hakyll blog
3author: Javran Cheng
3author: Javran Cheng
4url: https://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html
4url: https://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html
5−type: external
5+external: true
6---
6---
web/tutorials/external-blogger-port.mddeleted−6
@@ -1,6 +0,0 @@
1−---
2−title: Port an existing Blogger blog to Hakyll
3−author: Daniel Campoverde
4−url: 'http://www.sillybytes.net/posts/from_blogger_to_hakyll.html'
5−type: external
6−---
web/tutorials/external-cassius-template.mddeleted−6
@@ -1,6 +0,0 @@
1−---
2−title: Using Cassius templating with Hakyll
3−author: Daniel Campoverde
4−url: 'http://www.sillybytes.net/posts/using_hakyll_with_cassius.html'
5−type: external
6−---
web/tutorials/external-clean-urls-with-hakyll.md+1−1
@@ -2,5 +2,5 @@
2title: Clean URLs with Hakyll
2title: Clean URLs with Hakyll
3author: Rohan Jain
3author: Rohan Jain
4url: http://www.rohanjain.in/hakyll-clean-urls/
4url: http://www.rohanjain.in/hakyll-clean-urls/
5−type: external
5+external: true
6---
6---
web/tutorials/external-deploying-with-widely.md+1−1
@@ -2,5 +2,5 @@
2title: Deploying with Widely
2title: Deploying with Widely
3author: Kyle Marek-Spartz
3author: Kyle Marek-Spartz
4url: http://kyle.marek-spartz.org/posts/2013-12-09-widely-and-hakyll.html
4url: http://kyle.marek-spartz.org/posts/2013-12-09-widely-and-hakyll.html
5−type: external
5+external: true
6---
6---
web/tutorials/external-external-code-inclusion.mddeleted−6
@@ -1,6 +0,0 @@
1−---
2−title: 'External code inclusion with Hakyll'
3−author: 'Tobias Pleyer'
4−url: 'http://blog.tpleyer.de/posts/2019-04-21-external-code-inclusion-with-hakyll.html'
5−type: external
6−---
web/tutorials/external-functionfield.md+1−1
@@ -2,5 +2,5 @@
2title: Hakyll's functionField
2title: Hakyll's functionField
3author: Beerend Lauwers
3author: Beerend Lauwers
4url: http://beerendlauwers.be/posts/2015-09-21-hakylls-functionfield.html
4url: http://beerendlauwers.be/posts/2015-09-21-hakylls-functionfield.html
5−type: external
5+external: true
6---
6---
web/tutorials/external-github-pages-circle-ci.mddeleted−6
@@ -1,6 +0,0 @@
1−---
2−title: Create a GitHub page with Hakyll and CircleCI
3−author: Juan Pedro Villa
4−url: https://www.stackbuilders.com/news/dr-hakyll-create-a-github-page-with-hakyll-and-circleci
5−type: external
6−---
web/tutorials/external-inlining-and-compressing-css.md+1−1
@@ -2,5 +2,5 @@
2title: Inlining and compressing CSS
2title: Inlining and compressing CSS
3author: Kyle Marek-Spartz
3author: Kyle Marek-Spartz
4url: http://kyle.marek-spartz.org/posts/2014-12-09-hakyll-css-template-compiler.html
4url: http://kyle.marek-spartz.org/posts/2014-12-09-hakyll-css-template-compiler.html
5−type: external
5+external: true
6---
6---
web/tutorials/faq.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: FAQ
2title: FAQ
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: article
5---
4---
6
5
7## "hGetContents: invalid argument" or "commitBuffer: invalid argument"
6## "hGetContents: invalid argument" or "commitBuffer: invalid argument"
web/tutorials/github-pages-tutorial.md+3−10
@@ -1,7 +1,6 @@
1---
1---
2title: Using Hakyll with GitHub Pages
2title: Using Hakyll with GitHub Pages
3author: Erik Stevenson
3author: Erik Stevenson
4−type: article
5---
4---
6
5
7## Introduction
6## Introduction
@@ -87,7 +86,7 @@ stack exec myblog build
87Update the local list of remote branches to ensure we're able to checkout the branch we want in the next step.
86Update the local list of remote branches to ensure we're able to checkout the branch we want in the next step.
88
87
89```
88```
90−git fetch --all
89+git fetch -all
91```
90```
92
91
93Switch to the `master` branch.
92Switch to the `master` branch.
@@ -143,7 +142,7 @@ stack exec myblog clean
143stack exec myblog build
142stack exec myblog build
144
143
145# Get previous files
144# Get previous files
146−git fetch --all
145+git fetch -all
147git checkout -b master --track origin/master
146git checkout -b master --track origin/master
148
147
149# Overwrite existing files with new files
148# Overwrite existing files with new files
@@ -169,13 +168,7 @@ git stash pop
169Earlier it was mentioned a flaw is that deleted files will persist in the published site until deleted manually. This is easily overcome by using `rsync` instead of `cp`.
168Earlier it was mentioned a flaw is that deleted files will persist in the published site until deleted manually. This is easily overcome by using `rsync` instead of `cp`.
170
169
171```
170```
172−rsync -a --filter='P _site/' \
171+rsync -a --filter='P _site/' --delete-excluded _site/ .
173− --filter='P _cache/' \
174− --filter='P .git/' \
175− --filter='P .gitignore' \
176− --filter='P .stack-work' \
177− --delete-excluded \
178− _site/ .
179```
172```
180
173
181The only drawback this approach has is the requirement that *every* file in your site "go through" Hakyll. Fortunately, in many cases this is not an issue.
174The only drawback this approach has is the requirement that *every* file in your site "go through" Hakyll. Fortunately, in many cases this is not an issue.
web/tutorials/hakyll-3-to-hakyll4-migration-guide.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Hakyll 3 to Hakyll 4 migration guide
2title: Hakyll 3 to Hakyll 4 migration guide
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: article
5---
4---
6
5
7Introduction
6Introduction
web/tutorials/robertwpearce-01-setup-and-initial-customization.htmldeleted−5
@@ -1,5 +0,0 @@
1−---
2−title: 'Pt. 1: Setup & Initial Customization'
3−url: 'https://robertwpearce.com/hakyll-pt-1-setup-and-initial-customization.html'
4−type: robertwpearce
5−---
web/tutorials/robertwpearce-02-generating-a-sitemap-xml-file.htmldeleted−5
@@ -1,5 +0,0 @@
1−---
2−title: 'Pt. 2: Generating a Sitemap XML File'
3−url: 'https://robertwpearce.com/hakyll-pt-2-generating-a-sitemap-xml-file.html'
4−type: robertwpearce
5−---
web/tutorials/robertwpearce-03-generating-rss-and-atom-xml-feeds.htmldeleted−5
@@ -1,5 +0,0 @@
1−---
2−title: 'Pt. 3: Generating RSS and Atom XML Feeds'
3−url: 'https://robertwpearce.com/hakyll-pt-3-generating-rss-and-atom-xml-feeds.html'
4−type: robertwpearce
5−---
web/tutorials/robertwpearce-04-copying-static-files-for-your-build.htmldeleted−5
@@ -1,5 +0,0 @@
1−---
2−title: 'Pt. 4: Copying Static Files For Your Build'
3−url: 'https://robertwpearce.com/hakyll-pt-4-copying-static-files-for-your-build.html'
4−type: robertwpearce
5−---
web/tutorials/robertwpearce-05-generating-custom-post-filenames-from-a-title-slug.htmldeleted−5
@@ -1,5 +0,0 @@
1−---
2−title: 'Pt. 5 – Generating Custom Post Filenames From a Title Slug'
3−url: 'https://robertwpearce.com/hakyll-pt-5-generating-custom-post-filenames-from-a-title-slug.html'
4−type: robertwpearce
5−---
web/tutorials/using-clay-with-hakyll.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Using Clay with Hakyll
2title: Using Clay with Hakyll
3author: Jasper Van der Jeugt
3author: Jasper Van der Jeugt
4−type: article
5---
4---
6
5
7[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
6[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
web/tutorials/using-teasers-in-hakyll.markdown−1
@@ -1,7 +1,6 @@
1---
1---
2title: Using teasers in Hakyll
2title: Using teasers in Hakyll
3author: Ivan Veselov
3author: Ivan Veselov
4−type: article
5---
4---
6
5
7## Introduction
6## Introduction