分享

Hexo yilia主题启用及相关设置

 印度阿三17 2019-07-19

yilia主题作者已经不维护了,还有好多坑没有填完,在此记录一下

主题地址:https://github.com/litten/hexo-theme-yilia

主题下载并启用

进入命令行,下载yilia主题,输入:

git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia

修改站点配置文件 _config.yml,找到如下代码:

## Themes: https:///themes/
theme: landscape

landscape 修改为yilia即可。

修改语言

打开站点配置文件,搜索language,找到如下代码:

author:
language:
timezone:

language后面输入zh-CN

注意:冒号后面必须有一个空格。

“所有文章”按钮的安装

首先使用命令 node -v 检查版本是不是大于6.2

在博客根目录执行以下命令:

npm i hexo-generator-json-content --save

在博客配置文件 _config.yml 最下面加上:

jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: false
tags: true

添加图片资源文件夹

路径为 themes/yilia/source/下,可添加一个 assets 文件夹,里面存放图片资源即可

需要添加头像或者微信/支付宝二维码图片,直接引用即可。路径为 themes/yilia/_config.yml

# 微信二维码图片
weixin: /assets/img/wechat.png
# 头像图片
avatar: /assets/img/head.jpg
# 网页图标
favicon: /assets/img/head.jpg

文章显示摘要

在你 MD 格式文章正文插入 <!-- more --> 即可,只会显示它之前的,此后的就不显示,点击文章标题,全文阅读才可看到,同时注释掉文件 themes/yilia/_config.yml里的:

# excerpt_link: more

文章显示目录

增加文章目录 TOC ( table of content ),方便阅读文章, 在 themes/yilia/_config.ym中进行配置 toc: 2即可,它会将你 Markdown 语法的标题,生成目录,目录查看在右下角。

增加归档菜单

修改 themes/yilia/_config.yml 内容:

menu:
主页: /
归档: /archives/index.html

修复失效的微信分享二维码

打开themes\yilia\layout\_partial\post\share.ejs文件
把第49行中的 //pan.baidu.com/share/qrcode?url=修改为:

//api.qrserver.com/v1/create-qr-code/?size=150x150&data=

更改左侧昵称字体

themes\yilia\source\main.0cf68a.css 文件里面修改,找到 header-author ,修改里面的 font-family ,改成:

font-family:"Times New Roman",Georgia,Serif

左侧显示总文章数

打开 themes\yilia\layout_partial\left-col.ejs 文件

在:

<nav class="header-menu">
<ul>
<% for (var i in theme.menu){ %>
<li><a href="<%- url_for(theme.menu[i]) %>"><%= i %></a></li>
<%}%>
</ul>
</nav>

后面添加:

<nav>
总文章数 <%=site.posts.length%>
</nav>

添加字数统计

首先安装 hexo-wordcount

使用如下命令安装:

npm i --save hexo-wordcount

Node 版本7.6.0之前,请安装 2.x 版本 (Node.js v7.6.0 and previous)

npm install hexo-wordcount@2 --save

然后在 themes\yilia\layout\_partial\left-col.ejs中添加:

总字数 <span class="post-count"><%= totalcount(site, '0,0.0a') %></span>

编辑 themes\yilia\layout_partial\article.ejs

在header下面加入:

<div align="center" class="post-count">
字数:<%= wordcount(post.content) %>字 | 预计阅读时长:<%= min2read(post.content) %>分钟
</div>

即可显示单篇字数和预计阅读时长。

添加来必力(livere)评论系统

yilia默认带了几个系统,但是没有来必力,所以可以自己加
首先是去注册来必力,然后获取到自己的 id

新建 themes\yilia\layout\_partial\comment\livere.ejs 文件,输入如下内容:

<!-- 来必力City版安装代码 -->
<div id="lv-container" data-id="city" data-uid="<%=theme.livere_uid%>">
<script type="text/javascript">
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
j = d.createElement(s);
j.src = 'https://cdn-city./js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
</script>
<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
</div>
<!-- City版安装代码已完成 -->

然后编辑 themes\yilia\layout\_partial\article.ejs 文件,找到:<% if (!index && post.comments){ %> ,添加:

<% if (theme.livere){ %>
<%- partial('comment/livere', {
key: post.slug,
title: post.title,
url: config.url url_for(post.path)
}) %>
<% } %>

在主题配置文件 themes\yilia\_config.yml 中添加以下内容:

livere: true
livere_uid: 你的id

关闭信息收集(可选)

关于访问 litten.me:9005 的问题,这个主题的作者之前为了更好地完善这个主题,有时候会收集用户的客户端信息,详情请见https://github.com/litten/hexo-theme-yilia/issues/528 ,如果不想被统计,就将 themes\yilia\source-src\js\report.js 里面的内容清空。不过这个请求是异步的,不会影响博客加载速度,而且作者已经不维护了,所以关不关都行。

来源:https://www./content-4-339101.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多