hexo杂谈

写一些写博客时踩过的坑,还有用hexo写博客时常用的东西

神里镇文

一些报错

Deployer not found: git

已经在站点配置文件中写入了

1
2
3
4
deploy:
type: git
repository: git@github.com:jensentsts/jensentsts.github.io.git
branch: main

但是执行hexo d报错ERROR Deployer not found: git

解决方案
安装hexo-deployer-git插件

1
npm install hexo-deployer-git --save

然后就可以愉快地hexo d啦~

github的坑

必看!github的url区分大小写的坑

比如我博客的url就是 https://jensentsts.github.io//后填写的便是目录
理论上来讲,/后边的东西不区分大小写
但!是!
github是区分大小写的!例如linkLink就不是同一个东西
因此如果你用主题文件夹里的_config.yml把你的友链页面设为links/index.md,而你在sources/下的对应文件夹名称为Links
你在loaclhost:4000里能够正常访问友链页面
然而当你在github上点击友链,使用https://jensentsts.github.io/links/index.html 去访问你的友链时,github不能给你返回对应的页面,会报404
如果你去你的github库里检查,会发现links正在好好地躺在你的库里
解决方案:大小写完全一致,即在主题的_config.yml里的和在sources/下的名称完全一致

现在的github使用main分支

写这一条的时间是2021年12月10日,注意信息的时效性
以前都是用master作为主分支的,现在默认生成的是main,注意修改你的_config.yml

这里是杂谈

为文章添加多个标签

在你的markdown文件头部,也就是俩---之间的部分,添加如下代码:

1
tags: [标签1, 标签2, 标签3]

当然,这样也是可以的:

1
2
3
tags:
-_标签1_
-_标签2_

上面写的_是空格的意思,-和标签后面都必须有一个空格。

截取文章摘要

手动在文章合适的位置添加<!--more-->。不同的主题写

给文章置顶

简单粗暴的方法:把date改成99999-12-31 23:59:59
然后就是使用现成的库

1
2
$ npm uninstall hexo-generator-index --save
$ npm install hexo-generator-index-pin-top --save

然后在你的文章前面的---之间加上top: true即可,比如说:

1
2
3
4
---
title: 友情链接
top: true
---

如果想直接修改主题的文件,你也可以参考这篇文章

草稿

我不用草稿……

1
2
hexo new draft 文章名称
hexo n draft 文章名称

记录你的更新时间

依旧是在.md文件顶头的---之间写updated: 年年年年-月月-日日 时时:分分:秒秒

使用LaTeX

首先要保证你的主题是支持LaTeX的!!!你得阅读主题的文档。如果支持,就去找用kramed或者是pandoc的使用mathjax的教程吧
我当时配置了两个小时都没成功,最后发现是Lite主题不支持LaTeX……
如果你的主题不支持LaTeX,但你又不想换,可以用知乎的开放API……也就是https://www.zhihu.com/equation?tex=[你的LaTeX公式],效果:图片挂了QAQ……
当然写进url的公式里的任何\都要转义成%5C
因为能支持,所以我才换了material 这个主题……。现在让我们来欣赏一下欧拉恒等式吧:
$$ e^{i\pi}+1=0 $$
如果没有写·per_page: true·,记得在.md文件顶部写mathjax: true
补充:有的主题会为mathjax等插件专门写了设置,请查看自己的主题的_config.yml以正常使用mathjax。

插件推荐

有的主题可能不支持一些插件
列出来的yaml代码, 请在根目录下的_config.yml文件里新增该配置
专门针对SEO的优化请看这篇文章

代码高亮

npm i hexo-prism-plugin -s

1
2
3
4
5
prism_plugin:
mode: 'preprocess' # realtime/preprocess
theme: 'tomorrow' # 主题选项
line_number: false # false
custom_css:

可选主题:

coy,dark,funky,okaidia,solarizedlight,tomorrow,twilight,a11y-dark,atom-dark,
base16-ateliersulphurpool.light,cb,darcula,dracula,duotone-dark,duotone-earth,
duotone-forest,duotone-light,duotone-sea,duotone-space,ghcolors,hopscotch,
material-dark,material-light,material-oceanic,pojoaque,shades-of-purple,
synthwave84,vs,xonokai,default,

中文链接转拼音

npm i hexo-permalink-pinyin –save

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

评论emoji表情支持

npm i hexo-filter-github-emojis –save

将markdown中的emoji语法转换为emoji表情

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

压缩html、css、js、图片

npm i hexo-all-minifier –save

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
all_minifier: true

html_minifier:
enable: true
ignore_error: false
exclude:

css_minifier:
enable: true
exclude:
- '*.min.css'

js_minifier:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js'

image_minifier:
enable: false
interlaced: false
multipass: false
optimizationLevel: 2
pngquant: false
progressive: false

速度优化

见博客:Hexo博客之速度优化

一些美化hexo博客的方法

作者

勇敢梧桐树

发布于

2021-07-20

更新于

2021-12-10

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×