给 Stellar 编写和添加组件 以 侧边栏添加 Waline 为例
今天心血来潮想给自己的博客的侧边栏增加一个整个站点的评论区, 记录下给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
| ...
site_tree: home: leftbar: welcome, recent, <mark>sidecommet</mark> rightbar: index_blog: base_dir: blog menu_id: post leftbar: welcome, recent, <mark>sidecommet</mark> rightbar: nav_tabs: index_topic: base_dir: topic menu_id: post index_wiki: base_dir: wiki menu_id: wiki leftbar: related, recent, <mark>sidecommet</mark> rightbar: nav_tabs: post: menu_id: post leftbar: related, recent, <mark>sidecommet</mark> rightbar: ghrepo, toc topic: menu_id: post wiki: menu_id: wiki leftbar: tree, related, recent, <mark>sidecommet</mark> 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 page: leftbar: recent, <mark>sidecommet</mark> rightbar: toc ...
|