Skip to content

Commit

Permalink
feat: split jsconfig
Browse files Browse the repository at this point in the history
still wip
  • Loading branch information
Candinya committed May 21, 2024
1 parent 333b2f8 commit a4f48db
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 109 deletions.
17 changes: 1 addition & 16 deletions .demo/_config.kratos-rebirth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ image:

# 顶部导航栏配置
top_nav:
items:
- label: 首页
icon: home
url: /
Expand Down Expand Up @@ -65,22 +66,6 @@ sidebar:
- tagcloud
- posts

# JavaScript 相关配置
## 由于Javascript被压缩后难以有效编辑与生成,因而为了简化操作,将相关的配置项在生成文件时以独立的json文件写出,调用时使用fetch API获取。
jsconfig:
main:
createTime: "2018/05/06 17:03:12"
donateBtn: "支持我~"
scanNotice: "扫一扫,好不好?"
qr_alipay: "/images/alipayqr.webp"
qr_wechat: "/images/wechatpayqr.webp"
siteLeaveEvent: false
leaveTitle: "{{{(>_<)}}}哦哟,崩溃啦~"
returnTitle: "(*´∇`*)欸,又好啦~"
copyrightNotice: "该内容采用 CC BY-NC-SA 4.0 许可协议,著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。"
expire_day: 30
topNavScrollToggle: true

# Friends 友链相关内容
friends:
href: "friends"
Expand Down
78 changes: 54 additions & 24 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ image:
dark: "/images/about.webp" # 暗色模式

# 顶部导航栏配置
top_nav: []
# - label: 这个菜单的标签文字
# icon: 这个菜单前的图标(在 tabler icons 图标库中选择,可以不设置)
# url: 这个菜单指向的链接(站内或是站外均可)
# submenu: 这个菜单是否为一个二级菜单,有了这个选项就会忽略上面的 url
# - label: 二级菜单项的标签文字
# icon: 二级菜单前的图标(在 tabler icons 图标库中选择,可以不设置)
# url: 二级菜单项指向的链接
top_nav:
auto_hide: true
items: []
# - label: 这个菜单的标签文字
# icon: 这个菜单前的图标(在 tabler icons 图标库中选择,可以不设置)
# url: 这个菜单指向的链接(站内或是站外均可)
# submenu: 这个菜单是否为一个二级菜单,有了这个选项就会忽略上面的 url
# - label: 二级菜单项的标签文字
# icon: 二级菜单前的图标(在 tabler icons 图标库中选择,可以不设置)
# url: 二级菜单项指向的链接

# 文章的列表配置(首页/分页/标签页)
post_index:
Expand All @@ -68,9 +70,10 @@ footer_links: []
# 一些有特色的组件 (其他的请在 additional_injections 自行追加)
footer_components:
uptime:
since: "2018/05/06 17:03:12"
text: 本站已运行

# Post Page 文章内页配置
# Post 文章页配置
posts:
default_cover: "/images/about.webp" # 没有头图的文章使用的默认图片
show_cc: true
Expand All @@ -80,7 +83,14 @@ posts:
enable: true
threshold: 1500
estimate_wavy: true # 在文章字数处显示表示大约字数的波浪号
expire_after: 30 #

pages:
show_cc: true
donate: true
share: true

# 代码高亮
code_highlight:
theme: night-eighties # 代码高亮主题(light | night | night-eighties | night-blue | night-bright)

Expand All @@ -98,21 +108,41 @@ sidebar:
hide: false
hide_id: false

# JavaScript 相关配置
## 由于Javascript被压缩后难以有效编辑与生成,因而为了简化操作,将相关的配置项在生成文件时以独立的json文件写出,调用时使用fetch API获取。
jsconfig:
main:
createTime: "2018/05/06 17:03:12"
donateBtn: "支持我~"
scanNotice: "扫一扫,好不好?"
qr_alipay: "/images/alipayqr.webp"
qr_wechat: "/images/wechatpayqr.webp"
siteLeaveEvent: false
leaveTitle: "{{{(>_<)}}}哦哟,崩溃啦~"
returnTitle: "(*´∇`*)欸,又好啦~"
copyrightNotice: "该内容采用 CC BY-NC-SA 4.0 许可协议,著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。"
expire_day: 30
topNavScrollToggle: true
# 分享组件设置
share:
platforms: []
# - icon: ""
# color: ""
# qrcode: true
# link_template: ""

# 捐赠组件设置
donate:
title: "支持我~"
subtitle: "扫一扫,好不好?"
platforms: []
# - icon: ""
# text: ""
# qrcode: ""

# 站点离开提示
inactive_notice:
enabled: true
message:
leave: "{{{(>_<)}}}哦哟,崩溃啦~"
return: "(*´∇`*)欸,又好啦~"

