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:
parent
f1bf5b6c0d
commit
3a30fb8a07
blog
2011-03-21-long-time.markdown2011-03-24-school-memories.markdown2011-03-26-earth-hour-official-video.markdown2011-03-26-firefox.markdown2011-04-01-compski-night-firends-and-fun.markdown2011-04-03-happy-birthday-colin.markdown2011-04-05-sharing-the-posterous-way.markdown2011-04-19-bed-of-roses.markdown2011-04-20-happy.markdown2011-04-28-adept.markdown2011-05-02-the-story-of-linux.markdown2011-05-07-gsoc-2011-i-am-in.markdown2011-05-14-welcome-to-acm-courtesy-of-google.markdown2011-05-28-hmm-vacation-work-time.markdown2011-06-04-distributed-computing.markdown2011-06-05-random-reverbations.markdown2011-07-19-birthday-food-for-thought.markdown2011-08-23-sigsegv.markdown2011-08-30-what-you-do-when-you-get-a-free-day.markdown2011-09-10-good-to-be-back.markdown2011-09-11-nothing-else-matters.markdown2011-09-16-crazy.markdown2011-10-11-ffmepg-nokia-7210-video-clips.markdown2011-10-11-latex-on-the-go.markdown2011-10-28-falling-slowly.markdown2012-01-09-arrow-keys-input-in-python.markdown2012-03-18-progress-bar-in-mercurial-pushpull.markdown2012-03-29-thamarassery-mountain-pass-wayanad.markdown2012-11-21-netbsd-chronicles.markdown2012-11-24-my-perfect-terminal.markdown2012-12-06-rooting-a-nexus-7.markdown2012-12-12-name-your-servers.markdown2013-01-01-a-thank-you-note.markdown2013-05-03-new-home.markdown2013-05-28-getting-started-with-rtems-on-archlinux.markdown2013-05-28-summer-of-code-2013.markdown2013-06-23-debugging-rtems-with-gdb.markdown2014-08-16-automatic-log-in-for-act-broadband.markdown2015-02-21-syslog-on-mac-os-x-cheat-sheet.markdown2015-03-28-state-of-terminal-2015-edition.markdown2015-03-29-notes-on-cgo.markdown2015-06-30-static-site-generators.markdown2015-08-22-recursion.markdown2015-12-01-a-random-rant.markdown2015-12-28-swanthathralokam.markdown2016-01-14-golang-shorthand-operator-allows-accidental-shadowing-of-variable.markdown2016-03-31-finding-a-programming-job.markdown
blogng.cabalsite.hs@ -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
|
||||||
|
27
site.hs
27
site.hs
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user