site.hs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/*.md"
  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. post <- fmap (head) recentFirst =<< loadAll "posts/*.md"
  57. pandocCompiler
  58. >>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
  59. >>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
  60. >>= relativizeUrls
  61. match "index.html" $ do
  62. route idRoute
  63. compile $ do
  64. posts <- recentFirst =<< loadAll "posts/*"
  65. let indexCtx =
  66. listField "posts" postCtx (return posts) `mappend`
  67. constField "title" "Home" `mappend`
  68. defaultContext
  69. getResourceBody
  70. >>= applyAsTemplate indexCtx
  71. >>= loadAndApplyTemplate "templates/default.html" indexCtx
  72. >>= relativizeUrls
  73. match "templates/*" $ compile templateBodyCompiler
  74. --------------------------------------------------------------------------------
  75. postCtx :: Context String
  76. postCtx =
  77. dateField "date" "%B %e, %Y" `mappend`
  78. defaultContext
  79. postCtxWithTags :: Tags -> Context String
  80. postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx