on master help sign in
Some prototype work on the Page.List module
7f7494cJasper Van der Jeugt
hakyll.cabal+34−33
@@ -81,52 +81,53 @@ Library
81
81
82 Exposed-Modules:
82 Exposed-Modules:
83 Hakyll
83 Hakyll
84− Hakyll.Main
84+ Hakyll.Core.CompiledItem
85− Hakyll.Web.Blaze
85+ Hakyll.Core.Compiler
86− Hakyll.Web.Util.Url
87− Hakyll.Web.Preview.Server
88− Hakyll.Web.Preview.Poll
89− Hakyll.Web.CompressCss
90− Hakyll.Web.Template
91− Hakyll.Web.Feed
92− Hakyll.Web.Tags
93− Hakyll.Web.Pandoc
94− Hakyll.Web.Pandoc.FileType
95− Hakyll.Web.Page
96− Hakyll.Web.Template.Read
97− Hakyll.Web.RelativizeUrls
98− Hakyll.Web.Page.Read
99− Hakyll.Web.Page.Metadata
100 Hakyll.Core.Configuration
86 Hakyll.Core.Configuration
101 Hakyll.Core.DependencyAnalyzer
87 Hakyll.Core.DependencyAnalyzer
88+ Hakyll.Core.DirectedGraph
89+ Hakyll.Core.DirectedGraph.Dot
90+ Hakyll.Core.Identifier
102 Hakyll.Core.Identifier.Pattern
91 Hakyll.Core.Identifier.Pattern
103− Hakyll.Core.UnixFilter
92+ Hakyll.Core.Logger
104− Hakyll.Core.Util.Arrow
105− Hakyll.Core.Util.File
106− Hakyll.Core.Util.String
107 Hakyll.Core.Resource
93 Hakyll.Core.Resource
108 Hakyll.Core.Resource.Provider
94 Hakyll.Core.Resource.Provider
109 Hakyll.Core.Resource.Provider.File
95 Hakyll.Core.Resource.Provider.File
110− Hakyll.Core.CompiledItem
96+ Hakyll.Core.Routes
111− Hakyll.Core.Compiler
97+ Hakyll.Core.Rules
112 Hakyll.Core.Run
98 Hakyll.Core.Run
113 Hakyll.Core.Store
99 Hakyll.Core.Store
100+ Hakyll.Core.UnixFilter
101+ Hakyll.Core.Util.Arrow
102+ Hakyll.Core.Util.File
103+ Hakyll.Core.Util.String
114 Hakyll.Core.Writable
104 Hakyll.Core.Writable
115 Hakyll.Core.Writable.CopyFile
105 Hakyll.Core.Writable.CopyFile
116 Hakyll.Core.Writable.WritableTuple
106 Hakyll.Core.Writable.WritableTuple
117− Hakyll.Core.Identifier
107+ Hakyll.Main
118− Hakyll.Core.DirectedGraph.Dot
108+ Hakyll.Web.Blaze
119− Hakyll.Core.DirectedGraph
109+ Hakyll.Web.CompressCss
120− Hakyll.Core.Rules
110+ Hakyll.Web.Feed
121− Hakyll.Core.Routes
111+ Hakyll.Web.Page
122− Hakyll.Core.Logger
112+ Hakyll.Web.Page.List
113+ Hakyll.Web.Page.Metadata
114+ Hakyll.Web.Page.Read
115+ Hakyll.Web.Pandoc
116+ Hakyll.Web.Pandoc.FileType
117+ Hakyll.Web.Preview.Poll
118+ Hakyll.Web.Preview.Server
119+ Hakyll.Web.RelativizeUrls
120+ Hakyll.Web.Tags
121+ Hakyll.Web.Template
122+ Hakyll.Web.Template.Read
123+ Hakyll.Web.Util.Url
123
124
124 Other-Modules:
125 Other-Modules:
125− Paths_hakyll
126− Hakyll.Web.Template.Read.Hakyll
127− Hakyll.Web.Template.Read.Hamlet
128− Hakyll.Web.Template.Internal
129− Hakyll.Web.Page.Internal
130 Hakyll.Core.Compiler.Internal
126 Hakyll.Core.Compiler.Internal
131 Hakyll.Core.DirectedGraph.Internal
127 Hakyll.Core.DirectedGraph.Internal
132 Hakyll.Core.Rules.Internal
128 Hakyll.Core.Rules.Internal
129+ Hakyll.Web.Page.Internal
130+ Hakyll.Web.Template.Internal
131+ Hakyll.Web.Template.Read.Hakyll
132+ Hakyll.Web.Template.Read.Hamlet
133+ Paths_hakyll
src/Hakyll.hs+2
@@ -21,6 +21,7 @@ module Hakyll
21 , module Hakyll.Web.CompressCss
21 , module Hakyll.Web.CompressCss
22 , module Hakyll.Web.Feed
22 , module Hakyll.Web.Feed
23 , module Hakyll.Web.Page
23 , module Hakyll.Web.Page
24+ , module Hakyll.Web.Page.List
24 , module Hakyll.Web.Page.Metadata
25 , module Hakyll.Web.Page.Metadata
25 , module Hakyll.Web.Page.Read
26 , module Hakyll.Web.Page.Read
26 , module Hakyll.Web.Pandoc
27 , module Hakyll.Web.Pandoc
@@ -51,6 +52,7 @@ import Hakyll.Web.Blaze
51import Hakyll.Web.CompressCss
52import Hakyll.Web.CompressCss
52import Hakyll.Web.Feed
53import Hakyll.Web.Feed
53import Hakyll.Web.Page
54import Hakyll.Web.Page
55+import Hakyll.Web.Page.List
54import Hakyll.Web.Page.Metadata
56import Hakyll.Web.Page.Metadata
55import Hakyll.Web.Page.Read
57import Hakyll.Web.Page.Read
56import Hakyll.Web.Pandoc
58import Hakyll.Web.Pandoc
src/Hakyll/Core/Compiler.hs+1−1
@@ -230,7 +230,7 @@ getDependency id' = CompilerM $ do
230 Found x -> return x
230 Found x -> return x
231 where
231 where
232 notFound =
232 notFound =
233− "Hakyll.Core.Compiler.getDependency: " ++ show id' ++ " not found " ++
233+ "Hakyll.Core.Compiler.getDependency: " ++ show id' ++ " was "
234 "not found in the cache, the cache might be corrupted or " ++
234 "not found in the cache, the cache might be corrupted or " ++
235 "the item you are referring to might not exist"
235 "the item you are referring to might not exist"
236 wrongType e r =
236 wrongType e r =
src/Hakyll/Web/Page.hs−10
@@ -56,7 +56,6 @@ module Hakyll.Web.Page
56 , pageCompilerWith
56 , pageCompilerWith
57 , pageCompilerWithPandoc
57 , pageCompilerWithPandoc
58 , addDefaultFields
58 , addDefaultFields
59− , sortByBaseName
60 ) where
59 ) where
61
60
62import Prelude hiding (id)
61import Prelude hiding (id)
@@ -64,8 +63,6 @@ import Control.Category (id)
64import Control.Arrow (arr, (>>^), (&&&), (>>>))
63import Control.Arrow (arr, (>>^), (&&&), (>>>))
65import System.FilePath (takeBaseName, takeDirectory)
64import System.FilePath (takeBaseName, takeDirectory)
66import qualified Data.Map as M
65import qualified Data.Map as M
67−import Data.List (sortBy)
68−import Data.Ord (comparing)
69
66
70import Text.Pandoc (Pandoc, ParserState, WriterOptions)
67import Text.Pandoc (Pandoc, ParserState, WriterOptions)
71
68
@@ -137,10 +134,3 @@ addDefaultFields = (getRoute &&& id >>^ uncurry addRoute)
137 . trySetField "path" p
134 . trySetField "path" p
138 where
135 where
139 p = toFilePath i
136 p = toFilePath i
140−
141−-- | Sort posts based on the basename of the post. This is equivalent to a
142−-- chronologival sort, because of the @year-month-day-title.extension@ naming
143−-- convention in Hakyll.
144−--
145−sortByBaseName :: [Page a] -> [Page a]
146−sortByBaseName = sortBy $ comparing $ takeBaseName . getField "path"
src/Hakyll/Web/Page/List.hsnew file+82
@@ -0,0 +1,82 @@
1+-- | Provides an easy way to combine several pages in a list. The applications
2+-- are obvious:
3+--
4+-- * A post list on a blog
5+--
6+-- * An image list in a gallery
7+--
8+-- * A sitemap
9+--
10+module Hakyll.Web.Page.List
11+ ( setFieldPageList
12+ , pageListCompiler
13+ , chronological
14+ , recentFirst
15+ , sortByBaseName
16+ ) where
17+
18+import Control.Arrow ((>>>), arr)
19+import Data.List (sortBy)
20+import Data.Monoid (Monoid, mconcat)
21+import Data.Ord (comparing)
22+import System.FilePath (takeBaseName)
23+
24+import Hakyll.Core.Compiler
25+import Hakyll.Core.Identifier
26+import Hakyll.Core.Identifier.Pattern
27+import Hakyll.Web.Page
28+import Hakyll.Web.Page.Metadata
29+import Hakyll.Web.Template
30+
31+-- | Set a field of a page to a listing of pages
32+--
33+setFieldPageList :: ([Page String] -> [Page String])
34+ -- ^ Determines list order
35+ -> Identifier Template
36+ -- ^ Applied to every page
37+ -> String
38+ -- ^ Key indicating which field should be set
39+ -> Pattern (Page String)
40+ -- ^ Selects pages to include in the list
41+ -> Compiler (Page String) (Page String)
42+ -- ^ Compiler that sets the page list in a field
43+setFieldPageList sort template key pattern =
44+ requireAllA pattern $ setFieldA key $ pageListCompiler sort template
45+
46+-- | Create a list of pages
47+--
48+pageListCompiler :: ([Page String] -> [Page String]) -- ^ Determine list order
49+ -> Identifier Template -- ^ Applied to pages
50+ -> Compiler [Page String] String -- ^ Compiles page list
51+pageListCompiler sort template =
52+ arr sort >>> applyTemplateToList template >>> arr concatPages
53+
54+-- | Apply a template to every page in a list
55+--
56+applyTemplateToList :: Identifier Template
57+ -> Compiler [Page String] [Page String]
58+applyTemplateToList identifier =
59+ require identifier $ \posts template -> map (applyTemplate template) posts
60+
61+-- | Concatenate the bodies of a page list
62+--
63+concatPages :: Monoid m => [Page m] -> m
64+concatPages = mconcat . map pageBody
65+
66+-- | Sort pages chronologically. This function assumes that the pages have a
67+-- @year-month-day-title.extension@ naming scheme -- as is the convention in
68+-- Hakyll.
69+--
70+chronological :: [Page a] -> [Page a]
71+chronological = sortBy $ comparing $ takeBaseName . getField "path"
72+
73+-- | The reverse of 'chronological'
74+--
75+recentFirst :: [Page a] -> [Page a]
76+recentFirst = reverse . chronological
77+
78+-- | Deprecated, see 'chronological'
79+--
80+sortByBaseName :: [Page a] -> [Page a]
81+sortByBaseName = chronological
82+{-# DEPRECATED sortByBaseName "Use chronological" #-}
src/Hakyll/Web/Tags.hs+10−6
@@ -111,7 +111,7 @@ readCategory = readTagsWith getCategory
111
111
112-- | Render tags in HTML
112-- | Render tags in HTML
113--
113--
114−renderTags :: (String -> Identifier a)
114+renderTags :: (String -> Identifier (Page a))
115 -- ^ Produce a link
115 -- ^ Produce a link
116 -> (String -> String -> Int -> Int -> Int -> String)
116 -> (String -> String -> Int -> Int -> Int -> String)
117 -- ^ Produce a tag item: tag, url, count, min count, max count
117 -- ^ Produce a tag item: tag, url, count, min count, max count
@@ -141,10 +141,14 @@ renderTags makeUrl makeItem concatItems = proc (Tags tags) -> do
141
141
142-- | Render a tag cloud in HTML
142-- | Render a tag cloud in HTML
143--
143--
144−renderTagCloud :: (String -> Identifier a) -- ^ Produce a link for a tag
144+renderTagCloud :: (String -> Identifier (Page a))
145+ -- ^ Produce a link for a tag
146+ -> Double
145− -> Double -- ^ Smallest font size, in percent
147+ -- ^ Smallest font size, in percent
148+ -> Double
146− -> Double -- ^ Biggest font size, in percent
149+ -- ^ Biggest font size, in percent
147− -> Compiler (Tags a) String -- ^ Tag cloud renderer
150+ -> Compiler (Tags a) String
151+ -- ^ Tag cloud renderer
148renderTagCloud makeUrl minSize maxSize =
152renderTagCloud makeUrl minSize maxSize =
149 renderTags makeUrl makeLink (intercalate " ")
153 renderTags makeUrl makeLink (intercalate " ")
150 where
154 where
@@ -162,7 +166,7 @@ renderTagCloud makeUrl minSize maxSize =
162
166
163-- | Render a simple tag list in HTML, with the tag count next to the item
167-- | Render a simple tag list in HTML, with the tag count next to the item
164--
168--
165−renderTagList :: (String -> Identifier a) -> Compiler (Tags a) (String)
169+renderTagList :: (String -> Identifier (Page a)) -> Compiler (Tags a) (String)
166renderTagList makeUrl = renderTags makeUrl makeLink (intercalate ", ")
170renderTagList makeUrl = renderTags makeUrl makeLink (intercalate ", ")
167 where
171 where
168 makeLink tag url count _ _ = renderHtml $
172 makeLink tag url count _ _ = renderHtml $