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() { _Blog.toggleTheme = function() {
$('.theme-switch').on('click', () => { $('.theme-switch').on('click', () => {
$('body').toggleClass('dark-theme'); $('body').toggleClass('dark-theme');
isDark = !isDark; window.isDark = !window.isDark;
window.localStorage && window.localStorage.setItem('theme', isDark ? 'dark' : 'light'); window.localStorage && window.localStorage.setItem('theme', window.isDark ? 'dark' : 'light');
this.echarts(); this.echarts();
}); });
}; };

View file

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

View file

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

View file

@ -16,7 +16,11 @@
<body> <body>
{{- /* Check theme isDark before body rendering */ -}} {{- /* Check theme isDark before body rendering */ -}}
<script> <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'); window.isDark && document.body.classList.add('dark-theme');
</script> </script>

View file

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