终于弄好了www

经过一天的不懈奋斗,在经过了jekyll配置环境的痛苦折磨之后,最后选择了用hexo+github pages配置,hexo是一款静态博客工具,使用起来比较简单,指比让从来没有配过ruby的我去弄明白jekyll简单多了!

配置方法

  • 新建github仓库,名为<username>.github.io,这个是后来访问用的
  • 回到本地命令行(笔者用的是wsl
    1
    2
    3
    4
    5
    6
    npm install -g hexo-cli
    sudo npm install -g hexo-cli (Mac) # 据说Mac得这么干
    cd AN-EMPTY-FLRODER # 进入你想放置的本地文件夹 一定要是空的!
    hexo init # 初始化hexo内容
    npm install # 下载配置
    npm install hexo-deployer-git --save # 下载部署工具
  • 此时环境基本配置完毕了,开始修改配置,打开_config.yml,将其Deployment部分改为
    1
    2
    3
    4
    deploy:
    type: git
    repository: git@github.com:<username>/<username>.github.io.git
    branch: main
  • 部署准备完成
    1
    hexo g -d # 生成页面并部署

此时可以访问https://<username>.github.io访问自己的博客!

操作方法

1
2
3
4
5
6
7
8
hexo new "name"       # 新建文章
hexo new page "name" # 新建页面
hexo g # 生成页面
hexo d # 部署
hexo g -d # 生成页面并部署
hexo s # 本地预览
hexo clean # 清除缓存和已生成的静态文件
hexo help # 帮助

更换主题

进入网站https://hexo.io/themes/可以选择主题,挑选好后进行配置,配置方法为在博客根目录.下执行如下命令:

1
git clone THEME-REPO themes/<theme-name>

例如本博客使用的是stellar主题,执行命令为:

1
git clone git@github.com:xaoxuu/hexo-theme-stellar.git themes/stellar

下载好后,在./_config.yml下修改theme的内容为你想要的即可

致谢

https://zhuanlan.zhihu.com/p/60578464

Debug

  • TypeError: Cannot read properties of null (reading 'utcOffset')
    • 时区设置错误,允许的中国时区只有Asia/Harbin,Asia/Shanghai,Asia/Chongqing,Asia/Urumqi,Asia/Kashgar
  • 无法生成.html文件
    • 检查themes下的文件名和配置文件中的是否相同,如果相同尝试先clean再重新创建,如果还是不行则直接重新clone一下主题库(原因未知)
  • 行内公式无法渲染
    • 更换md渲染器,并添加Katex支持,方法为:
      1
      2
      3
      npm un hexo-renderer-marked --save
      npm i hexo-renderer-markdown-it --save
      npm i @traptitech/markdown-it-katex --save
      并在_config.yml中加入(注意缩进):
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      markdown:
      preset: 'default'
      render:
      html: true
      xhtmlOut: true
      breaks: true
      langPrefix: 'language-'
      linkify: true
      typographer: true
      quotes: '“”‘’'
      plugins:
      - plugin:
      name: '@traptitech/markdown-it-katex'
      options: # see https://katex.org/docs/options.html
      blockClass: "math-block"
      strict: false
      throwOnError: false
      errorColor: "#cc0000"
  • 单纯做了上面的操作之后会出现行内数字/字母重复渲染的现象,也即一遍纯文本一遍公式文本,例如’ISP’会被渲染成’ISPISPISP
    • 在文章头部加上katex: true即可
  • 静态图片问题
    • 使用相对于source文件夹的绝对路径,例如/assets/...代表存在/blog/sources/assets/...下,这样在本地md可能显示会有问题,但是stellar可以正常生成