hexo博客next8.21.0主题美化优化教程
为了描述方便,_config.yml
称为 站点配置文件,_config.next.yml
称为 主题配置文件。
下载 next 主题文件
Hexo-Next 主题博客个性化配置超详细,超全面(两万字)_hexo next 记录访问了ip-CSDN博客
next主题项目:next-theme/hexo-theme-next: 🎉 Elegant and powerful theme for Hexo. (github.com)
在
D:\Hexo-Blog\blog-demo
文件夹下打开Open Git Bash here,输入以下命令:下载next源码git clone https://github.com/next-theme/hexo-theme-next themes/next
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo
$ git clone https://github.com/next-theme/hexo-theme-next themes/next
Cloning into 'themes/next'...
remote: Enumerating objects: 7576, done.
remote: Counting objects: 100% (994/994), done.
remote: Compressing objects: 100% (177/177), done.
remote: Total 7576 (delta 875), reused 820 (delta 817), pack-reused 6582 (from 3
)
Receiving objects: 100% (7576/7576), 1.60 MiB | 2.20 MiB/s, done.
Resolving deltas: 100% (4819/4819), done.手动将 D:\Hexo-Blog\blog-demo\themes\next 复制到博客根目录下 D:\Hexo-Blog\blog-demo 并重命名为**_config.next.yml** 即可。以后如果修改任何主题配置,都只需修改**_config.next.yml**的配置即可。
如果是第一次安装使用hexo以及next主题,还需要安装pug以及stylus的渲染器。也可以检查路径hexo-next8.23\blog-demo\node_modules下是否存在hexo-renderer-stylus和hexo-renderer-pug文件夹,如果没有,就是没有安装上面的渲染器,需要安装。安装完成后会在上面的文件夹生成2个文件hexo-renderer-stylus和hexo-renderer-pug。
npm install hexo-renderer-pug hexo-renderer-stylus --save
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo
$ npm install hexo-renderer-pug hexo-renderer-stylus --save
added 34 packages in 5s
40 packages are looking for funding
run `npm fund` for details推送到github
D:\Hexo-Blog\blog-demo 下的 Git BASH终端
hexo clean && hexo generate && hexo deploy
vscode终端下用命令:hexo cl; hexo g; hexo d
卸载自带的 landscape 主题
上面安装好next主题后,hexo自带的主题hexo-theme-landscape
就可以卸载了。npm uni hexo-theme-landscape --save
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 执行结果 |
然后在hexo-next8.23\blog-demo\node_modules
文件夹下看是否还有hexo-theme-landscape文件夹存在。
修改语言网站标题等
打开站点配置文件,搜索 language,找到如下代码:
# Site 网站标题 设置 |
切换主题
next 主题自带四种样式。在主题配置文件中查找:scheme
找到如下代码:想要那个样式,去掉前面的#
即可。
# Schemes |
在侧边栏网站名称下显示图片
自行放置一张想要显示的图片到blog-demo\themes\next\source\images
路径下,修改主题配置代码custom_logo:
的值为:/images/绝世九小姐.jpg
。
新建标签及分类界面等菜单键页面
打开 主题配置文件,搜索 menu,找到如下代码:进行修改。
menu: |
urlmark
代表网页侧边栏中的菜单名称,英文翻译成中文的话修改blog-demo\themes\next\languages
路径下的zh-CN.yml
文件,打开文件找到menu:
在其下最后添加urlmark: 网址收藏
,你想翻译成哪个中文都可以的。修改为中文的第二种方法。网上大多数的教程都是建议直接修改该文件,但是和前面提到的页面定制相似,我们并不希望直接修改主题目录中的国际化配置文件。注意到同级目录中有一个
theme/next/languages/README.md
文件,里面提供了官方建议的无侵入式地覆盖默认翻译的方法:
在 Hexo 博客项目的`` blog-demo\source路径下创建
_data文件夹,在
_data文件夹下创建一个
languages.yml `文件。添加如下配置覆盖默认翻译:# language
zh-CN:
# items
menu:
# the translation you perfer
links: 友链
guestbook: 留言板
Bookmarking: 网址收藏
Friend link: 友情链接/urlmark
表示的是要打开的文件的路径,默认是打开其下的index.md
文件。||
这后面跟的是网页菜单项前显示的图标,图标网站2hexo new page about
为新建关于页,会在blog-demo\source
文件夹下生成一个about文件夹,里面生成一个
index.md文件,在短
—`下编写关于你网站的信息即可,样式如式:
|
hexo new page tag
为新建标签页,会在blog-demo\source
文件夹下生成一个tag
文件夹,里面生成一个index.md
文件,在短---
下编写关于你网站的信息即可,title
为标签,type
为标签,即可。- 如果还要生成其它的页面,按以上格式生成修改即可。
侧边栏设置
设置头像:
设置头像圆形,停留旋转效果,修改主题配置如下:
#侧边栏头像 |
侧边栏上显示相关文章:
在主题配置文件中搜索related_posts
将enable: true
开启相关文章推荐功能。
添加社交链接:
修改主题配置如下:
#社交链接,用法:`关键字:固定链接||图标` |
修改站点页脚信息-footer
在主题配置文件中修改网站页脚信息:
footer: # 底部信息区 |
修改文章信息-meta
默认主题下, 文章标题下方会显示文章的创建时间、文章的修改时间、文章分类信息等元数据,用户可以在主题配置文件中自定义设置需要显示的 meta 元信息:
post_meta: |
文章目录信息
在主题配置中修改:
toc: |
添加打赏功能
启用主题配置文件中的打赏相关字段,并将个人收款码图片置于themes\next\source\images\
目录下,注意保持图片命名与配置文件中一致:
#捐赠(赞助商)设置,奖励设置: |
代码块选项
修改主题配置文件如下:
codeblock: |
浏览页面显示当前浏览进度
主题配置中搜索scrollpercent
,修改如下:
back2top: |
修改网站加载前特效
修改主题配置文件:
#页面加载过程中,顶部的进度条。更多信息:https://github.com/CodeByZach/pace |
图片实现全屏查看
使用第三方了图片浏览放大功能的fancybox
插件 next
主题已经集成了这个第三方插件 ,只须更改 主题配置文件将fancybox
的值设为true
即可。
启用网站与文章的浏览人数统计
在博客的底部显示网站与文章浏览的人数及次数。
# Show Views / Visitors of the website / page with busuanzi. |
修改文章模板部分
修改文章底部的#
号的标签
next8.0以上版本,可以直接在next主题文件下的_config.next.yml中查找 tag_icon
然后把后面的 false
改为 true
。
# Use icon instead of the symbol # to indicate the tag at the bottom of the post |
为啥呢,因为我在next/layout/_macro/post.njk下发现了这段代码{%- set tag_indicate = '' if theme.tag_icon else '#' %}
修改hexo
博客的字体大小 行间距。
修改blog-demo\themes\next\source\css\_variables\base.styl
文件内容如下:
// Font size 此为调整字体大小。
$font-size-base = (hexo-config('font.enable') and hexo-config('font.global.size') is a 'unit') ? unit(hexo-config('font.global.size'), em) : 1em;
$font-size-smallest = .75em;
$font-size-smaller = .8125em;
$font-size-small = .875em;
$font-size-medium = 1em;
$font-size-large = 1.0em; //这是新加行 调整字体大小
//$font-size-large = 1.125em;
$font-size-larger = 1.25em;
$font-size-largest = 1.5em;
//这是行距调整 |
修改链接文字颜色样式
修改文件模板themes\next\source\css\_common\components\post\post-body.styl
文件最后添加如下代码:
.post-body p a{ |
侧边栏上显示文章列表:
修改文件模板blog-demo\themes\next\layout\_macro\sidebar.njk
,在sidebar.njk文件的最后2行({% endmacro %}
和</aside>
)前面添加以下代码:
<!--最近文章--> |
在主题配置文件里面添加:
# 近期文章配置 |
在blog-demo\themes\next\layout\_partials\post
路径下新建文件post-recent.njk,post-recent.njk
文件里写上如下代码:
<div class="links-of-blogroll-title" style="padding-bottom: 5px; padding-top: 5px; padding-left: 0px; padding-right: 20px; font-size: 1.6em; argin-right: 5px;"> |
在blog-demo\themes\next\source\css\main.styl
文件的最后添加以下代码,给显示的最近文章添加计数:
//侧边栏计数伪类 |
给网站添加本站运行天数
在博客的底部显示本站已安全运行 1248 天 01小时27分35秒。
在文件blog-demo\themes\next\layout\_partials\footer.njk
的最后一行添加:
<div style="font-size: 0.85rem"> |
在blog-demo\source
文件夹下新建runtime.js文件。代码如下:
!(function() { |
博客增加小顶栏(工具栏)
打开文件blog-demo\themes\next\layout\index.njk
,在其中指定位置增加如下代码:
{% block class %}index posts-expand{% endblock %} |
/posts/f687/
和/posts/30c3/
是存放的post文章。其他页面同理。
为友情链接单独开个页面
hexo new page links
添加一个友情页,会在blog-demo\source\links
下生成一个index.md
文件,打开输入以下内容。
--- |
hexo
插件安装
Local Search本地搜索
此插件用于生成搜索索引文件,其中包含文章的所有必要数据,您可以使用这些数据为您的博客编写本地搜索引擎。支持 XML
和 JSON
格式输出。安装插件hexo-generator-searchdb,执行以下命令:npm install hexo-generator-searchdb
然后在站点配置文件最后添加如下代码:
search: |
编辑 主题配置文件,启用本地搜索功能:
#本地搜索,依赖关系:https://github.com/next-theme/hexo-generator-searchdb |
安装侧边栏相关文章列表插件
hexo-related-posts
是 Hexo 静态站点生成器的插件,使用 TF/IDF 算法生成相关文章列表。npm i --save hexo-related-posts
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 执行结果 |
然后在主题配置中启用:
# Related popular posts相关热门文章 没有安装包 |
隐藏文章插件
Github地址:https://github.com/printempw/hexo-hide-posts,在站点根目录下执行`npm install hexo-hide-posts –save`,在站点目录下的_config.yml中如下配置:
# hexo-hide-posts |
在文章的属性中定义 hidden: true 即可隐藏文章。
--- |
在 安装twikoo评论插件
twikoo评论插件说明
暂不支持 NexT 8 以下的版本,请先升级到 NexT 8。然后在 Hexo 项目根目录执行
# For NexT version >= 8.0.0 && < 8.4.0 #8.0到8.4的版本用下面这个 |
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 执行结果 |
然后在主题配置文件修改配置:
comments: |
字数统计和阅读时长插件
主题 配置文件中已经有了hexo-word-counter这个插件的配置,但是没有安装插件包,插件包地址,所有只在主题配置中设置还是不行的。
npm i -- save hexo-word-counter |
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 代码执行结果 |
然后在主题配置文件中启用:
# Post wordcount display settings Hexo 文章的字数统计和阅读时长 没有安装包 |
文章加密插件
首先, hexo-blog-encrypt这是 Hexo 生态圈中 最好的 博客加密插件。在线演示, 所有的密码都是 hello。安装命令npm install --save hexo-blog-encrypt
,安装完成之后,把将 “password” 字段添加到您文章信息头就像这样。
--- |
- 高级设置 具体设置请查看这里
title: Hello World
tags:
- 作为日记加密
date: 2016-03-30 21:12:21
password: mikemessi
abstract: 有东西被加密了, 请输入密码查看.
message: 您好, 这里需要密码.
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
flowchart 流程图插件
hexo默认不支持流程图,flowchart简便易食,可以瞬间使hexo流程图无中生有。
npm install --save hexo-filter-flowchart |
语法结构:X=>Y: Z。其中,X是变量名, Y是指操作模块名,冒号后面的Z是具体显示的文字内容。需要注意的是,冒号后要加空格才能识别,而X,Y与=>之间不允许有空格。
节点Y的固定内容。start=》开始,end=》结束,operation=》普通操作块,subroutine=》子任务块,condition=》判断块,intputoutput=》输入输出块。
连接方向。连接线有上下左右四个方向,如果需要指定连接线连接到某一特定方向,在连接线开始的元素后面添加方向即可,方向包括:(top),(bottom),(left),(right)。
如果要设置条件框连接线方向,在括号中添加即可。条件框只有两个方向可供选择:yes向下,no向右(默认),yes向右,no向下。cond(yes,right),cond(no,bottom)。
在hexo站点配置文件中修改
highlight: # 代码块的设置, 请参考 Highlight.js 进行设置
exclude_languages: # 美人鱼流程图
- mermaid
line_number: false
auto_detect: false
tab_replace: ''
wrap: true
hljs: false在主题 配置文件中开启美人鱼流程图设置, Hexo 配置文件也要设置
# Mermaid tag
mermaid:
enable: true
# Available themes: default | dark | forest | neutral
theme:
light: default
dark: dark百度站点地图插件
npm install hexo-generator-baidu-sitemap --save
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo
$ npm install hexo-generator-baidu-sitemap --save
npm warn deprecated lodash.pick@4.4.0: This package is deprecated. Use destructu
ring assignment syntax instead.
npm warn deprecated rimraf@2.4.5: Rimraf versions prior to v4 are no longer supp
orted
npm warn deprecated source-map-url@0.4.1: See https://github.com/lydell/source-m
ap-url#deprecated
npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprec
ated
npm warn deprecated glob@6.0.4: Glob versions prior to v9 are no longer supporte
d
npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/sour
ce-map-resolve#deprecated
npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#dep
recated
npm warn deprecated hexo-bunyan@1.0.0: Please see https://github.com/hexojs/hexo
-bunyan/issues/17
npm warn deprecated cuid@1.3.8: Cuid and other k-sortable and non-cryptographic
ids (Ulid, ObjectId, KSUID, all UUIDs) are all insecure. Use @paralleldrive/cuid
2 instead.
npm warn deprecated swig-templates@2.0.3: unmaintained
npm warn deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgra
de to @latest
npm warn deprecated core-js@1.2.7: core-js@<3.23.3 is no longer maintained and n
ot recommended for usage due to the number of issues. Because of the V8 engine w
hims, feature detection in old core-js versions could cause a slowdown up to 100
x even if nothing is polyfilled. Some versions have web compatibility issues. Pl
ease, upgrade your dependencies to the actual version of core-js.
added 235 packages in 17s
56 packages are looking for funding
run `npm fund` for details安装完成后,每次进行打包的时候,会自动在public文件夹下生成``sitemap.xml
和
baidusitemap.xml`分别用于Google和百度。将页面提交到服务器后,通过域名/sitemap.xml或者域名/baidusitemap.xml可以进行访问sitemap。
Google 版本
npm install hexo-generator-sitemap --save
参考:https://zhuanlan.zhihu.com/p/150999914
站点配置文件中添加以下代码:
baidusitemap:
path: baidusitemap.xml设置百度主动推送
安装``hexo-baidu-url-submit`插件。
npm install hexo-baidu-url-submit --save
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 执行结果
$ npm install hexo-baidu-url-submit --save
added 2 packages in 3s
56 packages are looking for funding
run `npm fund` for details在站点配置文件中添加baidu-url-submit的配置项
baidu_url_submit:
count: 1000 ## 提交最新的1000个链接
host: https://blog.bere.top/ ## 在百度站长平台中注册的域名
token: rNAJGHTNfQltcUPa #请注意这是您的秘钥, 所以请不要把博客源代码发布在公众仓库里!
path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里安装hexo-seo-submit
hexo7.3.0和next主题8.23现在只能安装hexo-seo-submit@0.11.0-@0.15.0的版本,
如果版本太高会出现错误:
ERROR Plugin load failed: hexo-seo-submit
安装hexo-seo-submit@0.15.0
npm i --save [email protected]
Administrator@DESKTOP-O7B3NJL MINGW64 /d/hexo-next8.23/blog-demo 执行结果
$ npm i --save hexo-seo-submit@0.15.0
added 19 packages in 3s
58 packages are looking for funding
run `npm fund` for details然后在站点配置文件中添加以下代码:
# 生成站点地图,被搜索 这个没用上 没有适用的版本
hexo-seo-submit:
sortBy: updated # created | updated, default created
count: 2 # set all engine count, default 10
fileRootPath: hexo-seo-submit # will generate in root/public/fileRootPath, default '', root/public/
CI:
enable: true
cron: 0 4 * * *
platform: github # github | coding, default gitHub
branch: main # actions trigger branch, default master
baidu:
enable: true # default false
path: baidu.txt # default google.txt
count: 1
token: rNAJGasdfwcUPa
google:
enable: true
path: google-url.txt # default google.txt
# find path in root
accountKeysJSonFile: google.json # path.join(process.cwd(), path)
count: 2
# maybe required
proxy: http://127.0.0.1:7890
bing:
enable: true
apiKey: da53b5f392234d0ab22
sortBy: created # default created
path: bing.json
Markdown 和 Visual Studio Code
Markdown 编写教程
一次完整的Hexo写作流程
博客文章加密:
微信公众号引流插件:https://docs.techgrow.cn/v1/wechat/tutorial/hexo/