site.hs 2.7 KB

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