You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a commenting feature for the blog using [giscus][giscus]. Basically, it uses [Github Discussions][discussions-docs] to store comments instead of storing it in its own database on the web server. Since this website is hosted on [Github Pages][pages-docs] and Pages only supports static websites, it cannot host its own databases to store things such as comments. This guide explains how to add giscus comments to statically-hosted websites, and some quirks and caveats with using Github Discussions as a database for your comments.
10
12
11
-
# Try it
13
+
##Try it
12
14
13
15
You can test it out yourself on this blog post in the comments below by signing into your Github account and commenting, or you can comment on the [Github Discussions post](https://github.com/de-soot/de-soot.github.io/discussions/22) directly and it will show up on the comments section on the website similarly.
14
16
15
-
# Add it to your own Github Pages website
17
+
##Add it to your own Github Pages website
16
18
17
19
1) Make sure to enable Github Discussions on your website's Github repository.
18
20
19
21
2) Navigate to `giscus.app` on your browser's address bar and follow the instructions under the "Configuration" section to configure your `<script>` tag attribute values.
20
22
21
23
3) After you have done so, you can simply copy and paste it into your webpage!
22
24
23
-
# Note
25
+
##Note
24
26
25
27
Giscus finds and links the comments to the Github Discussions by searching through and matching URLs, path names, titles, and other such metadata. If you try to change a page's title without editing the associated Github Discussion accordingly, it may lead to giscus not being able to find and link it to the Github Discussion (this is especially noticible if you set the `<script>`'s `data-strict` attribute value to `"1"`), and hence Giscus will create a new Github Discussion.
Copy file name to clipboardExpand all lines: _posts/2024-09-07-dark-mode.md
+10-12Lines changed: 10 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,30 +2,28 @@
2
2
layout: post
3
3
title: Dark Mode without Javascript
4
4
date: 2024-09-07
5
-
categories: dark mode, dark theme, night mode, night theme, colour scheme, jekyll, css, github pages, static site generators, system default
5
+
categories: dark mode, dark theme, night mode, night theme, colour scheme, jekyll, css, github pages, static site generators, system default theme, website, webpage, customisation
6
6
permalink: /dark-mode
7
7
---
8
8
9
-
This guide explains why and how to easily make a dark theme for your website using CSS `@media` queries.
9
+
Alternative title: System default theme for webpages
10
10
11
-
Alternative title: System default theme for websites
12
-
13
-
# Why Dark Mode
11
+
## Why Dark Mode
14
12
15
13
For users visiting a website in a dark room at night, it would be less straining for their eyes if the webpage was displayed in a darker colour to match the environment, which is what [dark mode][dark-mode] does.
16
14
17
15
<imgsrc="https://zerowidthjoiner.net/uploads/2020/04-11/light-vs-dark.png"alt="Comparison image of light theme on the left and dark theme on the right.">
18
16
19
-
# How to do it
17
+
##How to do it
20
18
21
19
From [MDN Web Docs][mdn]:
22
20
> The @media[CSS][css][at-rule][at-rule] can be used to apply part of a [style sheet][style-sheet] based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.
23
21
24
-
## For Non-Static-Site-Generator Websites
22
+
###For Non-Static-Site-Generator Websites
25
23
26
24
There is also a [video guide by Eric Murphy on Youtube][yt-vid] if you prefer to follow along with a video.
27
25
28
-
### External Style Sheet
26
+
####External Style Sheet
29
27
30
28
To separate code between HTML and CSS, link an external CSS style sheet in the `<head>` tag in the HTML document. Like so:
31
29
@@ -54,7 +52,7 @@ And in your `styles.css`:
54
52
}
55
53
```
56
54
57
-
### With the \<style> HTML tag
55
+
####With the \<style> HTML tag
58
56
59
57
You can also type out your CSS code in between `<style>` tags if you prefer everything to be contained in one HTML document:
60
58
@@ -79,7 +77,7 @@ You can also type out your CSS code in between `<style>` tags if you prefer ever
79
77
</html>
80
78
```
81
79
82
-
## For Static Site Generator Websites
80
+
###For Static Site Generator Websites
83
81
84
82
It is a little bit less straightforward to do this with static site generators like Jekyll (which is what this website uses) or Hugo, as you have to override the theme's CSS style sheet.
85
83
@@ -110,7 +108,7 @@ And you should get something like this after adding the dark mode code.
110
108
111
109
For other static site generator websites, you can refer to the official documentation found online for information on how to override your theme's style-sheet.
112
110
113
-
# Configure Giscus Theme
111
+
##Configure Giscus Theme
114
112
115
113
To set `giscus` comments to match the website if you have done the CSS `@media` trick shown above, simply set the `<script>`'s `data-theme` attribute value to `"preferred_color_scheme"` as shown below.
116
114
@@ -126,7 +124,7 @@ To set `giscus` comments to match the website if you have done the CSS `@media`
126
124
</script>
127
125
```
128
126
129
-
# Conclusion
127
+
##Conclusion
130
128
131
129
If you found this blog post useful, leave a comment down below! Also check out how to add `giscus` comments to your own website on my [previous guide for it](/giscus-comments).
This blog guide goes into why and how to justify and hyphenate text on your website without Javascript.
9
+
## For Static-Site-Generator Websites
10
10
11
-
# For Static-Site-Generator Websites
12
-
13
-
It is a little bit less straightforward to do this with static site generators like Jekyll (which is what this website uses) or Hugo, you will have to override the theme's CSS style sheet.
11
+
It is a little bit less straightforward to follow this guide with static site generators like Jekyll (which is what this website also uses) or Hugo, you will have to override the theme's CSS style sheet.
14
12
15
13
There is a [blog post by Tom Kadwill on how to override your CSS styles in Jekyll][css-blog] you can follow to create your SCSS file, and after which you should get something resembling this:
16
14
@@ -23,11 +21,11 @@ There is a [blog post by Tom Kadwill on how to override your CSS styles in Jekyl
23
21
24
22
After this, you can follow all the steps below the same way as it would be done if you were using CSS in a non-static-site-generator instead of SCSS in a static site generator.
25
23
26
-
# Why Justify Text
24
+
##Why Justify Text
27
25
28
26
It is more of an aesthetic preference than anything. This jaggedness generally does not bother people that much because they have grown used to the popular left-aligned style of text on the web and probably do not know justification even exists on the web, only on printed books and newspapers. But it just looks better to me when all lines are the same length and the right side of text is not jagged. Justifcation is a way of acheiving that aesthetic goal without cutting words off abruptly.
29
27
30
-
# How to Justify
28
+
##How to Justify
31
29
32
30
It is actually pretty simple. To justify your body text, just add this to your CSS style sheet:
33
31
@@ -37,7 +35,7 @@ body {
37
35
}
38
36
```
39
37
40
-
# Why Hyphenate
38
+
##Why Hyphenate
41
39
42
40
Text justification can make your paragraphs look tidier, but it has the side-effect of awkwardly stretching out the whitespace between words, which can create and worsen an undesirable effect commonly referred to as 'rivers of white'. This effect is known to make text harder for dyslexic readers to read, decreasing accessibility.
43
41
@@ -49,7 +47,7 @@ By hyphenating, even though it does not solve the problem completely, it will re
49
47
50
48
Hyphenating text will cut off some words at the end of lines (indicated by an auto-inserted hyphen), but it will do it with an algorithm that tries to make it seamless.
51
49
52
-
# How to Hyphenate
50
+
##How to Hyphenate
53
51
54
52
Although there is a way to hyphenate with Javascript using [Hyphenopoly.js][hyphenopoly], there already is a built-in functionality in CSS to do this and it is [widely supported by browsers](https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens).
55
53
@@ -61,7 +59,7 @@ body {
61
59
}
62
60
```
63
61
64
-
# Other Blogs That Justify
62
+
##Other Blogs That Justify
65
63
66
64
Here are a list of other blogsites that I know of that use justified text:
67
65
- Chris Noxz's [noxz.tech][noxz], which renders static HTML from [`groff`][groff].
@@ -70,7 +68,7 @@ Here are a list of other blogsites that I know of that use justified text:
70
68
- Public Delivery's [publicdelivery.org][pubdeliver], which also justifies without hyphens.
71
69
- JPEG XL's [jpegxl.info][jpg], which had fixed its un-hyphenated text.
72
70
73
-
# Conclusion
71
+
##Conclusion
74
72
75
73
f you found this blog post useful, leave a comment down below! Also read how to add reactive dark-mode to your website in my [previous blog post](/dark-mode).
0 commit comments