Permalink
Browse files

Clean urls without html extension

  • Loading branch information...
alexanderlobov committed Feb 4, 2017
1 parent 6812e6a commit fb9446a5ad238c041c407cb2e7e35a1f9aeab491
Showing with 42 additions and 5 deletions.
  1. +1 −0 homepage.cabal
  2. +38 −2 site.hs
  3. +1 −1 templates/default.html
  4. +2 −2 templates/post.html
View
@@ -7,5 +7,6 @@ executable site
main-is: site.hs
build-depends: base == 4.*
, hakyll == 4.7.*
, filepath
ghc-options: -threaded
default-language: Haskell2010
View
40 site.hs
@@ -2,6 +2,13 @@
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import System.FilePath.Posix ( takeDirectory
, takeBaseName
, (</>)
, splitFileName
)
import Data.List (isInfixOf)
import Control.Applicative (empty)
config :: Configuration
@@ -21,14 +28,15 @@ main = hakyllWith config $ do
compile compressCssCompiler
match "posts/*" $ do
route $ setExtension "html"
route niceRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
>>= removeIndexHtml
create ["archive.html"] $ do
route idRoute
route niceRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let archiveCtx =
@@ -40,6 +48,7 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
>>= removeIndexHtml
match "index.html" $ do
@@ -55,6 +64,7 @@ main = hakyllWith config $ do
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
>>= removeIndexHtml
match "templates/*" $ compile templateCompiler
@@ -63,4 +73,30 @@ main = hakyllWith config $ do
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
myUrlField `mappend`
defaultContext
myUrlField :: Context a
myUrlField = field "myurl" $
fmap (maybe empty $ removeIndexStr . toUrl) . getRoute . itemIdentifier
niceRoute :: Routes
niceRoute = customRoute createIndexRoute
where createIndexRoute identifier =
takeDirectory p </> takeBaseName p </> "index.html"
where p = toFilePath identifier
removeIndexHtml :: Item String -> Compiler (Item String)
removeIndexHtml item = return $ fmap (withUrls removeIndexStr) item
removeIndexStr :: String -> String
removeIndexStr url = case splitFileName url of
(dir, "index.html") | isLocal dir -> dir
| otherwise -> url
_ -> url
where
isLocal :: String -> Bool
isLocal uri = not ("://" `isInfixOf` uri)
View
@@ -44,7 +44,7 @@
<a href="/">alexanderlobov</a>
</div>
<div id="navigation">
<a href="/archive.html">Archive</a>
<a href="/archive/">Archive</a>
</div>
</div>
View
@@ -10,8 +10,8 @@
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'http://alexanderlobov.ru$url$';
this.page.identifier = '$url$';
this.page.url = 'http://alexanderlobov.ru$myurl$';
this.page.identifier = '$myurl$';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');

0 comments on commit fb9446a

Please sign in to comment.