diff options
author | Raphael Aguiar <rmaguiar@tuta.io> | 2020-08-13 15:42:22 +0300 |
---|---|---|
committer | Raphael Aguiar <rmaguiar@tuta.io> | 2020-08-13 15:42:22 +0300 |
commit | 15cd9c4c3d65a4c90f9c349fdabab7dd21cda1b5 (patch) | |
tree | 9659b9522647c82c6d861c4fd96ff511cb24d04b | |
parent | a7a0189564cdf75708e623ce33a95823d1e92d56 (diff) |
Add ignoreSystemSettings and minor changes
* Add ignoreSystemSettings config param to fix #1
* Add social profiles: Snapchat and XING
* Other minor changes
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | assets/js/prepone.js | 66 | ||||
-rw-r--r-- | assets/svg/snapchat.svg | 1 | ||||
-rw-r--r-- | assets/svg/xing.svg | 1 | ||||
-rw-r--r-- | data/social.json | 18 | ||||
-rw-r--r-- | exampleSite/config.toml | 9 | ||||
-rw-r--r-- | exampleSite/content/posts/readme.md | 7 | ||||
-rw-r--r-- | layouts/partials/head.html | 15 |
8 files changed, 92 insertions, 32 deletions
@@ -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 = [ "<username>" ] medium = [ "<username>" ] reddit = [ "<username>" ] + snapchat = [ "<username>" ] soundcloud = [ "<username>" ] stackOverflow = [ "<username>" ] strava = [ "<username>" ] @@ -158,6 +160,7 @@ Here's an example of config file: twitter = [ "<username>", "@birb" ] vimeo = [ "<username>" ] whatsapp = [ "<number>" ] + xing = [ "<username>" ] youtube = [ "<channelid>" ] #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 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm169.5 338.9c-3.5 8.1-18.1 14-44.8 18.2-1.4 1.9-2.5 9.8-4.3 15.9-1.1 3.7-3.7 5.9-8.1 5.9h-.2c-6.2 0-12.8-2.9-25.8-2.9-17.6 0-23.7 4-37.4 13.7-14.5 10.3-28.4 19.1-49.2 18.2-21 1.6-38.6-11.2-48.5-18.2-13.8-9.7-19.8-13.7-37.4-13.7-12.5 0-20.4 3.1-25.8 3.1-5.4 0-7.5-3.3-8.3-6-1.8-6.1-2.9-14.1-4.3-16-13.8-2.1-44.8-7.5-45.5-21.4-.2-3.6 2.3-6.8 5.9-7.4 46.3-7.6 67.1-55.1 68-57.1 0-.1.1-.2.2-.3 2.5-5 3-9.2 1.6-12.5-3.4-7.9-17.9-10.7-24-13.2-15.8-6.2-18-13.4-17-18.3 1.6-8.5 14.4-13.8 21.9-10.3 5.9 2.8 11.2 4.2 15.7 4.2 3.3 0 5.5-.8 6.6-1.4-1.4-23.9-4.7-58 3.8-77.1C183.1 100 230.7 96 244.7 96c.6 0 6.1-.1 6.7-.1 34.7 0 68 17.8 84.3 54.3 8.5 19.1 5.2 53.1 3.8 77.1 1.1.6 2.9 1.3 5.7 1.4 4.3-.2 9.2-1.6 14.7-4.2 4-1.9 9.6-1.6 13.6 0 6.3 2.3 10.3 6.8 10.4 11.9.1 6.5-5.7 12.1-17.2 16.6-1.4.6-3.1 1.1-4.9 1.7-6.5 2.1-16.4 5.2-19 11.5-1.4 3.3-.8 7.5 1.6 12.5.1.1.1.2.2.3.9 2 21.7 49.5 68 57.1 4 1 7.1 5.5 4.9 10.8z"/></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M162.7 210c-1.8 3.3-25.2 44.4-70.1 123.5-4.9 8.3-10.8 12.5-17.7 12.5H9.8c-7.7 0-12.1-7.5-8.5-14.4l69-121.3c.2 0 .2-.1 0-.3l-43.9-75.6c-4.3-7.8.3-14.1 8.5-14.1H100c7.3 0 13.3 4.1 18 12.2l44.7 77.5zM382.6 46.1l-144 253v.3L330.2 466c3.9 7.1.2 14.1-8.5 14.1h-65.2c-7.6 0-13.6-4-18-12.2l-92.4-168.5c3.3-5.8 51.5-90.8 144.8-255.2 4.6-8.1 10.4-12.2 17.5-12.2h65.7c8 0 12.3 6.7 8.5 14.1z"/></svg>
\ 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 @@ -135,6 +135,15 @@ } }, { + "entry": "snapchat", + "label": "Snapchat", + "base": "https://www.snapchat.com/add/", + "icon": { + "id": "snapchat", + "source": "Font-Awesome" + } + }, + { "entry": "soundcloud", "label": "SoundCloud", "base": "https://soundcloud.com/", @@ -207,6 +216,15 @@ } }, { + "entry": "xing", + "label": "XING", + "base": "https://www.xing.com/profile/", + "icon": { + "id": "xing", + "source": "Font-Awesome" + } + }, + { "entry": "youtube", "label": "YouTube", "base": "https://youtube.com/channel/", 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 = [ "<username>" ] medium = [ "<username>" ] reddit = [ "<username>" ] + snapchat = [ "<username>" ] soundcloud = [ "<username>" ] stackOverflow = [ "<username>" ] strava = [ "<username>" ] @@ -169,6 +175,7 @@ paginate = 5 twitter = [ "<username>", "@birb" ] vimeo = [ "<username>" ] whatsapp = [ "<number>" ] + xing = [ "<username>" ] youtube = [ "<channelid>" ] #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 = [ "<username>" ] medium = [ "<username>" ] reddit = [ "<username>" ] + snapchat = [ "<username>" ] soundcloud = [ "<username>" ] stackOverflow = [ "<username>" ] strava = [ "<username>" ] @@ -161,6 +163,7 @@ Here's an example of config file: twitter = [ "<username>", "@birb" ] vimeo = [ "<username>" ] whatsapp = [ "<number>" ] + xing = [ "<username>" ] youtube = [ "<channelid>" ] #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 }} - <!-- Not properly tested? --> - <meta name="theme-color" content="{{ $darkAccent }}" {{ if not .Site.Params.Style.isDark }}media="(prefers-color-scheme: dark)"{{ end }}> - <meta name="theme-color" content="{{ $lightAccent }}" {{ if .Site.Params.Style.isDark }}media="(prefers-color-scheme: light)"{{ end }}> + {{ if .Site.Params.Style.ignoreSystemSettings }} + + {{ if .Site.Params.Style.isDark }} + <meta name="theme-color" content="{{ $darkAccent }}"> + {{ else }} + <meta name="theme-color" content="{{ $lightAccent }}"> + {{ end }} + + {{ else }} + <meta name="theme-color" content="{{ $darkAccent }}" media="(prefers-color-scheme: dark)"> + <meta name="theme-color" content="{{ $lightAccent }}" media="(prefers-color-scheme: light)"> + {{ end }} <style> |