From f8b3a3161217e09eff8a6477c9ebec1242c1dbee Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 9 Feb 2019 14:15:16 -0500 Subject: [PATCH 1/2] Optional dark theme avatar (eg. logo) --- assets/css/_common/_page/home.scss | 3 +++ assets/js/main.js | 13 +++++++++++++ exampleSite/config.toml | 1 + layouts/partials/home_post.html | 10 +++++++++- layouts/partials/home_profile.html | 8 +++++++- layouts/partials/js.html | 20 +++++++++++++++++--- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/assets/css/_common/_page/home.scss b/assets/css/_common/_page/home.scss index 55f6c30..0556754 100644 --- a/assets/css/_common/_page/home.scss +++ b/assets/css/_common/_page/home.scss @@ -31,6 +31,9 @@ } } } + .avatar.dark { + display: none; + } } h2.description { diff --git a/assets/js/main.js b/assets/js/main.js index fddf3fa..bde27f3 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -32,9 +32,22 @@ jQuery(function($) { _Blog.toggleTheme = function() { const currentTheme = window.localStorage && window.localStorage.getItem('theme') const isDark = currentTheme === 'dark' + var toggleVisibility = function(getDark) { + if (getDark) { + $('.dark').show() + $('.light').hide() + } else { + $('.dark').hide() + $('.light').show() + } + } + toggleVisibility(isDark) $('body').toggleClass('dark-theme', isDark) $('.theme-switch').on('click', () => { $('body').toggleClass('dark-theme') + const currentTheme = window.localStorage && window.localStorage.getItem('theme') + const isDark = currentTheme === 'dark' + toggleVisibility(!isDark) window.localStorage && window.localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light', ) }) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index e91dff2..21219f0 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -43,6 +43,7 @@ preserveTaxonomyNames = true since = 2011 author = "Covey.Liu" # Author's name avatar = "/images/me/avatar.jpeg" # Author's avatar + avatar_dark = "/images/me/avatar_dark.jpeg" # Optional dark theme avatar subtitle = "我会更好,因为我没有停止" # Subtitle cdn_url = "" # Base CDN URL home_mode = "" # post or other diff --git a/layouts/partials/home_post.html b/layouts/partials/home_post.html index e3e9364..120ab29 100644 --- a/layouts/partials/home_post.html +++ b/layouts/partials/home_post.html @@ -4,9 +4,17 @@ {{ $cdn_url := .Scratch.Get "cdn_url" }} {{ with .Site.Params.avatar}} {{ $avatar := .}} -
+ + + {{ end }} + {{ with .Site.Params.avatar_dark}} + {{ $avatar := .}} +
+ +
+ {{ end }} {{ with .Site.Params.subtitle}}

diff --git a/layouts/partials/home_profile.html b/layouts/partials/home_profile.html index cb81002..e2ab043 100644 --- a/layouts/partials/home_profile.html +++ b/layouts/partials/home_profile.html @@ -2,7 +2,13 @@ {{ $cdn_url := .Scratch.Get "cdn_url" }} {{ with .Site.Params.avatar}} {{ $avatar := .}} -
+
+ +
+ {{ end }} + {{ with .Site.Params.avatar_dark}} + {{ $avatar := .}} + {{ end }} diff --git a/layouts/partials/js.html b/layouts/partials/js.html index f78dc70..1faf0e8 100644 --- a/layouts/partials/js.html +++ b/layouts/partials/js.html @@ -9,17 +9,31 @@ {{ $lihtGallery_init := resources.Get "/js/lightGallery-init.js" }} {{ if .IsPage }} + {{ $vendorscript := "" }} {{ if $postHasImages }} - {{ $vendorscript := slice $jquery $lazysizes $prettify $dynamic $main $lihtGallery $lihtGallery_init | resources.Concat "/js/vendor_gallery.js" | resources.Minify }} + {{ if eq ( getenv "HUGO_ENV" ) "production" }} + {{ $vendorscript = slice $jquery $lazysizes $prettify $dynamic $main $lihtGallery $lihtGallery_init | resources.Concat "/js/vendor_gallery.js" | resources.Minify }} + {{ else }} + {{ $vendorscript = slice $jquery $lazysizes $prettify $dynamic $main $lihtGallery $lihtGallery_init | resources.Concat "/js/vendor_gallery.js" }} + {{ end }} {{ else }} - {{ $vendorscript := slice $jquery $prettify $dynamic $main | resources.Concat "/js/vendor_no_gallery.js" | resources.Minify }} + {{ if eq ( getenv "HUGO_ENV" ) "production" }} + {{ $vendorscript = slice $jquery $prettify $dynamic $main | resources.Concat "/js/vendor_no_gallery.js" | resources.Minify }} + {{ else }} + {{ $vendorscript = slice $jquery $prettify $dynamic $main | resources.Concat "/js/vendor_no_gallery.js" }} + {{ end }} {{ end }} {{ else }} - {{ $main := slice $jquery $main | resources.Concat "/js/vendor_main.js" | resources.Minify}} + + {{ if eq ( getenv "HUGO_ENV" ) "production" }} + {{ $main = slice $jquery $main | resources.Concat "/js/vendor_main.js" | resources.Minify }} + {{ else }} + {{ $main = slice $jquery $main | resources.Concat "/js/vendor_main.js" }} + {{ end }} {{ end }} From 8e4b2186cd8db1ac1c76d714b0b119d4ed1a13f1 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 9 Feb 2019 14:51:24 -0500 Subject: [PATCH 2/2] Add missing favicon values --- layouts/partials/head.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 2e08a5f..51204c4 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -15,6 +15,11 @@ + + + + +