on master help sign in
Some prototype work on the Page.List module
commit7f7494cd1448ea4c05756abdf2d6dd4d8430cd31 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 29 May 2011, 19:46 (15 years ago) parent2ed3df4
6 files changed+129−50
hakyll.cabal+34−33 src/Hakyll.hs+2 src/Hakyll/Core/Compiler.hs+1−1 src/Hakyll/Web/Page.hs−10 src/Hakyll/Web/Page/List.hs+82 src/Hakyll/Web/Tags.hs+10−6
hakyll.cabal+34−33
@@ -81,52 +81,53 @@ Library
8181
8282 Exposed-Modules:
8383 Hakyll
84− Hakyll.Main
85− Hakyll.Web.Blaze
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
84+ Hakyll.Core.CompiledItem
85+ Hakyll.Core.Compiler
10086 Hakyll.Core.Configuration
10187 Hakyll.Core.DependencyAnalyzer
88+ Hakyll.Core.DirectedGraph
89+ Hakyll.Core.DirectedGraph.Dot
90+ Hakyll.Core.Identifier
10291 Hakyll.Core.Identifier.Pattern
103− Hakyll.Core.UnixFilter
104− Hakyll.Core.Util.Arrow
105− Hakyll.Core.Util.File
106− Hakyll.Core.Util.String
92+ Hakyll.Core.Logger
10793 Hakyll.Core.Resource
10894 Hakyll.Core.Resource.Provider
10995 Hakyll.Core.Resource.Provider.File
110− Hakyll.Core.CompiledItem
111− Hakyll.Core.Compiler
96+ Hakyll.Core.Routes
97+ Hakyll.Core.Rules
11298 Hakyll.Core.Run
11399 Hakyll.Core.Store
100+ Hakyll.Core.UnixFilter
101+ Hakyll.Core.Util.Arrow
102+ Hakyll.Core.Util.File
103+ Hakyll.Core.Util.String
114104 Hakyll.Core.Writable
115105 Hakyll.Core.Writable.CopyFile
116106 Hakyll.Core.Writable.WritableTuple
117− Hakyll.Core.Identifier
118− Hakyll.Core.DirectedGraph.Dot
119− Hakyll.Core.DirectedGraph
120− Hakyll.Core.Rules
121− Hakyll.Core.Routes
122− Hakyll.Core.Logger
107+ Hakyll.Main
108+ Hakyll.Web.Blaze
109+ Hakyll.Web.CompressCss
110+ Hakyll.Web.Feed
111+ Hakyll.Web.Page
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
123124
124125 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
130126 Hakyll.Core.Compiler.Internal
131127 Hakyll.Core.DirectedGraph.Internal
132128 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
2121 , module Hakyll.Web.CompressCss
2222 , module Hakyll.Web.Feed
2323 , module Hakyll.Web.Page
24+ , module Hakyll.Web.Page.List
2425 , module Hakyll.Web.Page.Metadata
2526 , module Hakyll.Web.Page.Read
2627 , module Hakyll.Web.Pandoc
@@ -51,6 +52,7 @@ import Hakyll.Web.Blaze
5152import Hakyll.Web.CompressCss
5253import Hakyll.Web.Feed
5354import Hakyll.Web.Page
55+import Hakyll.Web.Page.List
5456import Hakyll.Web.Page.Metadata
5557import Hakyll.Web.Page.Read
5658import Hakyll.Web.Pandoc
src/Hakyll/Core/Compiler.hs+1−1
@@ -230,7 +230,7 @@ getDependency id' = CompilerM $ do
230230 Found x -> return x
231231 where
232232 notFound =
233− "Hakyll.Core.Compiler.getDependency: " ++ show id' ++ " not found " ++
233+ "Hakyll.Core.Compiler.getDependency: " ++ show id' ++ " was "
234234 "not found in the cache, the cache might be corrupted or " ++
235235 "the item you are referring to might not exist"
236236 wrongType e r =
src/Hakyll/Web/Page.hs−10
@@ -56,7 +56,6 @@ module Hakyll.Web.Page
5656 , pageCompilerWith
5757 , pageCompilerWithPandoc
5858 , addDefaultFields
59− , sortByBaseName
6059 ) where
6160
6261import Prelude hiding (id)
@@ -64,8 +63,6 @@ import Control.Category (id)
6463import Control.Arrow (arr, (>>^), (&&&), (>>>))
6564import System.FilePath (takeBaseName, takeDirectory)
6665import qualified Data.Map as M
67−import Data.List (sortBy)
68−import Data.Ord (comparing)
6966
7067import Text.Pandoc (Pandoc, ParserState, WriterOptions)
7168
@@ -137,10 +134,3 @@ addDefaultFields = (getRoute &&& id >>^ uncurry addRoute)
137134 . trySetField "path" p
138135 where
139136 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
111111
112112-- | Render tags in HTML
113113--
114−renderTags :: (String -> Identifier a)
114+renderTags :: (String -> Identifier (Page a))
115115 -- ^ Produce a link
116116 -> (String -> String -> Int -> Int -> Int -> String)
117117 -- ^ Produce a tag item: tag, url, count, min count, max count
@@ -141,10 +141,14 @@ renderTags makeUrl makeItem concatItems = proc (Tags tags) -> do
141141
142142-- | Render a tag cloud in HTML
143143--
144−renderTagCloud :: (String -> Identifier a) -- ^ Produce a link for a tag
145− -> Double -- ^ Smallest font size, in percent
146− -> Double -- ^ Biggest font size, in percent
147− -> Compiler (Tags a) String -- ^ Tag cloud renderer
144+renderTagCloud :: (String -> Identifier (Page a))
145+ -- ^ Produce a link for a tag
146+ -> Double
147+ -- ^ Smallest font size, in percent
148+ -> Double
149+ -- ^ Biggest font size, in percent
150+ -> Compiler (Tags a) String
151+ -- ^ Tag cloud renderer
148152renderTagCloud makeUrl minSize maxSize =
149153 renderTags makeUrl makeLink (intercalate " ")
150154 where
@@ -162,7 +166,7 @@ renderTagCloud makeUrl minSize maxSize =
162166
163167-- | Render a simple tag list in HTML, with the tag count next to the item
164168--
165−renderTagList :: (String -> Identifier a) -> Compiler (Tags a) (String)
169+renderTagList :: (String -> Identifier (Page a)) -> Compiler (Tags a) (String)
166170renderTagList makeUrl = renderTags makeUrl makeLink (intercalate ", ")
167171 where
168172 makeLink tag url count _ _ = renderHtml $