Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
feat(config): add config for default theme light/dark
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Feb 8, 2020
1 parent c5e64a9 commit 095089f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions assets/js/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
};
Expand Down
4 changes: 3 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion exampleSite/zh/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/home/social.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 095089f

Please sign in to comment.