Hexo Next主题增加贴纸

增加一个类似我头像下方的“written by human not by AI”的贴纸。

新增栏位

  1. 打开themes\hexo-theme-next\layout\_partials\sidebar\site-overview.njk文件,
    找到这段代码(CC协议的小组件):
site-overview.njk
1
2
3
4
5
6
7
<!-- 找到这段代码,不是添加! -->
{%- if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license animated" itemprop="license">
{%- set ccImage = '<img src="' + theme.vendors.creative_commons.url + '" alt="Creative Commons">' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div>
{%- endif %}

在下面新增以下代码:

site-overview.njk
1
2
3
4
5
6
{%- if theme.writtenbyhuman.enable and theme.creative_commons.sidebar %}
<div class="cc-license animated" itemprop="license">
{%- set notaiImage = '<img src="' + theme.writtenbyhuman.badge_url + '" alt="written by human not by AI">' %}
{{ next_url("https://notbyai.fyi/", notaiImage, {class: 'cc-opacity'}) }}
</div>
{%- endif %}

为了保持统一,我直接引用了CC小组件的样式。

  1. 打开站点的_config.yml文件,新增以下属性:
1
2
3
4
# 人类撰写贴纸
writtenbyhuman:
enable: true
badge_url: https://notbyai.fyi/img/written-by-human-not-by-ai-white.svg
  1. 完成。