Hexo Icarus 博客搭建过程

本篇为博主的部分魔改重装日记,以防自己日后因魔改迷失所做记录 📝

本帖涉及魔改源码的内容,会使用 diff 代码块标识,复制时请不要忘记删除前面的+、-符号。

准备工作

本电脑配置:
Windows 11
CPU:Intel i3-12100F

安装下列应用程序的最新版本(括号内为本教程使用版本):

安装 Hexo

本教程使用进阶安装(仅局部安装 hexo 包):

1
npm install hexo

将终端目录cd至将要搭建博客的文件夹。鉴于每个人的根目录名称都不一样,本帖博客根目录一律以 [BlogRoot] 指代。
Hexo 初始化并安装 npm 插件:

1
2
npx hexo init
npm install

切换主题

本博客使用 Icarus 主题,将以 Icarus 主题为例进行配置。
主题配置方法一般在主题的 Github 仓库或主题官网教程中说明。
Icarus 主题 Github仓库 & Icarus 主题官网

1
2
npm install hexo-theme-icarus
hexo config theme icarus

本人喜欢将主题文件(位于 [BlogRoot]/node_modules/hexo-theme-icarus/)移动至 [BlogRoot]/themes/icarus/ 文件夹下,以便于对主题进行魔改操作。

将 [BlogRoot]/_config.yml 中主题名改动:

1
2
## Themes: https://hexo.io/themes/
theme: icarus

配置文章链接转数字或字母

参考: hexo-abbrlink 项目 Github 仓库

百度蜘蛛抓取网页的规则: 对于蜘蛛说网页权重越高、信用度越高抓取越频繁,例如网站的首页和内页。蜘蛛先抓取网站的首页,因为首页权重更高,并且大部分的链接都是指向首页。然后通过首页抓取网站的内页,并不是所有内页蜘蛛都会去抓取。

搜索引擎认为对于一般的中小型站点,3层足够承受所有的内容了,所以蜘蛛经常抓取的内容是前三层,而超过三层的内容蜘蛛认为那些内容并不重要,所以不经常爬取。出于这个原因所以permalink后面跟着的最好不要超过2个斜杠。

使用 hexo-abbrlink 插件可以完美解决,具体使用方法如下:

安装 npm 包:

1
npm install hexo-abbrlink --save

在 [BlogRoot]/_config.yml 中:

1
2
3
4
5
6
7
8
9
- permalink: :year/:month/:day/:title/
+ permalink: p/:abbrlink/ # 此处可以自己设置,也可以直接使用 :/abbrlink

...

+ # abbrlink config
+ abbrlink:
+ alg: crc32 #算法: crc16(默认) and crc32
+ rep: hex #进制: dec(默认) and hex

alg 与 rep 示例:

1
2
3
4
5
6
7
8
9
crc16 & hex
https://test.com/posts/55c6.html
crc16 & dec
https://test.com/posts/43212.html

crc32 & hex
https://test.com/posts/6ec16a2c.html
crc32 & dec
https://test.com/posts/1521457752.html

新增 RSS 功能支持

参考: hexo-generator-feed 项目 Github 仓库
安装插件:

1
npm install hexo-generator-feed --save

新增首页文章隐藏功能

安装插件:

1
npm install hexo-hide-posts --save

在 [BlogRoot]/_config.yml 中:

1
2
3
4
5
6
7
8
9
10
# hexo-hide-posts
hide_posts:
enable: true
# Change the filter name to fit your need
filter: hidden
# Generators which you want to expose all posts (include hidden ones) to.
# Common generators: index, tag, category, archive, sitemap, feed, etc.
public_generators: []
# Add "noindex" meta tag to prevent hidden posts from being indexed by search engines
noindex: true

在文章配置中加入以下代码可实现其在首页的隐藏:

1
+ hidden: true

新增新年倒计时挂件

详见 Hexo Icarus 新年倒计时挂件

新增黑暗模式

详见 Icarus主题魔改/#主题夜间模式 | Winky’s Blog

新增图片懒加载

详见 使用 gulp 压缩 Hexo 博客文件(兼容 ES6 标准) | Ming’s Blog

Hexo Icarus 博客搭建过程

http://blog.junewind.top/p/32865/

作者

JuneWind

发布于

2024-02-06

更新于

2024-01-31

许可协议

评论