misconstruedⓂ️monologues https://blog.bemoe.online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.8KB

  1. --------------------------------------------------------------------------------
  2. {-# LANGUAGE OverloadedStrings #-}
  3. import Data.Monoid ((<>))
  4. import Hakyll
  5. import Hakyll.Favicon (faviconsRules, faviconsField)
  6. --------------------------------------------------------------------------------
  7. muraConf :: Configuration
  8. muraConf = defaultConfiguration
  9. { destinationDirectory = "_http"
  10. , storeDirectory = "_store"
  11. , tmpDirectory = "_tmp"
  12. , providerDirectory = "_input"
  13. }
  14. -- Our default context for pages
  15. ctx :: Context String
  16. ctx = defaultContext <>
  17. faviconsField
  18. main :: IO ()
  19. main = hakyllWith muraConf $ do
  20. faviconsRules "icons/favicon.svg"
  21. match "images/*" $ do
  22. route idRoute
  23. compile copyFileCompiler
  24. match "css/*" $ do
  25. route idRoute
  26. compile compressCssCompiler
  27. match (fromList ["about.md", "contact.md", "links.md"]) $ do
  28. route $ setExtension "html"
  29. compile $ pandocCompiler
  30. >>= loadAndApplyTemplate "templates/default.html" ctx
  31. >>= relativizeUrls
  32. -- Render Atom + Rss feeds
  33. create ["atom.xml"] $ do
  34. route idRoute
  35. (compileFeed renderAtom)
  36. create ["rss.xml"] $ do
  37. route idRoute
  38. (compileFeed renderRss)
  39. match "posts/*" $ do
  40. route $ setExtension "html"
  41. compile $ pandocCompiler
  42. >>= loadAndApplyTemplate "templates/post.html" postCtx
  43. >>= saveSnapshot "content"
  44. >>= loadAndApplyTemplate "templates/default.html" postCtx
  45. >>= relativizeUrls
  46. create ["archive.html"] $ do
  47. route idRoute
  48. compile $ do
  49. posts <- recentFirst =<< loadAll "posts/*"
  50. let archiveCtx =
  51. listField "posts" postCtx (return posts) <>
  52. constField "title" "archives" <>
  53. ctx
  54. makeItem ""
  55. >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
  56. >>= loadAndApplyTemplate "templates/default.html" archiveCtx
  57. >>= relativizeUrls
  58. match "index.html" $ do
  59. route idRoute
  60. compile $ do
  61. -- posts <- recentFirst =<< loadAll "posts/*"
  62. posts <- (return . (take 7))
  63. =<< recentFirst
  64. =<< loadAll "posts/*"
  65. let indexCtx =
  66. listField "posts" postCtx (return posts) <>
  67. constField "title" "ホームページ" <>
  68. ctx
  69. getResourceBody
  70. >>= applyAsTemplate indexCtx
  71. >>= loadAndApplyTemplate "templates/index.html" indexCtx
  72. >>= loadAndApplyTemplate "templates/default.html" indexCtx
  73. >>= relativizeUrls
  74. match "templates/*" $ compile templateBodyCompiler
  75. --------------------------------------------------------------------------------
  76. ---- Agnememnon the Fuck-Upperer - Conquerer of Small Type Declarations
  77. compileFeed ::
  78. (FeedConfiguration
  79. -> Context String
  80. -> [Item String]
  81. -> Compiler (Item String)
  82. ) -> Rules ()
  83. -- For those left alive, this abstracts out creating
  84. -- Atom and RSS feeds
  85. compileFeed f = compile $ do
  86. let feedCtx = postCtx <>
  87. bodyField "description"
  88. posts <- fmap (take 10) . recentFirst
  89. =<< loadAllSnapshots "posts/*" "content"
  90. f feedConfig feedCtx posts
  91. -- The configuration for our Atom/RSS feeds
  92. feedConfig :: FeedConfiguration
  93. feedConfig = FeedConfiguration {
  94. feedTitle = "be 萌え online blog"
  95. , feedDescription = "a blog of misconstruedⓂ️monologues"
  96. , feedAuthorName = "i am the walrus"
  97. , feedAuthorEmail = "blog@bemoe.online"
  98. , feedRoot = "https://blog.bemoe.online"
  99. }
  100. postCtx :: Context String
  101. postCtx =
  102. dateField "date" "%Y年%_m月%e日" <>
  103. ctx