diff --git a/example/content/2024-10-19-what-is-marmite-static-site-generator.md b/example/content/2024-10-19-what-is-marmite-static-site-generator.md index 0d5f5a3..7de57a2 100644 --- a/example/content/2024-10-19-what-is-marmite-static-site-generator.md +++ b/example/content/2024-10-19-what-is-marmite-static-site-generator.md @@ -211,8 +211,10 @@ Other options are available and can be viewed on [repository](https://github.com ## Theme customization The embedded templates are created with [picocss.com](https://picocss.com/) and -it is easy to customize, just put a `style.css` in the same folder where the markdown -files are located and use anything that pico supports or just be creative with css. +it is easy to customize, just put a `custom.css` and a `custom.js` +in your root folder and use anything that pico supports or just be creative with css. + +If customizing the css and js is not enough then you can create your own theme. ## Creating a new Theme diff --git a/example/static/style.css b/example/static/custom.css similarity index 100% rename from example/static/style.css rename to example/static/custom.css diff --git a/example/static/custom.js b/example/static/custom.js new file mode 100644 index 0000000..638fbb0 --- /dev/null +++ b/example/static/custom.js @@ -0,0 +1 @@ +/* Customize me */ diff --git a/example/static/marmite.css b/example/static/marmite.css index 84d0376..a9990c6 100644 --- a/example/static/marmite.css +++ b/example/static/marmite.css @@ -121,3 +121,7 @@ article footer { justify-content: space-between; align-items: center; } + +.spoiler, .spoiler > * { transition: color 0.5s, opacity 0.5s } +.spoiler:not(:hover) { color: transparent;background-color: #808080} +.spoiler:not(:hover) > * { opacity: 0 } diff --git a/example/static/marmite.js b/example/static/marmite.js new file mode 100644 index 0000000..b8c31bc --- /dev/null +++ b/example/static/marmite.js @@ -0,0 +1,90 @@ +// Theme switcher - light/dark +const themeSwitcher = { + // Config + _scheme: "auto", + toggleButton: document.getElementById("theme-toggle"), + rootAttribute: "data-theme", + localStorageKey: "picoPreferredColorScheme", + + // Init + init() { + this.scheme = this.schemeFromLocalStorage; + this.initToggle(); + this.updateIcon(); + }, + + // Get color scheme from local storage + get schemeFromLocalStorage() { + return window.localStorage?.getItem(this.localStorageKey) ?? this._scheme; + }, + + // Preferred color scheme + get preferredColorScheme() { + return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; + }, + + // Init toggle + initToggle() { + this.toggleButton.addEventListener( + "click", + (event) => { + event.preventDefault(); + // Toggle scheme + this.scheme = this.scheme === "dark" ? "light" : "dark"; + this.updateIcon(); + }, + false + ); + }, + + // Set scheme + set scheme(scheme) { + if (scheme == "auto") { + this._scheme = this.preferredColorScheme; + } else if (scheme == "dark" || scheme == "light") { + this._scheme = scheme; + } + this.applyScheme(); + this.schemeToLocalStorage(); + }, + + // Get scheme + get scheme() { + return this._scheme; + }, + + // Apply scheme + applyScheme() { + document.querySelector("html")?.setAttribute(this.rootAttribute, this.scheme); + // staticBase is defined on content.html template + document.querySelector("#highlightjs-theme")?.setAttribute("href", `${staticBase}/github-${this.scheme}.min.css`); + }, + + // Store scheme to local storage + schemeToLocalStorage() { + window.localStorage?.setItem(this.localStorageKey, this.scheme); + }, + + // Update icon based on the current scheme + updateIcon() { + if (this.scheme === "dark") { + this.toggleButton.innerHTML = "☼"; // Sun icon for light mode + } else { + this.toggleButton.innerHTML = "☽"; // Moon icon for dark mode + } + }, +}; + +// Init +themeSwitcher.init(); + +// Menu + +const menuToggle = document.getElementById('menu-toggle'); +const headerMenu = document.getElementById('header-menu'); + +menuToggle.addEventListener('click', function () { + headerMenu.classList.toggle('active'); +}); + + diff --git a/example/static/menu.js b/example/static/menu.js deleted file mode 100644 index c087e49..0000000 --- a/example/static/menu.js +++ /dev/null @@ -1,7 +0,0 @@ - -const menuToggle = document.getElementById('menu-toggle'); -const headerMenu = document.getElementById('header-menu'); - -menuToggle.addEventListener('click', function () { - headerMenu.classList.toggle('active'); -}); \ No newline at end of file diff --git a/example/static/robots.txt b/example/static/robots.txt new file mode 100644 index 0000000..5e9db7d --- /dev/null +++ b/example/static/robots.txt @@ -0,0 +1,5 @@ +User-agent: Mediapartners-Google +Disallow: + +User-agent: * +Allow: / diff --git a/example/static/theme-switcher.js b/example/static/theme-switcher.js deleted file mode 100644 index 58c8b73..0000000 --- a/example/static/theme-switcher.js +++ /dev/null @@ -1,84 +0,0 @@ -/*! - * Minimal theme switcher - * - * Pico.css - https://picocss.com - * Copyright 2019-2024 - Licensed under MIT - */ -const themeSwitcher = { - // Config - _scheme: "auto", - toggleButton: document.getElementById("theme-toggle"), - rootAttribute: "data-theme", - localStorageKey: "picoPreferredColorScheme", - - // Init - init() { - this.scheme = this.schemeFromLocalStorage; - this.initToggle(); - this.updateIcon(); - }, - - // Get color scheme from local storage - get schemeFromLocalStorage() { - return window.localStorage?.getItem(this.localStorageKey) ?? this._scheme; - }, - - // Preferred color scheme - get preferredColorScheme() { - return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; - }, - - // Init toggle - initToggle() { - this.toggleButton.addEventListener( - "click", - (event) => { - event.preventDefault(); - // Toggle scheme - this.scheme = this.scheme === "dark" ? "light" : "dark"; - this.updateIcon(); - }, - false - ); - }, - - // Set scheme - set scheme(scheme) { - if (scheme == "auto") { - this._scheme = this.preferredColorScheme; - } else if (scheme == "dark" || scheme == "light") { - this._scheme = scheme; - } - this.applyScheme(); - this.schemeToLocalStorage(); - }, - - // Get scheme - get scheme() { - return this._scheme; - }, - - // Apply scheme - applyScheme() { - document.querySelector("html")?.setAttribute(this.rootAttribute, this.scheme); - // staticBase is defined on content.html template - document.querySelector("#highlightjs-theme")?.setAttribute("href", `${staticBase}/github-${this.scheme}.min.css`); - }, - - // Store scheme to local storage - schemeToLocalStorage() { - window.localStorage?.setItem(this.localStorageKey, this.scheme); - }, - - // Update icon based on the current scheme - updateIcon() { - if (this.scheme === "dark") { - this.toggleButton.innerHTML = "☼"; // Sun icon for light mode - } else { - this.toggleButton.innerHTML = "☽"; // Moon icon for dark mode - } - }, -}; - -// Init -themeSwitcher.init(); diff --git a/example/templates/base.html b/example/templates/base.html index c1c1770..92078f1 100644 --- a/example/templates/base.html +++ b/example/templates/base.html @@ -16,7 +16,7 @@ } - + {% endblock -%} @@ -62,8 +62,8 @@