本文首发于Ray's Blog
最近把博客的主题换成了Icarus。这个主题不自带版权保护,我决定自己动手加一个。
Step 1. 打开/themes/icarus//languages/zh-CN.yml
,添加如下内容:
copyright:
title: "本文标题: "
author: "本文作者: "
link: "原文链接: "
license_title: "版权声明: "
date: "发布时间: "
license_content: "本网站所有文章除特别声明外,均采用 %s 许可协议。非商业转载请注明出处!"
Step 2. 打开/themes/icarus/layout
,新建copyright.ejs
,内容如下:
<div>
<ul class="post-copyright">
<li class="post-copyright-title">
<strong><%= __('copyright.title') %></strong>
<a href="<%- config.root %><%- post.path %>" target="_blank" title="本文标题: <%- page.title %>"><%- page.title %></a>
</li>
<li class="post-copyright-author">
<strong><%= __('copyright.author') %> </strong></a>
<a href="<%- config.root %>" target="_blank" title="本文作者: <%= config.author%>"><%= config.author%></a>
</li>
<li class="post-copyright-link">
<strong><%= __('copyright.link') %> </strong>
<a href="<%- config.root %><%- post.path %>" target="_blank" title="原文链接: <%- config.url %>/<%- post.path %>"><%- config.url %>/<%- post.path %></a>
</li>
<li class="post-copyright-date">
<strong><%= __('copyright.date') %> </strong></a>
<a href="/archives" target="_blank" title="发布时间: <%= page.date.format("YYYY-MM-DD HH:MM")%>"><%= page.date.format("YYYY-MM-DD HH:MM")%></a>
</li>
<li class="post-copyright-license">
<strong><%= __('copyright.license_title') %> </strong>
<%- _p('copyright.license_content', '<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>') %>
</li>
</ul>
</div>
Step 3. 在/layout/common/article.ejs
中添加如下内容(引入copyright.ejs
):
<% const services = has_config('donate') ? get_config('donate') : []; %>
<% if (!index && services.length > 0) { %>
<div class="card">
<div class="card-content">
<h3 class="menu-label has-text-centered"><%= __('donate.title') %></h3>
<div class="buttons is-centered">
<% for (let service of services) {
const type = get_config_from_obj(service, 'type');
if (type !== null) { %>
<%- _partial('donate/' + type, { type, service }) %>
<% }
} %>
</div>
</div>
</div>
<% } %>
+ <% if (!index && page.copyright){ %>
+ <%- partial('copyright') %>
<% } %>
<% if (!index && (post.prev || post.next)) { %>
<div class="card card-transparent">
<div class="level post-navigation is-flex-wrap is-mobile">
<% if (post.prev){ %>
<div class="level-start">
<a class="level level-item has-link-grey <%= !post.prev ? 'is-hidden-mobile' : '' %> article-nav-prev" href="<%- url_for(post.prev.path) %>">
<i class="level-item fas fa-chevron-left"></i>
<span class="level-item"><%= post.prev.title %></span>
</a>
</div>
<% } %>
<% if (post.next){ %>
<div class="level-end">
<a class="level level-item has-link-grey <%= !post.next ? 'is-hidden-mobile' : '' %> article-nav-next" href="<%- url_for(post.next.path) %>">
<span class="level-item"><%= post.next.title %></span>
<i class="level-item fas fa-chevron-right"></i>
</a>
</div>
<% } %>
</div>
</div>
<% } %>
最后打开你的博客,大功告成。