Merge pull request #58 from dillonzq/feature/config_default_theme

feat(config): add config for default theme light/dark
This commit is contained in:
Dillon 2020-02-08 22:23:38 +08:00 committed by GitHub
commit dd6c0f7907
5 changed files with 14 additions and 6 deletions

View file

@ -14,8 +14,8 @@ jQuery(function($) {
_Blog.toggleTheme = function() {
$('.theme-switch').on('click', () => {
$('body').toggleClass('dark-theme');
isDark = !isDark;
window.localStorage && window.localStorage.setItem('theme', isDark ? 'dark' : 'light');
window.isDark = !window.isDark;
window.localStorage && window.localStorage.setItem('theme', window.isDark ? 'dark' : 'light');
this.echarts();
});
};

View file

@ -110,9 +110,11 @@ dateFormatToUse = "2006-01-02"
description = "About LoveIt Theme"
# site keywords
keywords = ["Theme", "Hugo"]
# site default theme ("light", "dark")
defaultTheme = "light"
# Home Page Info
## [post, other] home mode
##home mode ("post", "other")
home_mode = "post"
## special amount of posts in each home post page
home_paginate = 6

View file

@ -110,9 +110,11 @@ dateFormatToUse = "2006-01-02"
description = "关于 LoveIt 主题"
# 网站关键词
keywords = ["Theme", "Hugo"]
# 网站默认主题 ("light", "dark")
defaultTheme = "light"
# 主页信息设置
## [post, other] 主页模式
## 主页模式 ("post", "other")
home_mode = "post"
## 主页在 post 模式下每页 post 显示数量
home_paginate = 6

View file

@ -16,7 +16,11 @@
<body>
{{- /* Check theme isDark before body rendering */ -}}
<script>
window.isDark = (window.localStorage && window.localStorage.getItem('theme')) === 'dark';
if (!window.localStorage || !window.localStorage.getItem('theme')) {
window.isDark = '{{ .Site.Params.defaultTheme }}' === 'dark';
} else {
window.isDark = (window.localStorage && window.localStorage.getItem('theme')) === 'dark';
}
window.isDark && document.body.classList.add('dark-theme');
</script>

View file

@ -269,7 +269,7 @@
</a>
{{- end -}}
{{- with .Site.Params.Social.Mastodon}}
{{ $MastodonPrefix := $.Site.Params.Social.MastodonPrefix | default "https://mastodon.social/" }}
{{- $MastodonPrefix := $.Site.Params.Social.MastodonPrefix | default "https://mastodon.social/" -}}
<a href="{{ $MastodonPrefix | safeURL }}{{ . }}" rel="me noopener noreffer" target="_blank">
<i class="fab fa-mastodon fa-fw" title="Mastodon"></i>
</a>