site.hs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --------------------------------------------------------------------------------
  2. {-# LANGUAGE OverloadedStrings #-}
  3. import Data.Monoid (mappend)
  4. import Hakyll
  5. --------------------------------------------------------------------------------
  6. main :: IO ()
  7. main = hakyll $ do
  8. match "images/*" $ do
  9. route idRoute
  10. compile copyFileCompiler
  11. match "css/*" $ do
  12. route idRoute
  13. compile compressCssCompiler
  14. match (fromList ["about.rst", "contact.markdown"]) $ do
  15. route $ setExtension "html"
  16. compile $ pandocCompiler
  17. >>= loadAndApplyTemplate "templates/default.html" defaultContext
  18. >>= relativizeUrls
  19. tags <- buildTags "posts/*" (fromCapture "tags/*.html")
  20. tagsRules tags $ \tag pattern -> do
  21. let title = "Posts tagged \"" ++ tag ++ "\""
  22. route idRoute
  23. compile $ do
  24. posts <- recentFirst =<< loadAll pattern
  25. let ctx = constField "title" title
  26. `mappend` listField "posts" postCtx (return posts)
  27. `mappend` defaultContext
  28. makeItem ""
  29. >>= loadAndApplyTemplate "templates/tag.html" ctx
  30. >>= loadAndApplyTemplate "templates/default.html" ctx
  31. >>= relativizeUrls
  32. match "posts/*" $ do
  33. route $ setExtension "html"
  34. compile $ pandocCompiler
  35. >>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
  36. >>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
  37. >>= relativizeUrls
  38. create ["archive.html"] $ do
  39. route idRoute
  40. compile $ do
  41. posts <- recentFirst =<< loadAll "posts/*"
  42. let archiveCtx =
  43. listField "posts" postCtx (return posts) `mappend`
  44. constField "title" "Archives" `mappend`
  45. defaultContext
  46. makeItem ""
  47. >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
  48. >>= loadAndApplyTemplate "templates/default.html" archiveCtx
  49. >>= relativizeUrls
  50. match "index.html" $ do
  51. route idRoute
  52. compile $ do
  53. posts <- recentFirst =<< loadAll "posts/*"
  54. let indexCtx =
  55. listField "posts" postCtx (return posts) `mappend`
  56. constField "title" "Home" `mappend`
  57. defaultContext
  58. getResourceBody
  59. >>= applyAsTemplate indexCtx
  60. >>= loadAndApplyTemplate "templates/default.html" indexCtx
  61. >>= relativizeUrls
  62. match "templates/*" $ compile templateBodyCompiler
  63. --------------------------------------------------------------------------------
  64. postCtx :: Context String
  65. postCtx =
  66. dateField "date" "%B %e, %Y" `mappend`
  67. defaultContext
  68. postCtxWithTags :: Tags -> Context String
  69. postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx