add archive
authorLucian Mogosanu <lucian.mogosanu@gmail.com>
Sat, 20 Jul 2013 08:42:16 +0000 (11:42 +0300)
committerLucian Mogosanu <lucian.mogosanu@gmail.com>
Sat, 20 Jul 2013 08:42:16 +0000 (11:42 +0300)
site.hs
templates/archive.html [new file with mode: 0644]
templates/default.html

diff --git a/site.hs b/site.hs
index 85dd540..768fc3c 100644 (file)
--- a/site.hs
+++ b/site.hs
@@ -8,6 +8,7 @@ main = hakyll $ do
   match "css/*" compileCss
   match "posts/*" compilePosts
   match (fromList ["about.markdown"]) compilePages
+  create ["archive.html"] compileArchive
   match "templates/*" $ compile templateCompiler
 
 compileIndex :: Rules ()
@@ -43,5 +44,19 @@ compilePages = do
     >>= loadAndApplyTemplate "templates/default.html" defaultContext
     >>= relativizeUrls
 
+compileArchive :: Rules ()
+compileArchive = do
+  route idRoute
+  compile $ do
+    posts <- loadAll "posts/*" >>= recentFirst
+    let archiveCtx =
+          listField "posts" postCtx (return posts) `mappend`
+          constField "title" "Archive"             `mappend`
+          defaultContext
+    makeItem ""
+      >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
+      >>= loadAndApplyTemplate "templates/default.html" archiveCtx
+      >>= relativizeUrls
+
 postCtx :: Context String
 postCtx = dateField "date" "%B %e, %Y" `mappend` defaultContext
diff --git a/templates/archive.html b/templates/archive.html
new file mode 100644 (file)
index 0000000..4d91f5b
--- /dev/null
@@ -0,0 +1,2 @@
+Posts from The Tar Pit:
+$partial("templates/post-list.html")$
index 4f248a0..781c585 100644 (file)
@@ -16,7 +16,7 @@
                </div>
                <div id="navigation">
                        <a href="/about.html">About</a>
-                       <a href="">Archive</a>
+                       <a href="/archive.html">Archive</a>
                        <a href="">RSS</a>
                </div>
        </div>