site.hs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "resume_jmelesky.pdf" $ do
  15. route idRoute
  16. compile copyFileCompiler
  17. match "*.md" $ do
  18. route $ setExtension "html"
  19. compile $ pandocCompiler
  20. >>= loadAndApplyTemplate "templates/default.html" defaultContext
  21. >>= relativizeUrls
  22. tags <- buildTags "posts/*.md" (fromCapture "tags/*.html")
  23. tagsRules tags $ \tag pattern -> do
  24. let title = "Posts tagged \"" ++ tag ++ "\""
  25. route idRoute
  26. compile $ do
  27. posts <- recentFirst =<< loadAll pattern
  28. let ctx = constField "title" title
  29. `mappend` listField "posts" postCtx (return posts)
  30. `mappend` defaultContext
  31. makeItem ""
  32. >>= loadAndApplyTemplate "templates/tag.html" ctx
  33. >>= loadAndApplyTemplate "templates/default.html" ctx
  34. >>= relativizeUrls
  35. match "posts/*.md" $ do
  36. route $ setExtension "html"
  37. compile $ pandocCompiler
  38. >>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
  39. >>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
  40. >>= relativizeUrls
  41. create ["archive.html"] $ do
  42. route idRoute
  43. compile $ do
  44. posts <- recentFirst =<< loadAll "posts/*"
  45. let archiveCtx =
  46. listField "posts" postCtx (return posts) `mappend`
  47. constField "title" "Archives" `mappend`
  48. defaultContext
  49. makeItem ""
  50. >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
  51. >>= loadAndApplyTemplate "templates/default.html" archiveCtx
  52. >>= relativizeUrls
  53. create ["new_index.html"] $ do
  54. route idRoute
  55. compile $ do
  56. posts <- recentFirst =<< loadAll "posts/*"
  57. let post =
  58. head (return posts)
  59. pandocCompiler
  60. >>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
  61. >>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
  62. >>= relativizeUrls
  63. match "index.html" $ do
  64. route idRoute
  65. compile $ do
  66. posts <- recentFirst =<< loadAll "posts/*"
  67. let indexCtx =
  68. listField "posts" postCtx (return posts) `mappend`
  69. constField "title" "Home" `mappend`
  70. defaultContext
  71. getResourceBody
  72. >>= applyAsTemplate indexCtx
  73. >>= loadAndApplyTemplate "templates/default.html" indexCtx
  74. >>= relativizeUrls
  75. match "templates/*" $ compile templateBodyCompiler
  76. --------------------------------------------------------------------------------
  77. postCtx :: Context String
  78. postCtx =
  79. dateField "date" "%B %e, %Y" `mappend`
  80. defaultContext
  81. postCtxWithTags :: Tags -> Context String
  82. postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx