From e90b28cd24587449e3f351487c793c29debccc81 Mon Sep 17 00:00:00 2001 From: mivinci <1366723936@qq.com> Date: Mon, 23 Aug 2021 21:40:38 +0800 Subject: [PATCH] enable reading template variable from JS files --- .gitignore | 3 ++- assets/js/theme.js | 3 ++- exampleSite/config.toml | 4 +++- layouts/partials/head.html | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index faa6c31..96e0abb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -public \ No newline at end of file +public +resources \ No newline at end of file diff --git a/assets/js/theme.js b/assets/js/theme.js index 24de5c9..bdc246d 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1,4 +1,5 @@ -const light = '🌝', dark = '🌚'; +const light = '{{ index .Site.Params.switch 1 }}', + dark = '{{ index .Site.Params.switch 0 }}'; const LIGHT = 'light', DARK = 'dark'; const themeSwitcher = document.getElementById('theme-switcher'); diff --git a/exampleSite/config.toml b/exampleSite/config.toml index fab58d9..626d37b 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -13,7 +13,7 @@ disqusShortname = "hugo-minima" [author] name = "XJJ" slogon = "A student and web developer from Earth 🌍" -description = "This is Minima, a clean and minimal Hugo theme porting from Minima on Hexo. It not only inherits everything from Hexo Minima like dark/light mode but intgrated KaTeX and some taxonomies like categories, series and tags. I created this from scratch using pure CSS and Vanilla JS without using unnecessary development packs! 😁" +description = "This is Minima, a clean and minimal Hugo theme porting from Minima on Hexo. It not only inherits everything from Hexo Minima like dark/light mode but intgrated KaTeX and some taxonomies like categories, series and tags. I created this from scratch using SCSS and Vanilla JS without unnecessary development packs! 😁" [params] @@ -27,6 +27,8 @@ subtitle = "" comment = "disqus" # timeformat timeformat = "Jan 2, 2006" +# switch for turning on/off lights. +switch = ["🌚", "🌝"] # OvO is a comment plugin written by the author of Minima. diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f339a7e..5b1705d 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -24,8 +24,8 @@ {{ $style := resources.Get "sass/main.scss" | resources.ToCSS $options }} - {{ $options := (dict "targetPath" (printf `minima.%d.js` $hash) "minify" true) }} - {{ $js := resources.Get "js/main.js" | js.Build $options }} + {{ $options = (dict "targetPath" (printf `minima.%d.js` $hash) "minify" true) }} + {{ $js := resources.Get "js/main.js" | js.Build $options | resources.ExecuteAsTemplate (printf `minima.%d.js` $hash) . }}