在Hexo中自动为Yilia主题增加版权声明

1.在themes/yilia/layout/_partial/article.ejs中标注的位置添加代码

<div class="article-entry" itemprop="articleBody">
	<% if (post.excerpt && index){ %>
		<%- post.excerpt %>
		<% if (theme.excerpt_link) { %>
			<a class="article-more-a" href="<%- url_for(post.path) %>#more"><%= theme.excerpt_link %> >></a>
		<% } %>
	<% } else { %>
		<%- post.content %>
	<% } %>
	<-- 在此处添加代码-->
	<% if ((theme.reward_type === 2 || (theme.reward_type === 1 && post.reward)) && !index){ %>
	<div class="page-reward">
		<a href="javascript:;" class="page-reward-btn tooltip-top">
		<div class="tooltip tooltip-east">

添加的代码如下

<%
  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>
    <%= sUrl%>
    <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>
<% } %>

2.更改声明样式

创建新文件themes/yilia/source-src/css/declare.scss,添加如下CSS代码。

.declare {
    background-color: #eaeaea;
    margin-top: 2em;
    border-left: 3px solid #ff1700;
    padding: .5em 1em;
}

3.为themes/yilia/source-src/css/main.scss添加如下代码。

@import "./declare";

4.生成新的代码,完成修改

如果你之前没有修改过Yilia,请先使用以下命令安装依赖。
进入主题根目录cd themes/yilia
安装依赖。

npm install

安装的时候遇到Bug
在这里插入图片描述
网上说用:(但是我的不行)

npm install --save-dev node-sass

最后没能解决,只好重新再搭一次(唉。。。。)

生成新主题
在themes/yilia/目录下输入:
npm run dev 生成新代码。
npm run dist 生成新代码,并压缩。

添加配置文件
修改themes/yilia/_config.yml
在需要进行版权声明的文章的md文件头部,设置属性

declare: true。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值