hugo-bear-blog : support 'lastmod' and add darkmode toggle
This commit is contained in:
parent
cbfa056a96
commit
e437c66e80
@ -1,6 +1,7 @@
|
||||
+++
|
||||
title = "{{ replace .Name "-" " " | title }}"
|
||||
date = "{{ .Date }}"
|
||||
lastmod = "{{ .Lastmod }}
|
||||
|
||||
#
|
||||
# description is optional
|
||||
|
@ -16,6 +16,7 @@
|
||||
{{ end -}}
|
||||
|
||||
{{- partial "style.html" . -}}
|
||||
{{- partial "script.html" . -}}
|
||||
|
||||
<!-- A partial to be overwritten by the user.
|
||||
Simply place a custom_head.html into
|
||||
@ -37,6 +38,7 @@
|
||||
<!-- A partial to be overwritten by the user.
|
||||
Simply place a custom_body.html into
|
||||
your local /layouts/partials-directory -->
|
||||
{{- partial "script_bottom.html" -}}
|
||||
{{- partial "custom_body.html" . -}}
|
||||
</body>
|
||||
|
||||
|
@ -6,6 +6,12 @@
|
||||
<time datetime='{{ .Date.Format "2006-01-02" }}' pubdate>
|
||||
{{ .Date.Format (default "02 Jan, 2006" .Site.Params.dateFormat) }}
|
||||
</time>
|
||||
{{ if ne .Lastmod .Date }}
|
||||
/ <b>EDIT :
|
||||
<time datetime='{{ .Lastmod.Format "2006-01-02" }}'>
|
||||
{{ .Lastmod.Format (default "02 Jan, 2006" .Site.Params.dateFormat) }}
|
||||
</time></b>
|
||||
{{ end }}
|
||||
</i>
|
||||
</p>
|
||||
{{ end }}{{ end }}
|
||||
|
@ -5,3 +5,6 @@
|
||||
{{ with .Site.GetPage "/blog" }}
|
||||
<a href="{{ "blog" | relURL }}">Blog</a>
|
||||
{{ end }}
|
||||
<a id="dark-mode-button" onclick="darkmode()" >
|
||||
<span>Toggle-Dark-Mode</span>
|
||||
</a>
|
25
layouts/partials/script.html
Normal file
25
layouts/partials/script.html
Normal file
@ -0,0 +1,25 @@
|
||||
<script>
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem('dark-mode') === null) {
|
||||
localStorage.setItem('dark-mode', 'true');
|
||||
}
|
||||
|
||||
function darkmode() {
|
||||
if (localStorage.getItem('dark-mode') === 'false') {
|
||||
darkmode_enable();
|
||||
} else if (localStorage.getItem('dark-mode') === null) {
|
||||
darkmode_enable();
|
||||
} else {
|
||||
darkmode_disable();
|
||||
}
|
||||
}
|
||||
|
||||
function darkmode_enable() {
|
||||
document.body.classList.add("dark-mode");
|
||||
localStorage.setItem('dark-mode', 'true');
|
||||
}
|
||||
|
||||
function darkmode_disable() {
|
||||
document.body.classList.remove("dark-mode");
|
||||
localStorage.setItem('dark-mode', 'false');
|
||||
}
|
||||
</script>
|
5
layouts/partials/script_bottom.html
Normal file
5
layouts/partials/script_bottom.html
Normal file
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
if (localStorage.getItem('dark-mode') === 'true') {
|
||||
darkmode_enable()
|
||||
}
|
||||
</script>
|
@ -126,48 +126,46 @@
|
||||
color: #8b6fcb;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
.dark-mode {
|
||||
background-color: #333;
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
strong,
|
||||
b {
|
||||
.dark-mode h1,
|
||||
.dark-mode h2,
|
||||
.dark-mode h3,
|
||||
.dark-mode h4,
|
||||
.dark-mode h5,
|
||||
.dark-mode h6,
|
||||
.dark-mode strong,
|
||||
.dark-mode b {
|
||||
color: #eee;
|
||||
}
|
||||
|
||||
a {
|
||||
.dark-mode a {
|
||||
color: #8cc2dd;
|
||||
}
|
||||
|
||||
code {
|
||||
.dark-mode code {
|
||||
background-color: #777;
|
||||
}
|
||||
|
||||
pre code {
|
||||
.dark-mode pre code {
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
.dark-mode blockquote {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
textarea,
|
||||
input {
|
||||
.dark-mode textarea,
|
||||
.dark-mode input {
|
||||
background-color: #252525;
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
.helptext {
|
||||
.dark-mode .helptext {
|
||||
color: #aaa;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user