From 15cd9c4c3d65a4c90f9c349fdabab7dd21cda1b5 Mon Sep 17 00:00:00 2001 From: Raphael Aguiar Date: Thu, 13 Aug 2020 09:42:22 -0300 Subject: Add ignoreSystemSettings and minor changes * Add ignoreSystemSettings config param to fix #1 * Add social profiles: Snapchat and XING * Other minor changes --- README.md | 7 ++++ assets/js/prepone.js | 66 +++++++++++++++++++++---------------- assets/svg/snapchat.svg | 1 + assets/svg/xing.svg | 1 + data/social.json | 18 ++++++++++ exampleSite/config.toml | 9 ++++- exampleSite/content/posts/readme.md | 7 ++++ layouts/partials/head.html | 15 +++++++-- 8 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 assets/svg/snapchat.svg create mode 100644 assets/svg/xing.svg diff --git a/README.md b/README.md index 441db3c..c4cd65c 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ You can change the default mode and accent colors in the config: [params.style] # Dark mode as default + # User preferences (site/system settings) will still have priority over it # The default is false isDark = true @@ -150,6 +151,7 @@ Here's an example of config file: linkedin = [ "" ] medium = [ "" ] reddit = [ "" ] + snapchat = [ "" ] soundcloud = [ "" ] stackOverflow = [ "" ] strava = [ "" ] @@ -158,6 +160,7 @@ Here's an example of config file: twitter = [ "", "@birb" ] vimeo = [ "" ] whatsapp = [ "" ] + xing = [ "" ] youtube = [ "" ] #entry = [ "username", "label (optional)" ] @@ -314,6 +317,10 @@ More possible params for your config file: [params.style] + # Disable the use of system settings (prefers-color-scheme) + # The default is false + ignoreSystemSettings = true + # Use an icon or text for footnote return links # The default is false hasIconAsFootnoteReturnLink = true diff --git a/assets/js/prepone.js b/assets/js/prepone.js index df24bcf..3f57767 100644 --- a/assets/js/prepone.js +++ b/assets/js/prepone.js @@ -12,9 +12,12 @@ // Based on: https://gist.github.com/regpaq/04c67e8aceecbf0fd819945835412d1f // ================================================= -// New prefers-color-scheme media query to detect OS light/dark mode setting -const PREFERS_LIGHT = window.matchMedia('(prefers-color-scheme: light)'); -const PREFERS_DARK = window.matchMedia('(prefers-color-scheme: dark)'); +{{ if not .Site.Params.Style.ignoreSystemSettings }} + // New prefers-color-scheme media query to detect OS light/dark mode setting + const PREFERS_LIGHT = window.matchMedia('(prefers-color-scheme: light)'); + const PREFERS_DARK = window.matchMedia('(prefers-color-scheme: dark)'); +{{ end }} + const ROOT = document.documentElement; const SHEET = document.documentElement.style; @@ -34,12 +37,16 @@ function setLight() { // And yes, I know 'true' here is a string if(localStorage.getItem('isDark') == 'true') { setDark() -} else if(localStorage.getItem('isDark') === null) { - setLight() -} else if(PREFERS_DARK.matches) { - setDark() -} else if(PREFERS_LIGHT.matches) { +} else if(localStorage.getItem('isDark') == 'false') { setLight() + + {{ if not .Site.Params.Style.ignoreSystemSettings }} + } else if(PREFERS_DARK.matches) { + setDark() + } else if(PREFERS_LIGHT.matches) { + setLight() + {{ end }} + }; console.log('Light/dark mode loaded.'); @@ -126,7 +133,7 @@ document.addEventListener('DOMContentLoaded', function () { } else { setLight(); - localStorage.removeItem('isDark') + localStorage.setItem('isDark', 'false') console.log("Mode changed to 'light' by the user."); @@ -150,32 +157,35 @@ document.addEventListener('DOMContentLoaded', function () { {{ end }} - // Runs when OS changes light/dark mode. Changes only if you were on default - // color state (light on light mode, dark on dark mode). - function OSModeChange() { + {{ if not .Site.Params.Style.ignoreSystemSettings }} - smoothTransition(); + // Runs when OS changes light/dark mode. Changes only if you were on default + // color state (light on light mode, dark on dark mode). + function OSModeChange() { - if (PREFERS_LIGHT.matches) { - setLight(); - localStorage.removeItem('isDark') - - console.log("Mode changed to 'light' in OS level."); + smoothTransition(); - } else if (PREFERS_DARK.matches) { - setDark(); - localStorage.setItem('isDark', 'true') + if (PREFERS_LIGHT.matches) { + setLight(); + localStorage.setItem('isDark', 'false') + + console.log("Mode changed to 'light' in OS level."); + + } else if (PREFERS_DARK.matches) { + setDark(); + localStorage.setItem('isDark', 'true') + + console.log("Mode changed to 'dark' in OS level."); + }; - console.log("Mode changed to 'dark' in OS level."); + updateAccent() }; - - updateAccent() - }; - // Listeners for when you change OS setting for light/dark mode - PREFERS_LIGHT.addListener(OSModeChange); - PREFERS_DARK.addListener(OSModeChange); + // Listeners for when you change OS setting for light/dark mode + PREFERS_LIGHT.addListener(OSModeChange); + PREFERS_DARK.addListener(OSModeChange); + {{ end }} // Mode change button document.querySelector('footer button') diff --git a/assets/svg/snapchat.svg b/assets/svg/snapchat.svg new file mode 100644 index 0000000..88cfa16 --- /dev/null +++ b/assets/svg/snapchat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/svg/xing.svg b/assets/svg/xing.svg new file mode 100644 index 0000000..c400771 --- /dev/null +++ b/assets/svg/xing.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/social.json b/data/social.json index 240b041..c7de59e 100644 --- a/data/social.json +++ b/data/social.json @@ -134,6 +134,15 @@ "source": "Element" } }, + { + "entry": "snapchat", + "label": "Snapchat", + "base": "https://www.snapchat.com/add/", + "icon": { + "id": "snapchat", + "source": "Font-Awesome" + } + }, { "entry": "soundcloud", "label": "SoundCloud", @@ -206,6 +215,15 @@ "source": "Font-Awesome" } }, + { + "entry": "xing", + "label": "XING", + "base": "https://www.xing.com/profile/", + "icon": { + "id": "xing", + "source": "Font-Awesome" + } + }, { "entry": "youtube", "label": "YouTube", diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 4a2330e..fdebfd9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -109,9 +109,14 @@ paginate = 5 [params.style] # Dark mode as default + # User preferences (site/system settings) will still have priority over it # The default is false isDark = true - + + # Disable the use of system settings (prefers-color-scheme) + # The default is false + ignoreSystemSettings = true + # Accent colors for light and dark mode respectively lightAccent = "#225670" # Default is "#225670" darkAccent = "#dd587c" # Default is "#dd587c" @@ -161,6 +166,7 @@ paginate = 5 linkedin = [ "" ] medium = [ "" ] reddit = [ "" ] + snapchat = [ "" ] soundcloud = [ "" ] stackOverflow = [ "" ] strava = [ "" ] @@ -169,6 +175,7 @@ paginate = 5 twitter = [ "", "@birb" ] vimeo = [ "" ] whatsapp = [ "" ] + xing = [ "" ] youtube = [ "" ] #entry = [ "username", "label (optional)" ] diff --git a/exampleSite/content/posts/readme.md b/exampleSite/content/posts/readme.md index 361ee86..560ff16 100644 --- a/exampleSite/content/posts/readme.md +++ b/exampleSite/content/posts/readme.md @@ -67,6 +67,7 @@ You can change the default mode and accent colors in the config: [params.style] # Dark mode as default + # User preferences (site/system settings) will still have priority over it # The default is false isDark = true @@ -153,6 +154,7 @@ Here's an example of config file: linkedin = [ "" ] medium = [ "" ] reddit = [ "" ] + snapchat = [ "" ] soundcloud = [ "" ] stackOverflow = [ "" ] strava = [ "" ] @@ -161,6 +163,7 @@ Here's an example of config file: twitter = [ "", "@birb" ] vimeo = [ "" ] whatsapp = [ "" ] + xing = [ "" ] youtube = [ "" ] #entry = [ "username", "label (optional)" ] @@ -317,6 +320,10 @@ More possible params for your config file: [params.style] + # Disable the use of system settings (prefers-color-scheme) + # The default is false + ignoreSystemSettings = true + # Use an icon or text for footnote return links # The default is false hasIconAsFootnoteReturnLink = true diff --git a/layouts/partials/head.html b/layouts/partials/head.html index c2753ba..42e8e52 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -335,9 +335,18 @@ {{ $darkAccent := .Site.Params.Style.darkAccent | default .Site.Data.default.style.darkAccent }} {{ $lightAccent := .Site.Params.Style.lightAccent | default .Site.Data.default.style.lightAccent }} - - - + {{ if .Site.Params.Style.ignoreSystemSettings }} + + {{ if .Site.Params.Style.isDark }} + + {{ else }} + + {{ end }} + + {{ else }} + + + {{ end }}