# 复制时自动追加版权相关说明
copyright_notice:
enabled: true
threshold: 150
template: |
$NEWLINE
-------------------------
该内容采用 CC BY-NC-SA 4.0 许可协议,著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
作者:$AUTHOR
来源:$TITLE
链接:$LINK
# Friends 友链相关内容
friends:
Expand Down
52 changes: 25 additions & 27 deletions layout/_partial/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@
<div class="nav-header">
<nav id="kratos-menu-wrap">
<ul id="kratos-primary-menu" class="sf-menu">
<% if (theme.top_nav) { %>
<% for (const item of theme.top_nav) { %>
<li>
<% if (item.submenu) { %>
<a>
<% } else { %>
<a href="<%- url_for(item.url) %>">
<% for (const item of theme.top_nav.items) { %>
<li>
<% if (item.submenu) { %>
<a>
<% } else { %>
<a href="<%- url_for(item.url) %>">
<% } %>
<% if (item.icon) { %>
<i class="ti ti-<%- item.icon %>"></i>
<% } %>
<% if (item.icon) { %>
<i class="ti ti-<%- item.icon %>"></i>
<%- item.label %>
</a>
<% if (item.submenu) { %>
<ul class="sub-menu">
<% for (const submenu of item.submenu) { %>
<li>
<a href="<%- url_for(submenu.url) %>">
<% if (submenu.icon) { %>
<i class="ti ti-<%- submenu.icon %>"></i>
<% } %>
<%- submenu.label %>
</a>
</li>
<% } %>
<%- item.label %>
</a>
<% if (item.submenu) { %>
<ul class="sub-menu">
<% for (const submenu of item.submenu) { %>
<li>
<a href="<%- url_for(submenu.url) %>">
<% if (submenu.icon) { %>
<i class="ti ti-<%- submenu.icon %>"></i>
<% } %>
<%- submenu.label %>
</a>
</li>
<% } %>
</ul>
<% } %>
</li>
<% } %>
</ul>
<% } %>
</li>
<% } %>
</ul>
</nav>
Expand Down
11 changes: 11 additions & 0 deletions layout/page.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
<div itemprop="articleBody"><%- page.content %></div>
</div>
<footer class="kratos-entry-footer clearfix">
<% if (theme.pages.donate || theme.pages.share) { %>
<div class="post-like-donate text-center clearfix" id="post-like-donate">
<% if (theme.pages.donate) { %>
<a class="donate" href="javascript:;"><i class="ti ti-coins"></i> <%- __('reward') %></a>
<% } %>
<% if (theme.pages.share) { %>
<a class="share" href="javascript:;"><i class="ti ti-share"></i> <%- __('share') %></a>
<%- partial('_tools/share', {page: page}) %>
<% } %>
</div>
<% } %>
<div class="footer-tag clearfix">
<div class="pull-date">
<time datetime="<%= date_xml(page.updated) %>" itemprop="dateModified"><%- __('last_modify') %><%- date(page.updated) %></time>
Expand Down
2 changes: 1 addition & 1 deletion layout/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</div>
<% } %>
<footer class="kratos-entry-footer clearfix">
<% if (theme.posts && (theme.posts.donate || theme.posts.share)) { %>
<% if (theme.posts.donate || theme.posts.share) { %>
<div class="post-like-donate text-center clearfix" id="post-like-donate">
<% if (theme.posts.donate) { %>
<a class="donate" href="javascript:;"><i class="ti ti-coins"></i> <%- __('reward') %></a>
Expand Down
26 changes: 26 additions & 0 deletions scripts/gen-jsconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 生成运行时调用的配置专用JS文件

hexo.once('generateBefore', () => {

hexo.extend.generator.register('jsconfig', () => {

const themeConfig = hexo.theme.config;

const jsCfg = {
createTime: themeConfig.footer_components.uptime.since,
siteLeaveEvent: themeConfig.inactive_notice.enabled,
leaveTitle: themeConfig.inactive_notice.message.leave,
returnTitle: themeConfig.inactive_notice.message.return,
copyrightNoticeEnabled: themeConfig.copyright_notice.enabled,
copyrightNotice: themeConfig.copyright_notice.template,
copyrightNoticeThreshold: themeConfig.copyright_notice.threshold,
expire_day: themeConfig.posts.expire_after,
topNavScrollToggle: themeConfig.top_nav.auto_hide,
};

return {
path: 'config.json',
data: JSON.stringify(jsCfg)
};
});
});
28 changes: 0 additions & 28 deletions scripts/genconfig.js

This file was deleted.

Loading

0 comments on commit a4f48db

Please sign in to comment.