Compatibility with Octopress site.

Don't break urls.
 1. New Route function which generates routes compatible with old blog.
 2. Renamed posts folder to blog.
This commit is contained in:
Dhananjay Balan committed 2017-01-31 20:44:01 +01:00
1 parent f1bf5b6c0d
commit 3a30fb8a07
49 files changed
+25 -4

No files matched your search

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
View File
@@ -7,5 +7,7 @@ executable site
main-is: site.hs main-is: site.hs
build-depends: base == 4.* build-depends: base == 4.*
, hakyll == 4.9.* , hakyll == 4.9.*
, filepath >= 1.4
, regex-compat
ghc-options: -threaded ghc-options: -threaded
default-language: Haskell2010 default-language: Haskell2010
+23 -4
View File
@@ -2,6 +2,10 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend) import Data.Monoid (mappend)
import Hakyll import Hakyll
import Hakyll.Core.Identifier (toFilePath)
import System.FilePath
import Text.Regex (splitRegex, mkRegex)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@@ -21,8 +25,8 @@ main = hakyll $ do
>>= loadAndApplyTemplate "templates/default.html" defaultContext >>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls >>= relativizeUrls
match "posts/*" $ do match "blog/*" $ do
route $ setExtension "html" route $ octopressRoute
compile $ pandocCompiler compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx >>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx >>= loadAndApplyTemplate "templates/default.html" postCtx
@@ -31,7 +35,7 @@ main = hakyll $ do
create ["archive.html"] $ do create ["archive.html"] $ do
route idRoute route idRoute
compile $ do compile $ do
posts <- recentFirst =<< loadAll "posts/*" posts <- recentFirst =<< loadAll "blog/*"
let archiveCtx = let archiveCtx =
listField "posts" postCtx (return posts) `mappend` listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend` constField "title" "Archives" `mappend`
@@ -46,7 +50,7 @@ main = hakyll $ do
match "index.html" $ do match "index.html" $ do
route idRoute route idRoute
compile $ do compile $ do
posts <- recentFirst =<< loadAll "posts/*" posts <- recentFirst =<< loadAll "blog/*"
let indexCtx = let indexCtx =
listField "posts" postCtx (return posts) `mappend` listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend` constField "title" "Home" `mappend`
@@ -65,3 +69,18 @@ postCtx :: Context String
postCtx = postCtx =
dateField "date" "%B %e, %Y" `mappend` dateField "date" "%B %e, %Y" `mappend`
defaultContext defaultContext
-- octopress compatible routes
octopressRoute :: Routes
octopressRoute = customRoute $ octoMangaling
octoMangaling :: Identifier -> FilePath
octoMangaling pathId = base </> year </> month </> day </> post </> "index.html"
where
p = toFilePath pathId
base = takeDirectory p
seps = splitRegex (mkRegex "-") $ takeBaseName p
year:month:day:xs = seps
post = tail $ foldl (\a b -> a ++ "-" ++ b) "" xs