记录一下搭建博客的过程。
安装hexo
参考内容:https://www.jianshu.com/p/9bbae1d105be
配置hexo与更换Next主题
下载主题
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
由于github被墙,使用代理科学上网后,clone经常报OpenSSL SSL_connect
的错,因此我直接在网页上下载的zip包,解压到themes/next
文件夹。
页面报错
跟换主题后重新hexo s
,页面无法显示内容,提示以下信息:
1 | {% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %} {% import '_macro/sidebar.swig' as sidebar_template %} {% block title %}{{ page.title }} | {{ config.title }}{% endblock %} {% block page_class %}page-post-detail{% endblock %} {% block content %} |
根据博客介绍,原因是hexo在5.0之后把swig给删除了需要自己手动安装,安装后解决了该问题。
1 | npm i hexo-renderer-swig |
显示公式
由于我的博客中有大量公式,页面中无法显示。参考博客解决了该问题,问题的核心是配置好两个因素:mathjax和kramed。
添加mathjax
1 | npm uninstall hexo-math --save |
换渲染引擎
1 | npm uninstall hexo-renderer-marked --save |
由于我之前瞎试,装过pandoc,也要一起卸掉:npm uninstall hexo-renderer-pandoc --save
修改渲染引擎的bug:到博客根目录下,找到node_modules\kramed\lib\rules\inline.js,第11行的 escape 变量:
1 | //escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/, |
第20行的em变量:
1 | //em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, |
配置.\themes\next\_config.yml
1 | # MathJax Support |
在文章的Front-matter里打开mathjax开关
1 | title: Hierarchical Attention Networks for Document Classification |
重启以下
1 | hexo clean |
到这里我的公式一部分能显示,一部分不能显示。继续查了查,发现别人也有这个情况,比如多行公式的时候显示不了,是因为不能出现连续的大括号{{
。我怀疑我的也是类似的问题,于是试了一下在我的:公式
的结构中,把冒号删了,居然所有公式都正常显示了,然后我又把冒号加回去,还是都可以显示!!!不知道上面那堆设置需要时间起作用还是我的修改触发了什么,总之问题解决了。
后面有查了一些博客之后,推测更有可能是浏览器缓存导致的改动生效的延迟,刷新网页的时候应该ctrl+F5
。
操作完这套后,本地预览可以正常显示公式,但github.io上却不行(有可能是我clean&generate没有放在最后一步)。根据大佬的指示,我去查了一下github.io页面,确实有报错!
1 error
1 | Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'. |
2 page errors
1 | Mixed content: load all resources via HTTPS to improve the security of your site |
google了一下错误内容,终于找到了解决方案,原来只是node_modules/hexo-renderer-mathjax/mathjax.html
中的 <script>
少了个type,终于搞定了!!
1 | Just if someone else face the same problem, you should use this: |
最后再重启一次
1 | hexo clean |