2023-06-02 hexo更换主题后报错

发布时间 2023-06-02 14:11:12作者: 哎呦你可棒棒了

具体报错如下:

{% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %} {% import '_macro/sidebar.swig' as sidebar_template %} {% block title %}{{ config.title }}{% if theme.index_with_subtitle and config.subtitle %} - {{config.subtitle }}{% endif %}{% endblock %} {% block page_class %} {% if is_home() %}page-home{% endif -%} {% endblock %} {% block content %}
{% for post in page.posts %} {{ post_template.render(post, true) }} {% endfor %}
{% include '_partials/pagination.swig' %} {% endblock %} {% block sidebar %} {{ sidebar_template.render(false) }} {% endblock %}

问题描述:换完主题后打开站点就成这样了。

原因:hexo缺少了一个包(swig)。

解决方案:在hexo博客根目录下打开终端,输入以下命令安装swig即可:

 npm i hexo-renderer-swig

安装完后,再hexo g,接着hexo s即可。

ps:据说是hexo 5.0版本后这个包(swig)就被删掉了,要手动安装回来。