【Win10】Hexo 搭建個人主頁 (十)添加版權說明(更新配置版)

前言

本篇博文是關於添加版權說明。


如果對於搭建等其它方面有需要了解的,讀者可以閱讀前幾篇比較優質的文章:

推薦閱讀:【Win10】搭建個人博客 Hexo框架 (自制)

推薦閱讀:【Win10】搭建個人博客 Hexo框架(部署到 github 上並 導入美化樣式 )

推薦閱讀:【Win10】Hexo 搭建個人主頁 (一)解決所有文章,缺失模塊問題

推薦閱讀:【Win10】Hexo 搭建個人主頁 (二)配置圖片資源

推薦閱讀:【Win10】Hexo 搭建個人主頁 (三)文章顯示摘要

推薦閱讀:【Win10】Hexo 搭建個人主頁 (四)文章顯示目錄

推薦閱讀:【Win10】Hexo 搭建個人主頁 (五)增加歸檔菜單

推薦閱讀:【Win10】Hexo 搭建個人主頁 (六)修改代碼塊樣式

推薦閱讀:【Win10】Hexo 搭建個人主頁 (七)增加不蒜子統計

推薦閱讀:【Win10】Hexo 搭建個人主頁 (八)添加Gitment評論系統

推薦閱讀:【Win10】Hexo 搭建個人主頁 (九)添加字數統計和閱讀時長功能

準備工作

大家可以跳到後面的更新版!

1.1在文末添加聲明

themes/yilia/layout/_partial/article.ejs文件的指定位置如下:

