on master help sign in
Add small blog premade config
commit4b662bc8316c32d51c7e84a0f90c0897eb12c0be authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 15 Jun 2011, 16:27 (15 years ago) parentfbe95ce
2 files changed+101
hakyll.cabal+1 src/Hakyll/Configs/SmallBlog.hs+100
hakyll.cabal+1
@@ -105,6 +105,7 @@ Library
105105 Hakyll.Core.Writable
106106 Hakyll.Core.Writable.CopyFile
107107 Hakyll.Core.Writable.WritableTuple
108+ Hakyll.Configs.SmallBlog
108109 Hakyll.Main
109110 Hakyll.Web.Blaze
110111 Hakyll.Web.CompressCss
src/Hakyll/Configs/SmallBlog.hsnew file+100
@@ -0,0 +1,100 @@
1+-- | This module provides a simple default configuration which behaves similar
2+-- to the Jekyll static site generator.
3+--
4+-- <http://jekyllrb.com/>
5+--
6+-- The idea is that you don't have to write your configuration yourself: you
7+-- just follow some conventions, and Hakyll does the rest.
8+--
9+{-# LANGUAGE OverloadedStrings #-}
10+{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
11+module Hakyll.Configs.SmallBlog
12+ ( SmallBlogConfiguration
13+ , defaultSmallBlogConfiguration
14+ , smallBlog
15+ , smallBlogWith
16+ ) where
17+
18+import Control.Arrow ((>>>))
19+
20+import Hakyll
21+
22+-- | Configuration datatype for the 'smallBlog' ruleset
23+--
24+data SmallBlogConfiguration = SmallBlogConfiguration
25+ { -- | Number of recent posts that are available
26+ numberOfRecentPosts :: Int
27+ } deriving (Show)
28+
29+-- | Defaults for 'SmallBlogConfiguration'
30+--
31+defaultSmallBlogConfiguration :: SmallBlogConfiguration
32+defaultSmallBlogConfiguration = SmallBlogConfiguration
33+ { numberOfRecentPosts = 3
34+ }
35+
36+-- | A default configuration for a small blog
37+--
38+smallBlog :: Rules
39+smallBlog = smallBlogWith defaultSmallBlogConfiguration
40+
41+-- | Version of 'smallBlog' which allows setting a config
42+--
43+smallBlogWith :: SmallBlogConfiguration -> Rules
44+smallBlogWith conf = do
45+ -- Images and static files
46+ ["favicon.ico"] --> copy
47+ ["img/**", "images/**"] --> copy
48+ ["static/**", "files/**"] --> copy
49+
50+ -- CSS files
51+ ["css/*.css", "style/*.css", "stylesheets/*.css"] --> css
52+
53+ -- All templates
54+ ["templates/*"] --> template
55+
56+ -- "Dynamic" content
57+ ["posts/*"] --> post
58+
59+ -- Top-level pages
60+ ["*.markdown", "*.html", "*.rst", "*.lhs"] --> topLevel
61+ where
62+ -- Useful combinator here
63+ xs --> f = mapM_ (\p -> match p $ f) xs
64+
65+ -- Completely static
66+ copy = route idRoute >> compile copyFileCompiler
67+
68+ -- CSS directories
69+ css = route (setExtension "css") >> compile compressCssCompiler
70+
71+ -- Templates
72+ template = compile templateCompiler
73+
74+ -- Posts
75+ post = do
76+ route $ setExtension "html"
77+ compile $ pageCompiler
78+ >>> applyTemplateCompiler "templates/post.html"
79+ >>> applyTemplateCompiler "templates/default.html"
80+ >>> relativizeUrlsCompiler
81+
82+ -- Top-level pages
83+ topLevel = do
84+ route $ setExtension "html"
85+ compile $ pageCompilerWithFields defaultHakyllParserState
86+ defaultHakyllWriterOptions id topLevelFields
87+ >>> applyTemplateCompiler "templates/default.html"
88+ >>> relativizeUrlsCompiler
89+
90+ -- Add the fields we need to top-level pages
91+ topLevelFields = setFieldPostList recentFirst "allPosts"
92+ >>> setFieldPostList (take nRecent . recentFirst) "recentPosts"
93+ >>> setFieldPostList chronological "chronologicalPosts"
94+
95+ -- Create a post list based on ordering/selection
96+ setFieldPostList f k = setFieldPageList f
97+ "templates/post-item.html" k "posts/*"
98+
99+ -- Number of most recent posts to show
100+ nRecent = numberOfRecentPosts conf