From 3c11f6cca5b73e188289ada66e7924b4b33e4f59 Mon Sep 17 00:00:00 2001 From: JJ Date: Sun, 21 Jul 2024 21:42:42 -0700 Subject: replace jekyll with hakyll --- .gitignore | 4 +++- 404.html | 14 +++++------ Gemfile | 5 ---- _config.yml | 2 -- _includes/footer.html | 3 --- _includes/header.html | 13 ----------- _layouts/default.html | 13 ----------- _templates/default.html | 13 +++++++++++ _templates/footer.html | 3 +++ _templates/header.html | 13 +++++++++++ _templates/main.html | 16 +++++++++++++ _templates/post.html | 17 ++++++++++++++ index.html | 4 +--- site.cabal | 10 ++++++++ site.hs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ stack.yaml | 4 ++++ 16 files changed, 149 insertions(+), 47 deletions(-) delete mode 100644 Gemfile delete mode 100644 _config.yml delete mode 100644 _includes/footer.html delete mode 100644 _includes/header.html delete mode 100644 _layouts/default.html create mode 100644 _templates/default.html create mode 100644 _templates/footer.html create mode 100644 _templates/header.html create mode 100644 _templates/main.html create mode 100644 _templates/post.html create mode 100644 site.cabal create mode 100644 site.hs create mode 100644 stack.yaml diff --git a/.gitignore b/.gitignore index ed90730..d2a7949 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +_cache _site -Gemfile.lock +.stack-work +stack.yaml.lock diff --git a/404.html b/404.html index 2c82613..885663d 100644 --- a/404.html +++ b/404.html @@ -1,10 +1,10 @@ --- -layout: default +layout: main title: 404 --- - - - {% include header.html %} -
-

404

- Page not found + + + +
+

404

+Page not found diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 7e303f2..0000000 --- a/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gem 'jekyll' - -gem "webrick", "~> 1.8" diff --git a/_config.yml b/_config.yml deleted file mode 100644 index d7040d8..0000000 --- a/_config.yml +++ /dev/null @@ -1,2 +0,0 @@ -title: my special corner of the web -email: web@toki.la diff --git a/_includes/footer.html b/_includes/footer.html deleted file mode 100644 index 049de4a..0000000 --- a/_includes/footer.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/_includes/header.html b/_includes/header.html deleted file mode 100644 index 832e2ec..0000000 --- a/_includes/header.html +++ /dev/null @@ -1,13 +0,0 @@ -
-

- apropos -

- -
diff --git a/_layouts/default.html b/_layouts/default.html deleted file mode 100644 index 6074f7a..0000000 --- a/_layouts/default.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - {{page.title}} - - - {{ content }} - - diff --git a/_templates/default.html b/_templates/default.html new file mode 100644 index 0000000..24da983 --- /dev/null +++ b/_templates/default.html @@ -0,0 +1,13 @@ + + + + + + + + $title$ + + +$body$ + + diff --git a/_templates/footer.html b/_templates/footer.html new file mode 100644 index 0000000..93b3dd7 --- /dev/null +++ b/_templates/footer.html @@ -0,0 +1,3 @@ + diff --git a/_templates/header.html b/_templates/header.html new file mode 100644 index 0000000..bfd4deb --- /dev/null +++ b/_templates/header.html @@ -0,0 +1,13 @@ +
+

+ apropos +

+ +
diff --git a/_templates/main.html b/_templates/main.html new file mode 100644 index 0000000..093c7da --- /dev/null +++ b/_templates/main.html @@ -0,0 +1,16 @@ + + + + + + + + $title$ + + +$partial("_templates/header.html")$ +
+$body$ +
+ + diff --git a/_templates/post.html b/_templates/post.html new file mode 100644 index 0000000..fca6aed --- /dev/null +++ b/_templates/post.html @@ -0,0 +1,17 @@ + + + + + + + + + $title$ + + +$partial("_templates/header.html")$ +
+$body$ +
+ + diff --git a/index.html b/index.html index f76ab69..8d2c961 100644 --- a/index.html +++ b/index.html @@ -1,10 +1,8 @@ --- -layout: default +layout: main title: my special corner of the web --- -{% include header.html %} -
diff --git a/site.cabal b/site.cabal new file mode 100644 index 0000000..432ed8f --- /dev/null +++ b/site.cabal @@ -0,0 +1,10 @@ +name: site +version: 0.1 +build-type: Simple +cabal-version: >= 1.10 + +executable site + main-is: site.hs + build-depends: base == 4.*, hakyll == 4.16.*, pandoc == 3.* + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 diff --git a/site.hs b/site.hs new file mode 100644 index 0000000..47a385b --- /dev/null +++ b/site.hs @@ -0,0 +1,62 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Hakyll hiding (pandocCompiler) +import Text.Pandoc.Options +import Text.Pandoc.Highlighting + +-- Pass custom options to the Pandoc compiler +pandocCompiler :: Compiler (Item String) +pandocCompiler = + let defaultExtensions = writerExtensions defaultHakyllWriterOptions + addedExtensions = extensionsFromList [Ext_lists_without_preceding_blankline] + removedExtensions = extensionsFromList [Ext_blank_before_header, Ext_blank_before_blockquote] + writerOptions = defaultHakyllWriterOptions { + writerExtensions = disableExtensions (defaultExtensions <> pandocExtensions <> addedExtensions) removedExtensions, + writerHTMLMathMethod = MathML, + writerHighlightStyle = Just zenburn + } + in pandocCompilerWith defaultHakyllReaderOptions writerOptions + +-- Loads the template specified in a post's metadata, if it exists +loadLayoutTemplate :: Context String -> Item String -> Compiler (Item String) +loadLayoutTemplate context item = do + field <- getMetadataField (itemIdentifier item) "layout" + case field of + Just path -> + let templatePath = "_templates/" ++ path ++ ".html" in + loadAndApplyTemplate (fromFilePath templatePath) context item + _ -> return item + +main :: IO () +main = hakyll $ do + -- Compile templates for future use + match "_templates/*" $ compile templateBodyCompiler + + -- Detect whether HTML files are standalone or in need of a template + match ("**.html" .||. "**.htm") $ do + route idRoute + compile $ do + identifier <- getUnderlying + field <- getMetadataField identifier "layout" + case field of + Just _ -> pandocCompiler + Nothing -> getResourceBody + >>= loadLayoutTemplate defaultContext + >>= relativizeUrls + + -- Match all other renderable files and apply their template, if it exists + match ("**.md" .||. "**.markdown") $ do + route $ setExtension "html" + compile $ pandocCompiler + >>= loadLayoutTemplate defaultContext + >>= relativizeUrls + + -- Additionally copy non-HTML files verbatium + match ("**.md" .||. "**.markdown") $ version "raw" $ do + route idRoute + compile pandocCompiler + + -- Copy all additional files verbatium + match "**" $ do + route idRoute + compile copyFileCompiler diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..36d8e5b --- /dev/null +++ b/stack.yaml @@ -0,0 +1,4 @@ +resolver: lts-22.30 +system-ghc: true +packages: +- . -- cgit v1.2.3-70-g09d2