site.hs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. --------------------------------------------------------------------------------
  2. {-# LANGUAGE OverloadedStrings #-}
  3. import Data.Monoid (mappend)
  4. import Hakyll
  5. import qualified Data.Set as S
  6. import Text.Pandoc
  7. --------------------------------------------------------------------------------
  8. main :: IO ()
  9. main = hakyll $ do
  10. match "images/*" $ do
  11. route idRoute
  12. compile copyFileCompiler
  13. match "images/*/*" $ do
  14. route idRoute
  15. compile copyFileCompiler
  16. match "assets/*" $ do
  17. route idRoute
  18. compile copyFileCompiler
  19. match "scripts/*" $ do
  20. route idRoute
  21. compile copyFileCompiler
  22. match "talks/*/*" $ do
  23. route idRoute
  24. compile copyFileCompiler
  25. match "talks/*/*/*" $ do
  26. route idRoute
  27. compile copyFileCompiler
  28. match "talks/*/*/*/*" $ do
  29. route idRoute
  30. compile copyFileCompiler
  31. match "stuff/zombie_protagonist/Zombie.swf" $ do
  32. route idRoute
  33. compile copyFileCompiler
  34. match "stuff/zombie_protagonist/library/mp3/*.mp3" $ do
  35. route idRoute
  36. compile copyFileCompiler
  37. match "css/*" $ do
  38. route idRoute
  39. compile compressCssCompiler
  40. match "resume_jmelesky.pdf" $ do
  41. route idRoute
  42. compile copyFileCompiler
  43. match "stuff/*.md" $ do
  44. route $ setExtension "html"
  45. compile $ siteCompiler
  46. >>= loadAndApplyTemplate "templates/default.html" defaultContext
  47. >>= relativizeUrls
  48. match "stuff/*/*.md" $ do
  49. route $ setExtension "html"
  50. compile $ siteCompiler
  51. >>= loadAndApplyTemplate "templates/default.html" defaultContext
  52. >>= relativizeUrls
  53. match "*.md" $ do
  54. route $ setExtension "html"
  55. compile $ siteCompiler
  56. >>= loadAndApplyTemplate "templates/default.html" defaultContext
  57. >>= relativizeUrls
  58. tags <- buildTags "posts/*.md" (fromCapture "tags/*.html")
  59. tagsRules tags $ \tag pattern -> do
  60. let title = "Posts tagged \"" ++ tag ++ "\""
  61. route idRoute
  62. compile $ do
  63. posts <- recentFirst =<< loadAll pattern
  64. let ctx = constField "title" title
  65. `mappend` listField "posts" postCtx (return posts)
  66. `mappend` defaultContext
  67. makeItem ""
  68. >>= loadAndApplyTemplate "templates/tag.html" ctx
  69. >>= loadAndApplyTemplate "templates/default.html" ctx
  70. >>= relativizeUrls
  71. match "posts/*.md" $ do
  72. route $ setExtension "html"
  73. compile $ siteCompiler
  74. >>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
  75. >>= saveSnapshot "post_content"
  76. >>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
  77. >>= relativizeUrls
  78. create ["archive.html"] $ do
  79. route idRoute
  80. compile $ do
  81. posts <- recentFirst =<< loadAll "posts/*.md"
  82. let archiveCtx =
  83. listField "posts" postCtx (return posts) `mappend`
  84. constField "title" "Archives" `mappend`
  85. defaultContext
  86. makeItem ""
  87. >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
  88. >>= loadAndApplyTemplate "templates/default.html" archiveCtx
  89. >>= relativizeUrls
  90. create ["index.html"] $ do
  91. route idRoute
  92. compile $ do
  93. post <- fmap head . recentFirst =<< loadAllSnapshots "posts/*.md" "post_content"
  94. loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags) post
  95. >>= relativizeUrls
  96. >>= changeIdentifier "index.html"
  97. match "templates/*" $ compile templateBodyCompiler
  98. --------------------------------------------------------------------------------
  99. postCtx :: Context String
  100. postCtx =
  101. dateField "date" "%B %e, %Y" `mappend`
  102. defaultContext
  103. postCtxWithTags :: Tags -> Context String
  104. postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx
  105. changeIdentifier :: Identifier -> Item a -> Compiler (Item a)
  106. changeIdentifier idt item = return (itemSetIdentifier idt item)
  107. itemSetIdentifier :: Identifier -> Item a -> Item a
  108. itemSetIdentifier x (Item _ i) = Item x i
  109. siteCompiler :: Compiler (Item String)
  110. siteCompiler =
  111. let addExtensions = [Ext_tex_math_dollars, Ext_tex_math_double_backslash,
  112. Ext_latex_macros, Ext_footnotes, Ext_inline_notes]
  113. wExtensions = foldr S.insert (writerExtensions defaultHakyllWriterOptions) addExtensions
  114. rExtensions = foldr S.insert (readerExtensions defaultHakyllReaderOptions) addExtensions
  115. siteWriterOptions = defaultHakyllWriterOptions {
  116. writerExtensions = wExtensions,
  117. writerHTMLMathMethod = MathJax ""
  118. }
  119. siteReaderOptions = defaultHakyllReaderOptions {
  120. readerExtensions = rExtensions
  121. }
  122. in pandocCompilerWith siteReaderOptions siteWriterOptions