Github的Pages创建Blog, 并支持数学公式渲染

github创建Pages的网页静态页面仓库

github仓库名为 github用户名.github.io

github创建blog的仓库

名字随便

hexo 安装

安装nodejs

安装git

情况npm缓存

1
npm cache clean --force

修改npm镜像源为npmmirror(淘宝镜像源已经过期)

1
npm config set registry https://registry.npmmirror.com

安装hexo

1
npm install -g hexo-cli

hexo 初始化

1
2
3
4
hexo init blog
cd blog
npm install
hexo server

安装hexo通过git发布的插件

1
npm install hexo-deployer-git --save

修改_config.yml文件

1
2
3
4
deploy:
type: git
repository: https://github.com/github用户名/github用户名.github.io.git
branch: main

安装 NexT 模板

1
2
npm install hexo-theme-next
git clone https://github.com/next-theme/hexo-theme-next themes/next

修改_config.yml文件 theme: next

hexo 配置

修改_config.yml文件

同步生成文件夹 post_asset_folder: true

修正路径(渲染器设置)

1
2
3
marked:
prependRoot: true
postAsset: false

安装pandoc

  1. 下载并安装pandoc:下载地址

  2. 选择安装到全部用户

  3. 检查_config.yml中是否有以下配置

    1
    2
    pandoc:
    pandoc_path: C:/Program Files/Pandoc/pandoc.exe

更换渲染器

1
2
npm un hexo-renderer-marked --save
npm i hexo-renderer-pandoc --save

配置数学公式

1
2
npm install hexo-filter-mathjax
hexo clean

如果需要使用 MathJax 来加载公式,对应文档的的文件头加入一个选项:mathjax: true,可以根据个人需求是否加入位于 scaffolds/post.md 文件模板中。

Hexo命令

启动hexo服务

1
hexo s

本机预览草稿

1
hexo S --draft

生成静态文件

1
hexo g

发布静态文件

1
hexo d

创建文章

1
hexo new "My New Post"

创建草稿

1
hexo new draft "new draft"

查看草稿

1
hexo server --drafts

发布草稿为文章

1
hexo publish [layout] <filename>
1
hexo publish draft <filename>

参考资料

https://hexo.io/docs/

http://home.ustc.edu.cn/~liujunyan/blog/hexo-next-theme-config/