最近才知道hexo可以搭建博客,果然又一次孤陋寡闻了,我是和GitHub连用,所以都是以它为例,下面正文开始

创建

这个博客中,很详细,具体参考就他了:https://caiyantao.gitee.io/2019/04/13/Hexo-%E4%B8%80/

主题更改

这个链接里是提供的所有主题:https://hexo.io/themes/index.html,大家可以查找自己欢喜的,然后下载即可

1
$ git clone https://github.com/theme-next/hexo-theme-next themes/next

个性化设置

编辑_config.yml

1
2
3
4
5
6
7
8
# Site
title: Hexo
subtitle: ''
description: ''
keywords:
author: Zhappy
language: zh-CN # default en, select from `themes/landscape/languages/`
timezone: Asia/Shanghai

Update

NexT releases new versions every month. You can update to latest master branch by the following command:

1
2
$ cd themes/next
$ git pull

扩展

LaTex

hexo默认渲染引擎是marked,但是没得mathjax,所以要配置一下才能用,具体参考:https://www.jianshu.com/p/68e6f82d88b7
成功后,效果如下
$x^2+y^2+z^2=r^2$

代码高亮

由于 Hexo 自带的代码高亮主题显示不好看,所以主题中使用到了 hexo-prism-plugin 的 Hexo 插件来做代码高亮,安装命令如下:

1
npm i -S hexo-prism-plugin

然后,修改 Hexo 根目录下 _config.yml 文件中 highlight.enable 的值为 false,并新增 prism 插件相关的配置,主要配置如下:

1
2
3
4
5
6
7
8
highlight:
enable: false

prism_plugin:
mode: 'preprocess' # realtime/preprocess
theme: 'tomorrow'
line_number: false # default false
custom_css:
中文链接转拼音(建议安装)

如果你的文章名称是中文的,那么 Hexo 默认生成的永久链接也会有中文,这样不利于 SEO,且 gitment 评论对中文链接也不支持。我们可以用 hexo-permalink-pinyin Hexo 插件使在生成文章时生成中文拼音的永久链接。

安装命令如下:

1
npm i hexo-permalink-pinyin --save

在 Hexo 根目录下的 _config.yml 文件中,新增以下的配置项:

1
2
3
permalink_pinyin:
enable: true
separator: '-' # default: '-'

:除了此插件外,hexo-abbrlink 插件也可以生成非中文的链接。

添加emoji表情支持(可选的)

本主题新增了对emoji表情的支持,使用到了 hexo-filter-github-emojis 的 Hexo 插件来支持 emoji表情的生成,把对应的markdown emoji语法(::,例如::smile:)转变成会跳跃的emoji表情,安装命令如下:

1
npm install hexo-filter-github-emojis --save

在 Hexo 根目录下的 _config.yml 文件中,新增以下的配置项:

1
2
3
4
5
6
githubEmojis:
enable: true
className: github-emoji
inject: true
styles:
customEmojis:

Bug

运行npm install 总是报出以下错误WARN optional SKIPPING OPTIONAL DEPENDENCY:…
1
2
3
4
5
6
7
8
9
10
11
12
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules\hexo-prism-plugin\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ hexo-filter-github-emojis@2.1.0
added 91 packages from 124 contributors and audited 1853 packages in 27.878s

6 packages are looking for funding
run `npm fund` for details

found 2 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details

  • 原因: fsevents不在package.json里,但是仍然安装了,是因为你的系统是Windows系统,fsevents是苹果系统的可选依赖,你的项目有可能是团队项目,别人在他的mac上安装了fsevents相关依赖库,
    所以到这边你也就安装到你的windows上边了。你可以检查你的package.json 文件中是不是有fsevents相关依赖,删除即好!
    如果没有,其他的npm包也会有依赖fsevents的!!!
  • 总结: 这是warning错误,是因为mac下需要 fsevents,这里是在windows环境,所以可以忽略这个警告,对你没什么影响的。
npm WARN deprecated core-js@2.6.11: core-js@< 3 is no longer…
1
2
3
4
5
6
7
Administrator@DESKTOP-5EUBVE8 MINGW64 /d/Myblogs/blog-next
$ npm install -save hexo-helper-live2d
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

> core-js@2.6.11 postinstall D:\Myblogs\blog-next\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

解决方案:

1
npm install --save  -g core-js@^3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Administrator@DESKTOP-5EUBVE8 MINGW64 /d/Myblogs/blog-next
$ npm install --save -g core-js@^3

> core-js@3.6.4 postinstall C:\Users\Administrator\AppData\Roaming\npm\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

+ core-js@3.6.4
added 1 package in 3.739s

hexo d ERROR Deployer not found: git
1
2
3
4
Administrator@DESKTOP-5EUBVE8 MINGW64 /d/Myblogs/blog-next (master)
$ hexo d
ERROR Deployer not found: git

原因:
解决方案:这是因为没安装hexo-deployer-git插件,在站点目录下输入下面的插件安装就好了:

1
npm install --save hexo-deployer-git

参考资料

https://www.cnblogs.com/Haidrens/p/11389137.html
https://blog.csdn.net/weixin_43675566/article/details/104344744
https://blog.csdn.net/qq_21808961/article/details/84476504