<%- post.content %>
	<% } %>
	<-- 在此處添加代碼-->
	<% if ((theme.reward_type === 2 || (theme.reward_type === 1 && post.reward)) && !index){ %>

添加如下代碼:

 <!-- 添加版權聲明 -->
    <%
  var sUrl = url.replace(/index\.html$/, '');
  sUrl = /^(http:|https:)\/\//.test(sUrl) ? sUrl : 'https:' + sUrl;
%>
<% if ((theme.declare_type === 2 || (theme.declare_type === 1 && post.declare)) && !index){ %>
  <div class="declare">
    <strong>本文作者:</strong>
    <% if(config.author != undefined){ %>
      <%= config.author%>
    <% }else{%>
      <font color="red">請在博客根目錄“_config.yml”中填入正確的“author”</font>
    <%}%>
    <br>
    <strong>本文鏈接:</strong>
    <a href="<%= config.url %>/<%= post.path %>" title="<%= post.title %>" target="_blank"><%= config.url %>/<%= post.path %></a>
    <br>
    <strong>版權聲明:</strong>
    本作品採用
    <a rel="license" href="<%= theme.licensee_url%>"><%= theme.licensee_name%></a>
    進行許可。轉載請註明出處!
    <% if(theme.licensee_img != undefined){ %>
      <br>
      <a rel="license" href="<%= theme.licensee_url%>"><img alt="知識共享許可協議" style="border-width:0" src="<%= theme.licensee_img%>"/></a>
    <% } %>
  </div>
<% } else {%>
  <div class="declare" hidden="hidden"></div>
<% } %>
      <!-- 添加版權聲明 -->
1.2添加樣式

在文件yilia/source/main.0cf68a.css中添加:

/*版權聲明的樣式*/
.declare {
  background-color: #eaeaea;
  margin-top: 2em;
  border-left: 3px solid #ff1700;
  padding: .5em 1em; 
}
1.3在主題中開啓設置

在文件themes/yilia/_config.yml中添加:

# 版權聲明
#在需要進行版權聲明的文章的md文件頭部,設置屬性declare: true。
#版權基礎設定:0-關閉聲明; 1-文章對應的md文件裏有declare: true屬性,纔有版權聲明; 2-所有文章均有版權聲明
declare_type: 1
licensee_url: https://creativecommons.org/licenses/by-nc-sa/4.0/        #當前應用的版權協議地址。
licensee_name: '知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議'        #版權協議的名稱
licensee_img: https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png    #版權協議的Logo

更新配置版

在文件themes/yilia/_config.yml中添加:

# 版權聲明
#在需要進行版權聲明的文章的md文件頭部,設置屬性declare: true。
#版權基礎設定:0-關閉聲明; 1-文章對應的md文件裏有declare: true屬性,纔有版權聲明; 2-所有文章均有版權聲明
declare:
  declare_type: 1
  licensee_url: https://creativecommons.org/licenses/by-nc-sa/4.0/        #當前應用的版權協議地址。
  licensee_name: 'CC BY-NC-SA 4.0'                                        #版權協議的名稱
  licensee_alias: '知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議'       # alias別名
  licensee_img: https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png    #版權協議的Logo

Hexo\themes\yilia\layout\_partial\post\下新建declare.ejs

<!-- 《添加版權聲明 -->
<!--添加版權聲明https://github.com/JoeyBling/hexo-theme-yilia-plus/commit/c1215e132f6d5621c5fea83d3c4f7ccbcca074a3-->
<%
  var sUrl = url.replace(/index\.html$/, '');
  sUrl = /^(http:|https:)\/\//.test(sUrl) ? sUrl : 'https:' + sUrl;
%>

<!-- #版權基礎設定:0-關閉聲明; 1-文章對應的md文件裏有declare: true屬性,纔有版權聲明; 2-所有文章均有版權聲明 -->
<% if ((theme.declare.declare_type === 2 || (theme.declare.declare_type === 1 && post.declare)) && !index){ %>
  <div class="declare">
    <strong class="author">本文作者:</strong>
    <% if(config.author != undefined){ %>
      <%= config.author%>
    <% }else{%>
      <font color="red">請在博客根目錄“_config.yml”中填入正確的“author”</font>
    <%}%>
    <br>
    <strong class="create-time">發佈時間:</strong>
    <%- date(post.date, 'YYYY-MM-DD') %>
    <br>
    <strong class="update-time">最後更新:</strong>
    <%- date(post.updated, 'YYYY-MM-DD') %>
    <br>
    <strong class="article-titles">本文標題:</strong>
    <a href="<%= config.url %>/<%= post.path %>" title="<%= post.title %>" target="_blank"><%= post.title %></a>
    <br>
    <strong class="article-url">本文鏈接:</strong>
    <a href="<%= config.url %>/<%= post.path %>" title="<%= post.title %>" target="_blank"><%= config.url %>/<%= post.path %></a>
    <br>
    <strong class="copyright">版權聲明:</strong>
    本作品採用
    <a rel="license" href="<%= theme.declare.licensee_url%>" title="<%= theme.declare.licensee_alias %>"><%= theme.declare.licensee_name%></a>
    許可協議進行許可。轉載請註明出處!
    <% if(theme.declare.licensee_img != undefined){ %>
      <br>
      <a rel="license" href="<%= theme.declare.licensee_url%>"><img alt="知識共享許可協議" style="border-width:0" src="<%= theme.declare.licensee_img%>"/></a>
    <% } %>
  </div>
<% } else {%>
  <div class="declare" hidden="hidden"></div>
<% } %>
<!-- 添加版權聲明》 -->

themes/yilia/layout/_partial/article.ejs文件的指定位置如下:

<%- post.content %>
	<% } %>
	<-- 在此處添加代碼-->
	<% if ((theme.reward_type === 2 || (theme.reward_type === 1 && post.reward)) && !index){ %>

添加如下代碼:

<!-- 《添加版權聲明 -->
<% if(theme.declare){%>
    <%- partial('post/declare') %>
<% } %>
<!-- 添加版權聲明》 -->

效果圖:

在這裏插入圖片描述

學如逆水行舟,不進則退
發佈了538 篇原創文章 · 獲贊 1515 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章