2017-01-22 21:30:42 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
import Data.Monoid (mappend)
|
|
|
|
import Hakyll
|
2017-01-31 14:52:21 +00:00
|
|
|
import Hakyll.Core.Identifier (toFilePath)
|
2019-01-13 00:43:27 +00:00
|
|
|
import Hakyll.Web.Feed
|
2017-01-31 14:52:21 +00:00
|
|
|
import System.FilePath
|
|
|
|
import Text.Regex (splitRegex, mkRegex)
|
|
|
|
|
2017-01-22 21:30:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2017-02-02 14:42:52 +00:00
|
|
|
config :: Configuration
|
2019-01-08 20:46:39 +00:00
|
|
|
{-
|
|
|
|
deploy command expects www to point to web server - this is the current config
|
|
|
|
Host www
|
|
|
|
Hostname 10.1.10.30
|
|
|
|
User root
|
|
|
|
ProxyJump dj@ares.dbalan.in
|
|
|
|
-}
|
2017-02-02 14:42:52 +00:00
|
|
|
config = defaultConfiguration {
|
2019-01-08 20:46:39 +00:00
|
|
|
destinationDirectory = "public"
|
|
|
|
, deployCommand = "rsync -vrP public/ www:/usr/local/www/nginx/blog/"
|
2017-02-02 14:42:52 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 00:43:27 +00:00
|
|
|
feedConfig :: FeedConfiguration
|
|
|
|
feedConfig = FeedConfiguration {
|
|
|
|
feedTitle = "Binary Strolls"
|
|
|
|
, feedDescription = "Blag"
|
|
|
|
, feedAuthorName = "Dhananjay Balan"
|
|
|
|
, feedRoot = "https://blog.dbalan.in"
|
|
|
|
, feedAuthorEmail = "blog@dbalan.in"
|
|
|
|
}
|
|
|
|
|
2017-01-22 21:30:42 +00:00
|
|
|
main :: IO ()
|
2017-02-02 14:42:52 +00:00
|
|
|
main = hakyllWith config $ do
|
2019-01-28 21:42:01 +00:00
|
|
|
tags <- buildTags "blog/*" (fromCapture "tags/*.html")
|
2017-02-01 15:38:12 +00:00
|
|
|
|
2017-01-22 21:30:42 +00:00
|
|
|
match "images/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
|
|
|
match "css/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile compressCssCompiler
|
|
|
|
|
2019-03-09 17:53:15 +00:00
|
|
|
match "fonts/crimson/*" $ do
|
2017-01-31 21:42:20 +00:00
|
|
|
route $ idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
2019-03-09 17:53:15 +00:00
|
|
|
match "fonts/lato/*" $ do
|
2017-01-31 21:42:20 +00:00
|
|
|
route $ idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
2017-02-13 22:29:23 +00:00
|
|
|
match "notes/*" $ do
|
2018-03-04 21:56:07 +00:00
|
|
|
route $ idRoute
|
|
|
|
compile copyFileCompiler
|
2017-02-13 22:29:23 +00:00
|
|
|
|
2017-01-31 14:52:21 +00:00
|
|
|
match "blog/*" $ do
|
|
|
|
route $ octopressRoute
|
2017-01-22 21:30:42 +00:00
|
|
|
compile $ pandocCompiler
|
2019-01-28 21:42:01 +00:00
|
|
|
>>= loadAndApplyTemplate "templates/post.html" (postCtxWTags tags)
|
2019-01-13 00:43:27 +00:00
|
|
|
>>= saveSnapshot "content"
|
2019-01-28 21:42:01 +00:00
|
|
|
>>= loadAndApplyTemplate "templates/default.html" (postCtxWTags tags)
|
2017-01-22 21:30:42 +00:00
|
|
|
>>= relativizeUrls
|
|
|
|
|
|
|
|
match "index.html" $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
2017-01-31 14:52:21 +00:00
|
|
|
posts <- recentFirst =<< loadAll "blog/*"
|
2017-01-22 21:30:42 +00:00
|
|
|
let indexCtx =
|
2017-01-31 21:42:20 +00:00
|
|
|
listField "posts" postCtx (return $ take 5 posts) `mappend`
|
2017-01-22 21:30:42 +00:00
|
|
|
constField "title" "Home" `mappend`
|
2017-02-01 15:38:12 +00:00
|
|
|
tagsField "tags" tags `mappend`
|
2017-01-22 21:30:42 +00:00
|
|
|
defaultContext
|
|
|
|
|
|
|
|
getResourceBody
|
|
|
|
>>= applyAsTemplate indexCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" indexCtx
|
|
|
|
>>= relativizeUrls
|
|
|
|
|
2019-01-13 00:43:27 +00:00
|
|
|
create ["archive.html"] $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
posts <- recentFirst =<< loadAll "blog/*"
|
|
|
|
let archiveCtx =
|
|
|
|
listField "posts" postCtx (return posts) `mappend`
|
|
|
|
constField "title" "Archives" `mappend`
|
|
|
|
defaultContext
|
|
|
|
|
|
|
|
makeItem ""
|
|
|
|
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
|
|
|
|
>>= relativizeUrls
|
|
|
|
|
2019-01-28 21:42:01 +00:00
|
|
|
-- tags!
|
|
|
|
tagsRules tags $ \tag pattern -> do
|
|
|
|
let title = "Posts tagged \"" ++ tag ++ "\""
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
posts <- recentFirst =<< loadAll pattern
|
|
|
|
let ctx = constField "title" title
|
|
|
|
`mappend` listField "posts" postCtx (return posts)
|
|
|
|
`mappend` defaultContext
|
|
|
|
|
|
|
|
makeItem ""
|
|
|
|
>>= loadAndApplyTemplate "templates/tag.html" ctx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" ctx
|
|
|
|
>>= relativizeUrls
|
|
|
|
|
2019-01-13 00:43:27 +00:00
|
|
|
create ["atom.xml"] $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
posts <- fmap (take 5) . recentFirst =<< loadAllSnapshots "blog/*" "content"
|
2019-01-13 00:57:16 +00:00
|
|
|
let feedCtx = postCtx `mappend` bodyField "description"
|
2019-01-13 00:43:27 +00:00
|
|
|
renderAtom feedConfig feedCtx posts
|
2017-01-22 21:30:42 +00:00
|
|
|
match "templates/*" $ compile templateBodyCompiler
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2017-02-01 15:38:12 +00:00
|
|
|
extractTags :: Rules Tags
|
|
|
|
extractTags = do
|
|
|
|
tags <- buildTags ("blogs/**" .&&. hasNoVersion) $ fromCapture "tags/*.html"
|
|
|
|
return $ sortTagsBy caseInsensitiveTags tags
|
|
|
|
|
2019-01-28 21:42:01 +00:00
|
|
|
postCtxWTags :: Tags -> Context String
|
|
|
|
postCtxWTags tags = tagsField "tags" tags <> postCtx
|
|
|
|
|
2017-01-22 21:30:42 +00:00
|
|
|
postCtx :: Context String
|
|
|
|
postCtx =
|
|
|
|
dateField "date" "%B %e, %Y" `mappend`
|
|
|
|
defaultContext
|
2017-01-31 14:52:21 +00:00
|
|
|
|
|
|
|
-- 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
|