今天心血来潮想给自己的博客的侧边栏增加一个整个站点的评论区, 记录下给Stellar添加组件的过程

1、编写ejs文件(…/blog/node_modules/hexo-theme-stellar/layout/_partial/widgets/name.ejs)

根据 Waline 提供的客户端例子编写布局文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%
function layoutDiv() {
var el = '<widget class="widget-wrapper post-list">';
el += '<link rel="stylesheet" href="https://blog.b1gm4x.com/css/waline.css"/>';
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + '博客留言' + '</span>' + '</div>';
el += '<div id="waline">' + '</div>';
el += '<script type="module">' + "import { init } from 'https://unpkg.com/@waline/client@v3/dist/waline.js'; init({ el: '#waline', dark: false, serverURL: 'https://blog.b1gm4x.com/comments', login: 'disable', wordLimit: 0, comment: false, path: 'side-bar', pageview: true});" + '</script>';
el += '</widget>';
return el;
}
%>
<%- layoutDiv() %>

2、修改widgets.yml (…/blog/node_modules\hexo-theme-stellar/_data/widgets.yml)

1
2
3
4
5
6
....
#侧边评论
sidecommet:
layout: sidecommet
....

修改 _config.stellar.yml 在你想添加的页面的对应布局上添加你的组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
######## Main ########
# 站点主结构树
site_tree:
# -- 列表类页面 -- #
# 主页配置
home:
leftbar: welcome, recent, <mark>sidecommet</mark>
rightbar:
# 博客列表页配置
index_blog:
base_dir: blog # 只影响自动生成的页面路径
menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id
leftbar: welcome, recent, <mark>sidecommet</mark> # for categories/tags/archives
rightbar:
nav_tabs: # 近期发布 分类 标签 专栏 归档 and ...
# '朋友文章': /friends/rss/
# 博客专栏列表页配置
index_topic:
base_dir: topic # 只影响自动生成的页面路径
menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 topic 的页面默认使用这里配置的 menu_id
# 文档列表页配置
index_wiki:
base_dir: wiki # 只影响自动生成的页面路径
menu_id: wiki # 未在 front-matter 中指定 menu_id 时,layout 为 wiki 的页面默认使用这里配置的 menu_id
leftbar: related, recent, <mark>sidecommet</mark> # for wiki
rightbar:
nav_tabs:
# 'more': https://github.com/xaoxuu
# -- 内容类页面 -- #
# 博客文章内页配置
post:
menu_id: post # 未在 front-matter 中指定 menu_id 时,layout 为 post 的页面默认使用这里配置的 menu_id
leftbar: related, recent, <mark>sidecommet</mark> # for pages using 'layout:post'
rightbar: ghrepo, toc
# 博客专栏文章内页配置
topic:
menu_id: post
# 文档内页配置
wiki:
menu_id: wiki # 未在 front-matter 中指定 menu_id 时,layout 为 wiki 的页面默认使用这里配置的 menu_id
leftbar: tree, related, recent, <mark>sidecommet</mark> # for wiki
rightbar: ghrepo, toc
# 作者信息配置
author:
base_dir: author # 只影响自动生成的页面路径
menu_id: post
leftbar: recent, timeline, <mark>sidecommet</mark>
rightbar: timeline
# 错误页配置
error_page:
menu_id: post
'404': '/404.html'
leftbar: recent, timeline, <mark>sidecommet</mark>
rightbar: timeline
# 其它自定义页面配置 layout: page
page:
leftbar: recent, <mark>sidecommet</mark>
rightbar: toc
...