返回

为 hexo maupassant 主题添加文章版权信息和相关文章推荐阅读功能

前端

为 hexo maupassant 主题添加文章版权信息和相关文章推荐功能

在网上看过别人的博客主题后,发现我现在用的maupassant主题缺少了两个实用的功能:在文章末尾添加版权信息和相关文章推荐阅读.既然缺少功能,那就参照别人的代码添加上对应的功能呗,这就是我为什么选择为 maupassant 主题添加文章版权信息和相关文章推荐功能。

如何添加文章版权信息

修改文件

在 maupassant 主题的文件夹中找到 _config.yml 文件,添加一行代码在底部:

copyright: 文章版权所有

修改模板文件

修改 maupassant 主题的 layout/_partial/footer.swig 文件,在底部添加以下代码:

{% if site.copyright %}
<footer class="footer">
  <div class="container text-center">
    <p>{% raw %}{{ site.copyright }}{% endraw %}</p>
  </div>
</footer>
{% endif %}

添加文章版权声明

在博客文章的 Front-matter 中添加以下代码:

copyright: 转载请注明出处

如何添加相关文章推荐

修改文件

在 maupassant 主题的文件夹中找到 _config.yml 文件,添加一行代码在底部:

related_post: true

修改模板文件

修改 maupassant 主题的 layout/_partial/footer.swig 文件,在底部添加以下代码:

{% if site.related_post and post.tags %}
<section class="related-post">
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <h3 class="section-title">相关文章</h3>
        <div class="row">
          {% for tag in post.tags %}
          {% for related_post in site.tags[tag].posts %}
          {% if related_post != post %}
          <div class="col-md-4">
            <div class="related-post-item">
              <a href="{{ related_post.url }}">
                <img src="{{ related_post.image }}" alt="{{ related_post.title }}">
              </a>
              <h4 class="related-post-title">
                <a href="{{ related_post.url }}">{{ related_post.title }}</a>
              </h4>
              <p class="related-post-excerpt">{{ related_post.excerpt }}</p>
            </div>
          </div>
          {% endif %}
          {% endfor %}
          {% endfor %}
        </div>
      </div>
    </div>
  </div>
</section>
{% endif %}

添加相关文章标签

在博客文章的 Front-matter 中添加以下代码:

tags: [文章标签1, 文章标签2, 文章标签3]

总结

通过以上步骤,您可以在 hexo maupassant 主题中添加文章版权信息和相关文章推荐功能,使您的博客更具专业性和用户友好性。