on master help sign in
Rename pageCompiler to pandocCompiler
commite633df17dd72703a541c46d829096dfe40b75e50 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 15 Dec 2012, 18:02 (14 years ago) parent3f42c9c
9 files changed+40−102
data/example/site.hs+2−2 hakyll.cabal−1 src/Hakyll.hs−2 src/Hakyll/Web/Page.hs−92 src/Hakyll/Web/Pandoc.hs+34−1 tests/Hakyll/Core/Rules/Tests.hs+2−2 tests/Hakyll/Web/Template/Tests.hs+2−2 web/tutorials/03-arrows.markdown → web/tutorials/04-arrows.markdown web/tutorials/04-guide.markdown → web/tutorials/05-guide.markdown
data/example/site.hs+2−2
@@ -18,14 +18,14 @@ main = hakyll $ do
1818
1919 match (fromList ["about.rst", "contact.markdown"]) $ do
2020 route $ setExtension "html"
21− compile $ pageCompiler
21+ compile $ pandocCompiler
2222 >>= loadAndApplyTemplate "templates/default.html" defaultContext
2323 >>= relativizeUrls
2424
2525 match "posts/*" $ do
2626 route $ setExtension "html"
2727 compile $ do
28− post <- pageCompiler
28+ post <- pandocCompiler
2929 saveSnapshot "content" post
3030 return post
3131 >>= loadAndApplyTemplate "templates/post.html" postCtx
hakyll.cabal−1
@@ -126,7 +126,6 @@ Library
126126 Hakyll.Main
127127 Hakyll.Web.CompressCss
128128 Hakyll.Web.Feed
129− Hakyll.Web.Page
130129 Hakyll.Web.Pandoc
131130 Hakyll.Web.Pandoc.Biblio
132131 Hakyll.Web.Pandoc.FileType
src/Hakyll.hs−2
@@ -20,7 +20,6 @@ module Hakyll
2020 , module Hakyll.Main
2121 , module Hakyll.Web.CompressCss
2222 , module Hakyll.Web.Feed
23− , module Hakyll.Web.Page
2423 , module Hakyll.Web.Pandoc
2524 , module Hakyll.Web.Pandoc.Biblio
2625 , module Hakyll.Web.Pandoc.FileType
@@ -52,7 +51,6 @@ import Hakyll.Core.Writable.CopyFile
5251import Hakyll.Main
5352import Hakyll.Web.CompressCss
5453import Hakyll.Web.Feed
55−import Hakyll.Web.Page
5654import Hakyll.Web.Pandoc
5755import Hakyll.Web.Pandoc.Biblio
5856import Hakyll.Web.Pandoc.FileType
src/Hakyll/Web/Page.hsdeleted−92
@@ -1,92 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | A page is a key-value mapping, representing a page on your site
3−--
4−-- A page is an important concept in Hakyll. It is a key-value mapping, and has
5−-- one field with an arbitrary type. A 'Page' thus consists of
6−--
7−-- * metadata (of the type @Map String String@);
8−--
9−-- * the actual value (of the type @a@).
10−--
11−-- Usually, the value will be a 'String' as well, and the value will be the body
12−-- of the page.
13−--
14−-- However, this is certainly no restriction. For example, @Page ByteString@
15−-- could be used to represent a binary item (e.g. an image) and some metadata.
16−--
17−-- Pages can be constructed using Haskell, but they are usually parsed from a
18−-- file. The file format for pages is pretty straightforward.
19−--
20−-- > This is a simple page
21−-- > consisting of two lines.
22−--
23−-- This is a valid page with two lines. If we load this in Hakyll, there would
24−-- be no metadata, and the body would be the given text. Let's look at a page
25−-- with some metadata:
26−--
27−-- > ---
28−-- > title: Alice's Adventures in Wonderland
29−-- > author: Lewis Caroll
30−-- > year: 1865
31−-- > ---
32−-- >
33−-- > Chapter I
34−-- > =========
35−-- >
36−-- > Down the Rabbit-Hole
37−-- > --------------------
38−-- >
39−-- > Alice was beginning to get very tired of sitting by her sister on the bank,
40−-- > and of having nothing to do: once or twice she had peeped into the book her
41−-- > sister was reading, but it had no pictures or conversations in it, "and
42−-- > what is the use of a book," thought Alice "without pictures or
43−-- > conversation?"
44−-- >
45−-- > ...
46−--
47−-- As you can see, we construct a metadata header in Hakyll using @---@. Then,
48−-- we simply list all @key: value@ pairs, and end with @---@ again. This page
49−-- contains three metadata fields and a body. The body is given in markdown
50−-- format, which can be easily rendered to HTML by Hakyll, using pandoc.
51−module Hakyll.Web.Page
52− ( pageCompiler
53− , pageCompilerWith
54− , pageCompilerWithPandoc
55− ) where
56−
57−
58−--------------------------------------------------------------------------------
59−import Control.Applicative ((<$>))
60−import Text.Pandoc (Pandoc, ParserState, WriterOptions)
61−
62−
63−--------------------------------------------------------------------------------
64−import Hakyll.Core.Compiler
65−import Hakyll.Core.Item
66−import Hakyll.Web.Pandoc
67−
68−
69−--------------------------------------------------------------------------------
70−-- | Read a page render using pandoc
71−pageCompiler :: Compiler (Item String)
72−pageCompiler =
73− pageCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
74−
75−
76−--------------------------------------------------------------------------------
77−-- | A version of 'pageCompiler' which allows you to specify your own pandoc
78−-- options
79−pageCompilerWith :: ParserState -> WriterOptions -> Compiler (Item String)
80−pageCompilerWith state options = pageCompilerWithPandoc state options id
81−
82−
83−--------------------------------------------------------------------------------
84−-- | An extension of 'pageCompilerWith' which allows you to specify a custom
85−-- pandoc transformation for the content
86−pageCompilerWithPandoc :: ParserState -> WriterOptions
87− -> (Pandoc -> Pandoc)
88− -> Compiler (Item String)
89−pageCompilerWithPandoc state options f = cached cacheName $
90− writePandocWith options . fmap f . readPandocWith state <$> getResourceBody
91− where
92− cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
src/Hakyll/Web/Pandoc.hs+34−1
@@ -1,5 +1,5 @@
11--------------------------------------------------------------------------------
2−-- | Module exporting convenientpandoc bindings
2+-- | Module exporting convenient pandoc bindings
33module Hakyll.Web.Pandoc
44 ( -- * The basic building blocks
55 readPandoc
@@ -9,6 +9,11 @@ module Hakyll.Web.Pandoc
99 , renderPandoc
1010 , renderPandocWith
1111
12+ -- * Derived compilers
13+ , pandocCompiler
14+ , pandocCompilerWith
15+ , pandocCompilerWithTransform
16+
1217 -- * Default options
1318 , defaultHakyllParserState
1419 , defaultHakyllWriterOptions
@@ -16,10 +21,12 @@ module Hakyll.Web.Pandoc
1621
1722
1823--------------------------------------------------------------------------------
24+import Control.Applicative ((<$>))
1925import Text.Pandoc
2026
2127
2228--------------------------------------------------------------------------------
29+import Hakyll.Core.Compiler
2330import Hakyll.Core.Item
2431import Hakyll.Web.Pandoc.FileType
2532
@@ -78,6 +85,32 @@ renderPandocWith :: ParserState -> WriterOptions -> Item String -> Item String
7885renderPandocWith state options = writePandocWith options . readPandocWith state
7986
8087
88+--------------------------------------------------------------------------------
89+-- | Read a page render using pandoc
90+pandocCompiler :: Compiler (Item String)
91+pandocCompiler =
92+ pandocCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
93+
94+
95+--------------------------------------------------------------------------------
96+-- | A version of 'pandocCompiler' which allows you to specify your own pandoc
97+-- options
98+pandocCompilerWith :: ParserState -> WriterOptions -> Compiler (Item String)
99+pandocCompilerWith state options = pandocCompilerWithTransform state options id
100+
101+
102+--------------------------------------------------------------------------------
103+-- | An extension of 'pandocCompilerWith' which allows you to specify a custom
104+-- pandoc transformation for the content
105+pandocCompilerWithTransform :: ParserState -> WriterOptions
106+ -> (Pandoc -> Pandoc)
107+ -> Compiler (Item String)
108+pandocCompilerWithTransform state options f = cached cacheName $
109+ writePandocWith options . fmap f . readPandocWith state <$> getResourceBody
110+ where
111+ cacheName = "Hakyll.Web.Page.pageCompilerWithPandoc"
112+
113+
81114--------------------------------------------------------------------------------
82115-- | The default reader options for pandoc parsing in hakyll
83116defaultHakyllParserState :: ParserState
tests/Hakyll/Core/Rules/Tests.hs+2−2
@@ -20,7 +20,7 @@ import Hakyll.Core.Routes
2020import Hakyll.Core.Rules
2121import Hakyll.Core.Rules.Internal
2222import Hakyll.Core.Writable.CopyFile
23−import Hakyll.Web.Page
23+import Hakyll.Web.Pandoc
2424import TestSuite.Util
2525
2626
@@ -61,7 +61,7 @@ rules = do
6161 -- Compile some posts
6262 match "*.md" $ do
6363 route $ setExtension "html"
64− compile pageCompiler
64+ compile pandocCompiler
6565
6666 -- Compile them, raw
6767 match "*.md" $ version "raw" $ do
tests/Hakyll/Web/Template/Tests.hs+2−2
@@ -15,7 +15,7 @@ import Test.HUnit (Assertion, (@=?))
1515--------------------------------------------------------------------------------
1616import Hakyll.Core.Item
1717import Hakyll.Core.Provider
18−import Hakyll.Web.Page
18+import Hakyll.Web.Pandoc
1919import Hakyll.Web.Template
2020import Hakyll.Web.Template.Context
2121import TestSuite.Util
@@ -36,7 +36,7 @@ case01 = withTestStore $ \store -> do
3636 out <- resourceString provider "template.html.out"
3737 tpl <- testCompilerDone store provider "template.html" $ templateCompiler
3838 item <- testCompilerDone store provider "example.md" $
39− pageCompiler >>= applyTemplate (itemBody tpl) testContext
39+ pandocCompiler >>= applyTemplate (itemBody tpl) testContext
4040
4141 out @=? itemBody item
4242
web/tutorials/03-arrows.markdown → web/tutorials/04-arrows.markdownrenamed

The content is the same.

web/tutorials/04-guide.markdown → web/tutorials/05-guide.markdownrenamed

The content is the same.