这是我的第一篇博客,因为暂时没有什么内容需要记录,就记录一下这个博客创建的过程。

这里是参考博文链接,这里是主题Butterfly的链接地址。

参考博文的记录非常详细了,这里主要记录一些我认为重要的以及踩过坑的地方。

创建文章

1
hexo new post article-title

这里article-title是要创建的.md文件的名称。

Hexo清理、生成、运行与提交

  • Hexo清理

    1
    hexo clean
  • Hexo生成

    1
    hexo g
  • Hexo运行

    1
    hexo s

输入指令后根据提示就可以在http://localhost:4000看到预期结果了

  • Hexo提交
    1
    hexo d

这里需要先在_config.yml配置发布,代码如下:

1
2
3
4
5
deploy:
type: git
repo: https://github.com/ruishaopu561/ruishaopu561.github.io
branch: hexo
message: update blog again, maybe something useful

branch是你上传代码的分支,message是上传时提交的信息(其实hexo d就是做了git add到push那一套)

关于github上的repo

在你应用主题之后,发布上去的应该是public文件夹里的代码,这也正是hexo g生成文件的位置。所以如果网站访问有问题的话应该去看看github里的文件分别是什么。

应用主题之后的修改

应用主题之后可能会想修改默认背景、默认头像等。这里可以参考Butterfly主题的参考文档

解决markdown里latex公式显现问题

参考链接1
参考链接2

第一步:删除无用包

1
2
npm uninstall hexo-renderer-marked --save
npm uninstall hexo-math --save

第二步:安装新的替换包

1
2
npm install hexo-renderer-kramed --save
npm install hexo-renderer-mathjax --save

第三步:修改代码

更改<your-project-dir>/node_modules/hexo-renderer-kramed/lib/renderer.js,更改:

1
2
3
4
5
// Change inline math rule
function formatText(text) {
// Fit kramed's rule: $$ + \1 + $$
return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');
}

为:
1
2
3
4
// Change inline math rule
function formatText(text) {
return text;
}

更新 Mathjax 的 CDN 链接,打开<path-to-your-project>/node_modules/hexo-renderer-mathjax/mathjax.html,把<script>更改为:

1
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

更改默认转义规则
打开<path-to-your-project/node_modules/kramed/lib/rules/inline.js

把:

1
escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,

更改为:
1
escape: /^\\([`*\[\]()# +\-.!_>])/,


1
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

更改为:
1
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

第四步:开启mathjax

主题里的_config.yml中开启 Mathjax, 找到 mathjax 字段添加如下代码:

1
2
mathjax:
enable: true

在博客中开启 Mathjax,添加以下内容:

1
2
3
4
---
···
mathjax: true
---