Replies: 20 comments 12 replies
-
Like this? https://codepen.io/sashatran/pen/rPaLgG |
Beta Was this translation helpful? Give feedback.
-
Yes that's right. Another example of it is the following Hugo theme https://academic-demo.netlify.com |
Beta Was this translation helpful? Give feedback.
-
This is how i (a noob) achieved/reverse-engineered it in Minimal-Mistakes
you can see it in action here (shameless plug) - my dev site I am sure Michael will come up with a better solution than that of the above monstrosity. Eagerly waiting as this issue has been marked with the |
Beta Was this translation helpful? Give feedback.
-
Not exactly sure how I'd handle this without bloating the theme with a bunch of extra CSS. Which means the dark skin's styling isn't available to the "light" or vice/versa. Does bundling in all the skins in a stylesheet really the best thing for those who don't care about a light/dark toggle? I dunno... There's also the issue of the theme not having a canonical "light" skin anymore. There are essentially 10 different color palettes someone can choose... and they don't all compliment each other. Which means probably designing 9 or so more color schemes to invert them. Personally I've never much cared for sites that add this sort of thing. I'd rather see it happen at the system or browser level. There are browser extensions that do just this which might have better results vs. me trying to maintain consistency across 10 color palettes x 2 modes (20 palettes if you're counting at home). |
Beta Was this translation helpful? Give feedback.
-
@mmistakes see https://inclusive-components.design/a-theme-switcher/ |
Beta Was this translation helpful? Give feedback.
-
That said I see this as a passing fad. Everyone scrambling to add a light/dark mode to their themes when the OS + browser should be responsible for this behavior. |
Beta Was this translation helpful? Give feedback.
-
OS + browser can go all dark mode on their browser menu but they can only go as far as just applying a dark contrast mode on the website content, which may lead to the website visuals getting all messed up. So it is actually upto the website developer to manage/feature their own dark mode. |
Beta Was this translation helpful? Give feedback.
-
I agree it's up to the site to control how it looks, but feel the toggle needs to be elsewhere which it seems like macOS is moving wards with Mojave as illustrated by @paulmillr here: https://paulmillr.com/posts/using-dark-mode-in-css/ |
Beta Was this translation helpful? Give feedback.
-
I was wondering if we could resume the discussion around Mojave dark mode, since I'm considering using this theme for docs and not having a dark/light toggle is a bit of a pain point (not insurmountable, just a very nice to have). |
Beta Was this translation helpful? Give feedback.
-
I know this issue has been marked as closed, but I was wondering if we could continue this discussion as per @rcarmo's suggestion. I'm aware that there is no canonical light or dark theme, but it would be great if some form of customization functionality could be added with a toggling option, i.e. allow users to enable a toggle with two themes specified in |
Beta Was this translation helpful? Give feedback.
-
I'd also very much like to be able to achieve this. |
Beta Was this translation helpful? Give feedback.
-
@astrob0t Hi, I'm a noobie in web dev here. Do you mind sharing your solution in more details? |
Beta Was this translation helpful? Give feedback.
-
Sorry for not viewing this thread earlier, I'm a noob to jekyll and web dev so apologies if this is not easy at all. Great theme Michael. Will love it always! Here is my original ISSUE : SummaryWouldn't it be great to add a two theme switching button feature to the website: Maybe include something in the theme configuration file as :
MotivationI thought of looking at some articles and found these :
However, these documents don't cover the themes that minimal mistakes uses, aka : | aqua | neon | plum | dirt | mint | sunrise | air | contrast | dark | DrawbacksNone that I know of , except that it may cause the one navigation menu item to maybe go to the sidebar with three horizontal bars? |
Beta Was this translation helpful? Give feedback.
-
It'd be great to have this toggle feature. |
Beta Was this translation helpful? Give feedback.
-
I've been able to achieve this. Before telling the procedure, let's discuss the main idea: First, edit _config.yml : There are going to be two themes. The first one is declared as usual. And for the second one, we create a new entry caled minimal_mistakes_skin2. So, add the following lines:
Create a file in your project directory in the location assets/css/theme2.scss (create a folder named assets, and inside that, create another folder named css) and insert the following lines in the file:
Now, create a _includes folder and copy the _includes/head.html from your Minimal-mistakes gems directory. Now we have to modify the file. Open it and find the following line:
Change it to:
and just after that line, add the following:
Note that, I am using "light" and "dark" as generic names of skin1 and skin2. These strings have nothing to do with the actual skin names. Now, create a _layouts folder and copy the _layouts/default.html from your Minimal-mistakes gems directory. Now we have to modify the file. Open it and find the following part:
Keep those lines intact and just above those, add the following:
Now if you build your site, you'll see a large button with bad design and written "HI!" on it (add your own css). Click on that to toggle theme. Also verify that the skin remains consistent if we navigate to other pages. Here is one example, done on the theme Please suggest improvements and designs for the button. |
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks for this, it looks very promising. The link to the example webpage is broken ( https://sohamsaha99.github.io/notes/ ). Could you please fix it to see how it looks like? Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hello,
So basically the best of both world.
and there is one problem: when the OS theme is set to dark, the theme change button on the website doesn't cause any effects. |
Beta Was this translation helpful? Give feedback.
-
Untested code but I think if you modify the <link rel="stylesheet alternate" href="{{ '/assets/css/theme2.css' | relative_url }}" id="theme_source_2">
<script>
let theme = sessionStorage.getItem('theme');
- if(theme === 'dark')
+ if (theme === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches)
{
sessionStorage.setItem('theme', 'dark');
node1 = document.getElementById('theme_source');
node2 = document.getElementById('theme_source_2');
node1.setAttribute('rel', 'stylesheet alternate');
node2.setAttribute('rel', 'stylesheet');
}
else
{
sessionStorage.setItem('theme', 'light');
}
</script> |
Beta Was this translation helpful? Give feedback.
-
I implemented night mode using this method. It works fine. Thanks. But I am facing an issue with giscus comment provider. How can I toggle giscus theme with site theme? |
Beta Was this translation helpful? Give feedback.
-
I love the solution provided by @sohamsaha99, Thanks!! But sometimes, whenever I reload a page or change the theme, CSS is loaded after HTML (I can see my form fields for a brief moment while they are still unstyled). I think I've solved this by first loading // in head.html
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}" id="theme_source">
{% if site.minimal_mistakes_skin2 %}
<link rel="stylesheet" href="{{ '/assets/css/theme2.css' | relative_url }}" id="theme_source_2">
<script>
if (sessionStorage.getItem('theme') === null) {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
sessionStorage.setItem('theme', 'dark');
}
else{
sessionStorage.setItem('theme', 'light');
}
}
let theme = sessionStorage.getItem('theme');
if(theme === "dark"){
document.getElementById('theme_source').setAttribute('rel', 'stylesheet alternate');
sessionStorage.setItem('theme', 'dark');
}
else
{
document.getElementById('theme_source_2').setAttribute('rel', 'stylesheet alternate');
sessionStorage.setItem('theme', 'light');
}
</script>
{% endif %} And for the button script, I've set a timeout for disabling a stylesheet (this solved the CSS issues when applying theme change for me): // in _includes/masthead.html
<div class="masthead">
.....
{% if site.minimal_mistakes_skin2 %}
<li><i class="fas fa-fw fa-adjust dark_mode_btn" aria-hidden="true" onclick="dark_mode_btn_click()"></i></li>
{% endif %}
.....
</div>
// in _includes/scripts.html
<script>
function dark_mode_btn_click() {
var node1 = document.getElementById('theme_source');
var node2 = document.getElementById('theme_source_2');
if(node1.getAttribute('rel')=='stylesheet'){
node2.setAttribute('rel', 'stylesheet');
setTimeout(function(){
node1.setAttribute('rel', 'stylesheet alternate');
}, 10);
sessionStorage.setItem('theme', 'dark');
}else{
node1.setAttribute('rel', 'stylesheet');
setTimeout(function(){
node2.setAttribute('rel', 'stylesheet alternate');
}, 10);
sessionStorage.setItem('theme', 'light');
}
return false;
}
<script> |
Beta Was this translation helpful? Give feedback.
-
Summary
I'm new to Front-end development. I was wondering if it would be possible to allow the user to toggle between themes/css properties using the same color configurations specified using minimal_mistakes_skin: "default"
Motivation
Beta Was this translation helpful? Give feedback.
All reactions