diff --git a/flake.nix b/flake.nix index a797e42..8f9409a 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ ] ./.; buildPhase = '' - hakyll-site build --verbose + static-site-generator build --verbose ''; installPhase = '' diff --git a/static-site-generator/Main.hs b/static-site-generator/Main.hs index f792cf3..49b788a 100644 --- a/static-site-generator/Main.hs +++ b/static-site-generator/Main.hs @@ -55,6 +55,17 @@ config = -------------------------------------------------------------------------------- -- BUILD +applyDefaultTemplate :: Context String -> Item String -> Compiler (Item String) +applyDefaultTemplate ctx item = do + head <- itemBody <$> loadAndApplyTemplate "templates/head.html" ctx item + navbar <- itemBody <$> loadAndApplyTemplate "templates/navbar.html" ctx item + + let ctx' = constField "head" head + <> constField "navbar" navbar + <> ctx + + loadAndApplyTemplate "templates/default.html" ctx' item + main :: IO () main = hakyllWith config $ do fileHashes <- preprocess (mapKeys (fromFilePath . drop 4 . toFilePath) <$> mkFileHashes "www/posts") @@ -64,7 +75,6 @@ main = hakyllWith config $ do , "favicon.ico" , "_config.yml" , "images/**" - , "js/*" , "fonts/*" ] $ \f -> match f $ do @@ -88,9 +98,8 @@ main = hakyllWith config $ do getResourceBody >>= replaceLogoLinks >>= pandocRendererCustom - >>= loadAndApplyTemplate "templates/post.html" ctx - >>= saveSnapshot "content" - >>= loadAndApplyTemplate "templates/default.html" ctx + >>= loadAndApplyTemplate "templates/blogpost.html" ctx + >>= applyDefaultTemplate ctx match "gogen/**" $ do let ctx = @@ -103,8 +112,7 @@ main = hakyllWith config $ do compile $ do pandocCompilerCustom >>= loadAndApplyTemplate "templates/gogen.html" ctx - >>= saveSnapshot "content" - >>= loadAndApplyTemplate "templates/default.html" ctx + >>= applyDefaultTemplate ctx match "*debug.md" $ do let ctx = constField "type" "article" <> postCtx @@ -115,14 +123,12 @@ main = hakyllWith config $ do getResourceBody >>= replaceLogoLinks >>= pandocRendererCustom - >>= loadAndApplyTemplate "templates/post.html" ctx - >>= saveSnapshot "content" - >>= loadAndApplyTemplate "templates/default.html" ctx + >>= loadAndApplyTemplate "templates/blogpost.html" ctx + >>= applyDefaultTemplate ctx match "index.html" $ do route idRoute compile $ do - -- posts :: Compiler posts <- recentFirst =<< loadAll "posts/*" gogen <- loadAll "gogen/**" @@ -135,7 +141,7 @@ main = hakyllWith config $ do getResourceBody >>= applyAsTemplate indexCtx - >>= loadAndApplyTemplate "templates/default.html" indexCtx + >>= applyDefaultTemplate indexCtx match "templates/*" $ compile templateBodyCompiler diff --git a/www/js/script.js b/www/js/script.js deleted file mode 100644 index 4fc48a9..0000000 --- a/www/js/script.js +++ /dev/null @@ -1,3 +0,0 @@ -;(function(w, d) { - console.log('Hello, world!', w, d) -})(window, document); diff --git a/www/js/ui.js b/www/js/ui.js deleted file mode 100644 index 17bd342..0000000 --- a/www/js/ui.js +++ /dev/null @@ -1,56 +0,0 @@ -// https://github.com/pure-css/pure/blob/master/site/static/js/ui.js - -(function (window, document) { - - // we fetch the elements each time because docusaurus removes the previous - // element references on page navigation - function getElements() { - return { - layout: document.getElementById('layout'), - menu: document.getElementById('menu'), - menuLink: document.getElementById('menuLink') - }; - } - - function toggleClass(element, className) { - var classes = element.className.split(/\s+/); - var length = classes.length; - var i = 0; - - for (; i < length; i++) { - if (classes[i] === className) { - classes.splice(i, 1); - break; - } - } - // The className is not found - if (length === classes.length) { - classes.push(className); - } - - element.className = classes.join(' '); - } - - function toggleAll() { - var active = 'active'; - var elements = getElements(); - - toggleClass(elements.layout, active); - toggleClass(elements.menu, active); - toggleClass(elements.menuLink, active); - } - - function handleEvent(e) { - var elements = getElements(); - - if (e.target.id === elements.menuLink.id) { - toggleAll(); - e.preventDefault(); - } else if (elements.menu.className.indexOf('active') !== -1) { - toggleAll(); - } - } - - document.addEventListener('click', handleEvent); - -}(this, this.document)); diff --git a/www/templates/post.html b/www/templates/blogpost.html similarity index 100% rename from www/templates/post.html rename to www/templates/blogpost.html diff --git a/www/templates/default.html b/www/templates/default.html index 11557ed..6617b60 100644 --- a/www/templates/default.html +++ b/www/templates/default.html @@ -1,102 +1,12 @@ - - $title$ - - - - $if(desc)$ - - $endif$ - - $if(author)$ - - $endif$ - - $if(keywords)$ - - $endif$ - - - - - $if(desc)$ - - $endif$ - - $if(image)$ - - $endif$ - - $if(type)$ - - $else$ - - $endif$ - - - - - $if(desc)$ - - $endif$ - - $if(image)$ - - $endif$ - - - - - - - - - - - - + $head$ -
- - -
- - - - - - - - - - -
+ $navbar$
-$body$ + $-body-$ - - diff --git a/www/templates/head.html b/www/templates/head.html new file mode 100644 index 0000000..a8d3701 --- /dev/null +++ b/www/templates/head.html @@ -0,0 +1,56 @@ + + $title$ + + + + $if(desc)$ + + $endif-$ + + $if(author)$ + + $endif-$ + + $if(keywords)$ + + $endif-$ + + + + + $if(desc)$ + + $endif-$ + + $if(image)$ + + $endif-$ + + $if(type)$ + + $else$ + + $endif-$ + + + + + $if(desc)$ + + $endif-$ + + $if(image)$ + + $endif-$ + + + + + + + + + + + + diff --git a/www/templates/navbar.html b/www/templates/navbar.html new file mode 100644 index 0000000..041ea2a --- /dev/null +++ b/www/templates/navbar.html @@ -0,0 +1,18 @@ +