summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hakyll.hs102
-rw-r--r--templates/default.html26
-rw-r--r--templates/post.html2
-rw-r--r--templates/post_short.html2
4 files changed, 82 insertions, 50 deletions
diff --git a/hakyll.hs b/hakyll.hs
index daac1a5..f5e1045 100644
--- a/hakyll.hs
+++ b/hakyll.hs
@@ -46,40 +46,40 @@ main = hakyll $ do
>>> relativizeUrlsCompiler
-- Index
- match "index.html" $ route idRoute
- create "index.html" $ constA mempty
- >>> arr (setField "title" "Home")
- >>> addTagCloud
- >>> addArchiveLinks
- >>> requireAllA allPosts (id *** arr recentFirst >>> addPosts)
- >>> applyTemplateCompiler "templates/index.html"
- >>> applyTemplateCompiler "templates/default.html"
- >>> relativizeUrlsCompiler
+ match "index*" $ route $ setExtension ".html"
+ metaCompile $ requireAllA allPosts $ arr (recentFirst . snd)
+ >>> ((constA () &&& constA "index*") &&& id)
+ >>> paginatePosts (const "Home")
match "posts/*" $ compile $ readPageCompiler
>>> (id &&& getIdentifier)
>>> setFieldA "path" (arr $ fromMaybe "" . runRoutes (setExtension ".html"))
>>> (id &&& arr (getField "path"))
- >>> setFieldA "url" (arr ('/':))
+ >>> setFieldA "url" (arr toUrl)
-- Tags
create "tags" $
- requireAll allPosts (\_ ps -> readTags ps :: Tags String)
+ requireAll_ allPosts >>> arr readTags
- -- Add a tag list compiler for every tag
match "tags/*" $ route $ setExtension ".html"
metaCompile $ require_ "tags"
>>> arr tagsMap
- >>> arr (map (\(t, p) -> (tagIdentifier t, makeTagList t p)))
+ >>> mapCompiler (((arr id &&& arr (parseGlob . (++ "*") . identifierPath . tagIdentifier)) *** id)
+ >>> paginatePosts (\tag -> "Posts tagged ‘" ++ tag ++ "’")
+ )
+ >>> arr concat
-- Archive
create "archive" $
- requireAll allPosts (\_ -> Tags . groupTuples . reverse . sortBy (compare `on` fst) . catMaybes . map (\page -> getDate page >>= (\date -> return (date, page))))
+ requireAll_ allPosts >>> arr (Tags . groupTuples . reverse . sortBy (compare `on` fst) . catMaybes . map (\page -> getDate page >>= (\date -> return (date, page))))
match "archive/**" $ route $ setExtension ".html"
metaCompile $ require_ "archive"
>>> arr tagsMap
- >>> arr (map (\(m, p) -> (archiveIdentifier m, makeArchive m p)))
+ >>> mapCompiler (((arr id &&& arr (parseGlob . (++ "*") . identifierPath . archiveIdentifier)) *** id)
+ >>> paginatePosts (\month -> "Archive for " ++ prettyMonth month)
+ )
+ >>> arr concat
-- Render RSS feed
match "rss.xml" $ route idRoute
@@ -97,10 +97,36 @@ main = hakyll $ do
notInPostGroup :: Pattern a -> Pattern a
notInPostGroup p = patternIntersection [complement $ inGroup postGroup, p]
-
+
allPosts :: Pattern (Page String)
allPosts = notInPostGroup "posts/*"
+ nav prev next = navPrev prev ++ navNext next
+
+ navPrev Nothing = "<span class=\"newer\">&nbsp;</span>"
+ navPrev (Just url) = "<span class=\"newer\"><a href=\"" ++ url ++ "\" >&laquo; Newer Entries</a></span>"
+
+ navNext Nothing = "<span class=\"older\">&nbsp;</span>"
+ navNext (Just url) = "<span class=\"older\"><a href=\"" ++ url ++ "\" >Older Entries &raquo;</a></span>"
+
+ pageTitle 0 = ""
+ pageTitle i = " - Page " ++ show (i+1)
+
+ paginatePosts :: (a -> String) -> Compiler ((a, Pattern (Page String)), [Page String]) [(Identifier (Page String), Compiler () (Page String))]
+ paginatePosts title = paginate 5 (setExtension ".html")
+ (arr (\(a, prev, next, i, pages) -> ((mempty, (a, prev, next, i)), pages))
+ >>> first (first (addTagCloud >>> addArchiveLinks)
+ >>> arr (\(page, (a, prev, next, i)) -> setField "nav" (nav prev next) $ setField "title" (title a ++ pageTitle i) page)
+ )
+ >>> addPosts
+ >>> applyTemplateCompiler "templates/index.html"
+ >>> applyTemplateCompiler "templates/default.html"
+ >>> relativizeUrlsCompiler
+ )
+
+
+
+
patternIntersection :: [Pattern a] -> Pattern a
patternIntersection patterns = predicate $ flip all patterns . flip matches
@@ -127,13 +153,31 @@ getDate = liftM ((\(y, m, _) -> printf "%04d/%02d" y m) . toGregorian . utctDay)
groupTuples :: Eq a => [(a, b)] -> [(a, [b])]
groupTuples = map (fst . head &&& map snd) . groupBy ((==) `on` fst)
+paginate :: Int -> Routes -> Compiler (a, Maybe String, Maybe String, Int, [Page String]) (Page String) -> Compiler ((a, Pattern (Page String)), [Page String]) [(Identifier (Page String), Compiler () (Page String))]
+paginate perPage routes c = arr $ \((a, pattern), posts) -> renderPages a pattern 0 (n posts) posts
+ where
+ renderPages _ _ _ _ [] = []
+ renderPages a pattern i n posts = (name i, constA (a, prev i, next i n, i, cur) >>> c):(renderPages a pattern (i+1) n rest)
+ where
+ (cur, rest) = splitAt perPage posts
+
+ prev 0 = Nothing
+ prev i = fmap toUrl . runRoutes routes . name $ i-1
+
+ next i n = if i == (n-1) then Nothing else fmap toUrl . runRoutes routes . name $ i+1
+
+ name 0 = fromCapture pattern ""
+ name i = fromCapture pattern $ show i
+
+ n posts = (length posts + perPage - 1) `div` perPage
+
addPosts :: Compiler (Page String, [Page String]) (Page String)
addPosts = setFieldA "posts" $
mapCompiler (addDate
>>> addTagCloud
>>> renderTagsField "prettytags" (fromCapture "tags/*")
- >>> applyTemplateCompiler "templates/post_short.html")
+ >>> applyTemplateCompiler "templates/post.html")
>>> arr mconcat
>>> arr pageBody
@@ -148,7 +192,7 @@ addArchiveLinks = requireA "archive" (setFieldA "archive" renderArchive)
where
renderArchive :: Compiler (Tags String) String
renderArchive = arr tagsMap
- >>> arr (map (\(s, p) -> "<li><a href=\"/archive/" ++ s ++ ".html\" title=\"" ++ prettyMonth s ++ "\">" ++ prettyMonth s ++ "</a>&nbsp;(" ++ show (length p) ++ ")</li>"))
+ >>> arr (map (\(s, p) -> "<li><a href=\"/archive/" ++ s ++ ".html\">" ++ prettyMonth s ++ "</a>&nbsp;(" ++ show (length p) ++ ")</li>"))
>>> arr mconcat
prettyMonth :: String -> String
@@ -177,30 +221,10 @@ tagIdentifier = fromCapture "tags/*"
archiveIdentifier :: String -> Identifier (Page String)
archiveIdentifier = fromCapture "archive/*"
-makeTagList :: String -> [Page String] -> Compiler () (Page String)
-makeTagList tag posts = constA (mempty, posts)
- >>> addPosts
- >>> addTagCloud
- >>> addArchiveLinks
- >>> arr (setField "title" ("Posts tagged &#8216;" ++ tag ++ "&#8217;"))
- >>> applyTemplateCompiler "templates/posts.html"
- >>> applyTemplateCompiler "templates/default.html"
- >>> relativizeUrlsCompiler
-
-makeArchive :: String -> [Page String] -> Compiler () (Page String)
-makeArchive month posts = constA (mempty, posts)
- >>> addPosts
- >>> addTagCloud
- >>> addArchiveLinks
- >>> arr (setField "title" ("Archive for " ++ prettyMonth month))
- >>> applyTemplateCompiler "templates/posts.html"
- >>> applyTemplateCompiler "templates/default.html"
- >>> relativizeUrlsCompiler
-
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedTitle = "Universe Factory"
, feedDescription = "Because one universe is not enough"
, feedAuthorName = "NeoRaider"
- , feedRoot = "http://blog.universe-factory.net/"
+ , feedRoot = "http://blog.universe-factory.net"
}
diff --git a/templates/default.html b/templates/default.html
index db34114..74eac8b 100644
--- a/templates/default.html
+++ b/templates/default.html
@@ -6,6 +6,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Universe Factory - $title$</title>
+ <link rel="alternate" type="application/rss+xml" title="Universe Factory &raquo; Feed" href="/rss.xml" />
<link rel="stylesheet" id="lightword_stylesheet-css" href="/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" id="lightword_stylesheet_original-css" href="/css/original.css" type="text/css" media="all" />
<style type="text/css">
@@ -16,15 +17,15 @@
<body class="home blog">
<div id="wrapper">
- <div id="top_cufon"><h1 id="logo"><a name="top" title="Universe Factory" href="/">Universe Factory</a> <small>Because one universe is not enough</small></h1></div>
+ <div id="top_cufon"><h1 id="logo"><a name="top" href="/">Universe Factory</a> <small>Because one universe is not enough</small></h1></div>
<div id="header">
- <a id="rss-feed" title="Syndicate this site using RSS" href="/feed/">Subscribe via RSS</a>
+ <a id="rss-feed" title="Syndicate this site using RSS" href="/rss.xml">Subscribe via RSS</a>
<div id="top_bar">
<div class="center_menu">
<ul id="front_menu" >
- <li><a class="s" title="Home" href="/"><span>Home</span></a></li>
+ <li><a class="s" href="/"><span>Home</span></a></li>
</ul>
</div>
</div>
@@ -33,14 +34,21 @@
<div id="content-body">
$body$
- <!--<div class="newer_older">
- <span class="newer">&nbsp;</span>
- <span class="older">&nbsp;<a href="/2/" >Older Entries &raquo;</a></span>
- </div>-->
+ <div class="newer_older">
+ <!--<span class="newer">&nbsp;</span>
+ <span class="older">&nbsp;<a href="/2/" >Older Entries &raquo;</a></span>-->
+ $nav$
+ </div>
</div>
<div class="content-sidebar">
<h3>Blogroll</h3>
<ul class="xoxo blogroll">
+ <li><a href="http://lenabits.wordpress.com/" rel="friend met">LenaBits</a></li>
+ <li><a href="http://mieke.planetcyb.org/" rel="friend met">Mieke</a></li>
+ <li><a href="https://mw.vc/" rel="friend met">Milliways</a></li>
+ <li><a href="http://notrademark.de/" rel="friend met">Msquare</a></li>
+ <li><a href="http://themesh.de/" rel="friend met">theMesh</a></li>
+ <li><a href="http://worldschanging.universe-factory.net/" rel="friend met">Worlds Changing</a></li>
</ul>
<h3>Tags</h3><div class="tagcloud">
@@ -54,8 +62,8 @@
</div>
<div id="footer">
<span class="text">
- Copyright &copy; 2012 <a href="http://blog.universe-factory.net/">Universe Factory</a> &middot; Powered by <a href="http://github.com/jaspervdj/hakyll" title="Hakyll">Hakyll</a><br/>
- Based on <a href="http://www.lightword-design.com/" title="Lightword Theme">Lightword Theme</a> by Andrei Luca adapted for Hakyll
+ Copyright &copy; 2012 <a href="http://blog.universe-factory.net/">Universe Factory</a> &middot; Powered by <a href="http://github.com/jaspervdj/hakyll">Hakyll</a><br/>
+ Based on <a href="http://www.lightword-design.com/">Lightword Theme</a> by Andrei Luca adapted for Hakyll
<a title="Go to top" class="top" href="#top">Go to top &uarr;</a>
</span>
</div>
diff --git a/templates/post.html b/templates/post.html
index 7505058..f6ac5b5 100644
--- a/templates/post.html
+++ b/templates/post.html
@@ -2,7 +2,7 @@
<div class="only_date">
$date$
</div>
- <h2>$title$</h2>
+ <h2><a href="$url$" rel="bookmark">$title$</a></h2>
<p>$body$</p>
<div class="cat_tags clear">
diff --git a/templates/post_short.html b/templates/post_short.html
index 06242ca..3cdfe59 100644
--- a/templates/post_short.html
+++ b/templates/post_short.html
@@ -2,7 +2,7 @@
<div class="only_date">
$date$
</div>
- <h2><a title="$title$" href="$url$" rel="bookmark">$title$</a></h2>
+ <h2><a href="$url$" rel="bookmark">$title$</a></h2>
<p>$body$</p>
<div class="cat_tags clear cat_tags_continue">