Permalink
Browse files

Index pages

  • Loading branch information...
crodjer committed Apr 4, 2012
1 parent 2707d05 commit 008dbad6da3f7c5f95a738d1684d047d194adf03
Showing with 21 additions and 14 deletions.
  1. +19 −13 site.hs
  2. +1 −1 templates/index.html
  3. +1 −0 templates/posts.html
View
32 site.hs
@@ -1,13 +1,13 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where
-import Control.Arrow ((>>>), arr)
+import Prelude hiding (id)
+import Control.Category (id)
+import Control.Arrow ((>>>), arr, (***))
import Data.Monoid (mempty, mconcat)
import Control.Monad (forM_)
import System.FilePath
-import Text.Pandoc
-import Hakyll.Web.Feed
-import Hakyll.Web.Page.Metadata
+import Text.Pandoc (writerTableOfContents, writerTemplate, writerStandalone)
import Hakyll
@@ -43,26 +43,27 @@ main = hakyllWith config $ do
route $ postRoute `composeRoutes` cleanURL
compile $ defaultCompiler
>>> arr (setField "host" host)
+ >>> renderModificationTime "lastmod" "%Y-%m-%d"
+ >>> renderModificationTime "updated" "%Y-%m-%dT%H:%M:%SZ"
>>> arr (renderDateField "date" "%B %e, %Y" "Date unknown")
- >>> arr (renderDateField "lastmod" "%Y-%m-%d" "")
>>> arr (copyBodyToField "description")
>>> applyTemplateCompiler "templates/post.html"
>>> applyTemplateCompiler "templates/default.html"
- {-match "./posts.html" $ route $ setRoot `composeRoutes` cleanURL-}
- {-create "./posts.html" $ constA mempty-}
- {->>> arr (setField "title" defaultTitle)-}
- {->>> requireAllA "posts/*" postList-}
- {->>> applyTemplateCompiler "templates/posts.html"-}
- {->>> applyTemplateCompiler "templates/default.html"-}
+ match "./posts.html" $ route $ cleanURL
+ create "./posts.html" $ constA mempty
+ >>> arr (setField "title" defaultTitle)
+ >>> requireAllA "posts/*" postList
+ >>> applyTemplateCompiler "templates/posts.html"
+ >>> applyTemplateCompiler "templates/default.html"
-- Index
match "index.html" $ route idRoute
create "index.html" $ constA mempty
>>> arr (setField "title" defaultTitle)
- >>> requireAllA "posts/*" postList
- >>> applyTemplateCompiler "templates/posts.html"
+ >>> requireAllA "posts/*" ( id *** arr (latest 3) >>> postList )
+ >>> applyTemplateCompiler "templates/index.html"
>>> applyTemplateCompiler "templates/default.html"
-- Render some static pages
@@ -71,8 +72,10 @@ main = hakyllWith config $ do
route $ setRoot `composeRoutes` cleanURL
compile $ defaultCompiler
>>> arr (setField "host" host)
+ >>> renderModificationTime "lastmod" "%Y-%m-%d"
>>> applyTemplateCompiler "templates/default.html"
+
-- Sitemap
match "sitemap.xml" $ route idRoute
create "sitemap.xml" $ constA mempty
@@ -141,6 +144,9 @@ fileToIndex = (flip combine) "index.html" . dropFileName . toFilePath
-- misc functions
--------------------------------------------------------------------------------
+latest:: Int -> [Page b] -> [Page b]
+latest n = take n . reverse . chronological
+
stripIndexLink :: Page a -> Page a
stripIndexLink = changeField "url" dropFileName
View
@@ -1,5 +1,5 @@
<div id="posts">
<h1>Recent posts</h1>
$posts$
- <p><a href="/posts.html">All posts&hellip;</a></p>
+ <p><a href="/posts/">All posts&hellip;</a></p>
</div>
View
@@ -1,3 +1,4 @@
<div id="posts">
+ <h1>Listing posts</h1>
$posts$
</div>

0 comments on commit 008dbad

Please sign in to comment.