By | ~fr33domlover |
At | 2017-12-08 |
Title | Route pages as index.html so that URLs don't contain file extension |
Description |
Edit file index.html 33188 → 33188
11 11 <p>I've reproduced a list of recent posts here for your reading pleasure:</p>
12 12 13 13 <h2>Posts</h2>
14 14 $partial("templates/post-list.html")$
15 15 - 16 <p>…or you can find more in the <a href="/archive.html">archives</a>.</p>
+ 16 <p>…or you can find more in the <a href="/archive">archives</a>.</p>
… … … … Edit file site.cabal 33188 → 33188
3 3 build-type: Simple
4 4 cabal-version: >= 1.10
5 5 6 6 executable site
7 7 main-is: site.hs
- 8 build-depends: base == 4.*
- 9 , hakyll == 4.9.*
+ 8 build-depends: base == 4.*
+ 9 , filepath
+ 10 , hakyll == 4.9.*
10 11 ghc-options: -threaded
11 12 default-language: Haskell2010
… … … … Edit file site.hs 33188 → 33188
- 1 --------------------------------------------------------------------------------
+ 1 {- Written in 2017 by fr33domlover <fr33domlover@riseup.net>.
+ 2 -
+ 3 - ♡ Copying is an act of love. Please copy, reuse and share.
+ 4 -
+ 5 - The author(s) have dedicated all copyright and related and neighboring
+ 6 - rights to this software to the public domain worldwide. This software is
+ 7 - distributed without any warranty.
+ 8 -
+ 9 - You should have received a copy of the CC0 Public Domain Dedication along
+ 10 - with this software. If not, see
+ 11 - <http://creativecommons.org/publicdomain/zero/1.0/>.
+ 12 -}
+ 13 2 14 {-# LANGUAGE OverloadedStrings #-}
- 3 import Data.Monoid (mappend)
- 4 import Hakyll
- 5 - 6 - 7 --------------------------------------------------------------------------------
+ 15 + 16 import Data.Monoid (mappend)
+ 17 import Hakyll
+ 18 import System.FilePath ((</>), dropExtension)
+ 19 + 20 pageRoute :: Routes
+ 21 pageRoute = customRoute $ (</> "index.html") . dropExtension . toFilePath
+ 22 + 23 postCtx :: Context String
+ 24 postCtx =
+ 25 dateField "date" "%B %e, %Y" `mappend`
+ 26 defaultContext
+ 27 8 28 main :: IO ()
9 29 main = hakyll $ do
10 30 match "images/*" $ do
11 31 route idRoute
12 32 compile copyFileCompiler
… … … … 14 34 match "css/*" $ do
15 35 route idRoute
16 36 compile compressCssCompiler
17 37 18 38 match (fromList ["about.rst", "contact.markdown"]) $ do
- 19 route $ setExtension "html"
+ 39 route pageRoute
20 40 compile $ pandocCompiler
21 41 >>= loadAndApplyTemplate "templates/default.html" defaultContext
22 42 >>= relativizeUrls
23 43 24 44 match "posts/*" $ do
- 25 route $ setExtension "html"
+ 45 route pageRoute
26 46 compile $ pandocCompiler
27 47 >>= loadAndApplyTemplate "templates/post.html" postCtx
28 48 >>= loadAndApplyTemplate "templates/default.html" postCtx
29 49 >>= relativizeUrls
30 50 31 51 create ["archive.html"] $ do
- 32 route idRoute
+ 52 route pageRoute
33 53 compile $ do
34 54 posts <- recentFirst =<< loadAll "posts/*"
35 55 let archiveCtx =
36 56 listField "posts" postCtx (return posts) `mappend`
37 57 constField "title" "Archives" `mappend`
… … … … 40 60 makeItem ""
41 61 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
42 62 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
43 63 >>= relativizeUrls
44 64 - 45 46 65 match "index.html" $ do
47 66 route idRoute
48 67 compile $ do
49 68 posts <- recentFirst =<< loadAll "posts/*"
50 69 let indexCtx =
… … … … 56 75 >>= applyAsTemplate indexCtx
57 76 >>= loadAndApplyTemplate "templates/default.html" indexCtx
58 77 >>= relativizeUrls
59 78 60 79 match "templates/*" $ compile templateBodyCompiler
- 61 - 62 - 63 --------------------------------------------------------------------------------
- 64 postCtx :: Context String
- 65 postCtx =
- 66 dateField "date" "%B %e, %Y" `mappend`
- 67 defaultContext
… … … …