summaryrefslogtreecommitdiff
path: root/site.hs
diff options
context:
space:
mode:
authorjamie <git@skilet.ro>2025-10-15 08:52:08 +0100
committerjamie <git@skilet.ro>2025-10-15 08:52:08 +0100
commit6d8a7df95f53ef33691f70759489bd7e961a9973 (patch)
tree89f94f7f6b4b625e5a87244f6e68314bbc0c9be7 /site.hs
parent49b15415e3d48d6e80a21d644fc3762fecfba0f5 (diff)
refactor: some "small" changes
Diffstat (limited to 'site.hs')
-rw-r--r--site.hs95
1 files changed, 42 insertions, 53 deletions
diff --git a/site.hs b/site.hs
index 832409e..7c9980b 100644
--- a/site.hs
+++ b/site.hs
@@ -1,37 +1,36 @@
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-import Control.Exception (SomeException, catch)
-import Data.List (isInfixOf, sortBy)
-import Data.Monoid (mappend)
-import Hakyll
-import Hakyll.Web.Sass (sassCompiler)
-import System.Environment
-import System.FilePath.Posix (splitFileName, takeBaseName,
- takeDirectory, (</>))
-import System.Process
+import Control.Exception
+import Data.List
+import Data.Monoid
+import Hakyll
+import Hakyll.Web.Sass
+import System.Environment
+import System.FilePath.Posix
+import System.Process
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
- match "images/*" $ do
- route idRoute
- compile copyFileCompiler
+ match "templates/*" $ compile templateBodyCompiler
- match "css/*.css" $ do
+ match ("assets/images/*" .||. "assets/fonts/*") $ do
route idRoute
- compile compressCssCompiler
+ compile copyFileCompiler
- match "css/*.scss" $ do
+ match "assets/css/*" $ do
route $ setExtension "css"
let compressCssItem = fmap compressCss
compile (compressCssItem <$> sassCompiler)
- match "404.html" $ do
- route idRoute
+ match "posts/*" $ do
+ route prettyRoute
compile $
pandocCompiler
- >>= loadAndApplyTemplate "templates/default.html" defaultCtx
+ >>= loadAndApplyTemplate "templates/post.html" postCtx
+ >>= saveSnapshot "content"
+ >>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
>>= removeIndexHtml
@@ -43,13 +42,11 @@ main = hakyll $ do
>>= relativizeUrls
>>= removeIndexHtml
- match "posts/*" $ do
- route prettyRoute
+ match "404.html" $ do
+ route idRoute
compile $
pandocCompiler
- >>= loadAndApplyTemplate "templates/post.html" postCtx
- >>= saveSnapshot "content"
- >>= loadAndApplyTemplate "templates/default.html" postCtx
+ >>= loadAndApplyTemplate "templates/default.html" defaultCtx
>>= relativizeUrls
>>= removeIndexHtml
@@ -59,8 +56,8 @@ main = hakyll $ do
posts <- recentFirst =<< loadAll "posts/*"
let archiveCtx =
listField "posts" postCtx (return posts)
- `mappend` constField "title" "Archives"
- `mappend` defaultCtx
+ <> constField "title" "Archives"
+ <> defaultCtx
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
@@ -68,10 +65,24 @@ main = hakyll $ do
>>= relativizeUrls
>>= removeIndexHtml
+ match "index.html" $ do
+ route idRoute
+ compile $ do
+ posts <- recentFirst =<< loadAll "posts/*"
+ let indexCtx =
+ listField "posts" postCtx (return posts)
+ <> defaultCtx
+
+ getResourceBody
+ >>= applyAsTemplate indexCtx
+ >>= loadAndApplyTemplate "templates/default.html" indexCtx
+ >>= relativizeUrls
+ >>= removeIndexHtml
+
create ["atom.xml"] $ do
route idRoute
compile $ do
- let feedCtx = postCtx `mappend` bodyField "description"
+ let feedCtx = postCtx <> bodyField "description"
posts <-
fmap (take 10) . recentFirst
=<< loadAllSnapshots "posts/*" "content"
@@ -80,28 +91,12 @@ main = hakyll $ do
create ["rss.xml"] $ do
route idRoute
compile $ do
- let feedCtx = postCtx `mappend` bodyField "description"
+ let feedCtx = postCtx <> bodyField "description"
posts <-
fmap (take 10) . recentFirst
=<< loadAllSnapshots "posts/*" "content"
renderRss feedConfiguration feedCtx posts
- match "index.html" $ do
- route idRoute
- compile $ do
- posts <- recentFirst =<< loadAll "posts/*"
- let indexCtx =
- listField "posts" postCtx (return posts)
- `mappend` defaultCtx
-
- getResourceBody
- >>= applyAsTemplate indexCtx
- >>= loadAndApplyTemplate "templates/default.html" indexCtx
- >>= relativizeUrls
- >>= removeIndexHtml
-
- match "templates/*" $ compile templateBodyCompiler
-
--------------------------------------------------------------------------------
feedConfiguration :: FeedConfiguration
feedConfiguration =
@@ -129,9 +124,9 @@ removeIndexHtml item = return $ fmap (withUrls removeIndexStr) item
removeIndexStr :: String -> String
removeIndexStr url = case splitFileName url of
(dir, "index.html") | isLocal dir -> dir
- _ -> url
+ _ -> url
where
- isLocal uri = not (isInfixOf "://" uri)
+ isLocal uri = not ("://" `isInfixOf` uri)
--------------------------------------------------------------------------------
@@ -150,17 +145,11 @@ cDateCtx = dateField "cdate" "%Y-%m-%d"
gitRevisionField :: String -> Context String
gitRevisionField = flip field (const gitRevision)
--- Compiler which attempts to find the current git revision. This is done by
--- first checking the "REVISION" environment variable and, if this fails,
--- running the command "git rev-parse HEAD".
gitRevision :: Compiler String
-gitRevision = do
- rev <- unsafeCompiler (getEnv "REVISION" `catch` (\e -> return (e :: SomeException) >> return ""))
- if rev == ""
- then unixFilter "git" ["rev-parse", "--short=7", "HEAD"] ""
- else return rev
+gitRevision = unixFilter "git" ["rev-parse", "--short=7", "HEAD"] ""
gitRevisionCtx :: Context String
gitRevisionCtx = gitRevisionField "revision"
--------------------------------------------------------------------------------
+--------------------------------------------------------------------------------