使用"hexo-tag-cloud"插件添加动态标签云。
效果
损不足 - 奉有余 (leafminer.github.io)
安装插件
配置主题
找到文件 hexo\node_modules\hexo-theme-next\layout\_macrosidebar.njk, 然后添加如下内容。
1 2 3 4 5 6 7 8 9 10 11 12
| {% if site.tags.length > 1 %} <script type="text/javascript" charset="utf-8" src="{{ url_for('/js/tagcloud.js') }}"></script> <script type="text/javascript" charset="utf-8" src="{{ url_for('/js/tagcanvas.js') }}"></script> <div class="widget-wrap"> <h3 class="widget-title">标签云</h3> <div id="myCanvasContainer" class="widget tagcloud"> <canvas width="250" height="250" id="resCanvas" style="width:100%"> {{ list_tags() }} </canvas> </div> </div> {% endif %}
|
【推荐,防止更新主题重置】或者修改主题的config.yml,去掉sidebar前面的#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
custom_file_path: head: source/_data/head.njk sidebar: source/_data/sidebar.njk footer: source/_data/footer.njk style: source/_data/styles.styl
|
新建文件source/_data/sidebar.njk,在文件中添加如下内容:
1 2 3 4 5 6 7 8 9 10 11 12
| {% if site.tags.length > 1 %} <script type="text/javascript" charset="utf-8" src="{{ url_for('/js/tagcloud.js') }}"></script> <script type="text/javascript" charset="utf-8" src="{{ url_for('/js/tagcanvas.js') }}"></script> <div class="widget-wrap"> <h3 class="widget-title">Tag Cloud</h3> <div id="myCanvasContainer" class="widget tagcloud"> <canvas width="250" height="250" id="resCanvas" style="width:100%"> {{ list_tags() }} </canvas> </div> </div> {% endif %}
|
在你的Hexo博客根目录,找到 _config.yml 文件然后添加如下的配置项:
1 2 3 4 5 6 7 8
| tag_cloud: textFont: Trebuchet MS, Helvetica textColor: '#333' textHeight: 25 outlineColor: '#E2E1D1' maxSpeed: 0.5 pauseOnSelected: false
|
预览部署
-
完成安装和显示,可以通过 hexo clean && hexo g && hexo s
来进行本地预览, hexo clean
为必须选项。
-
PS:不要使用hexo g -d
或者 hexo d -g
这类组合命令。
参考
hexo-tag-cloud - npm (npmjs.com)