【hexo】next踩坑侧边栏菜单链接乱码问题

乱码一

点击首页、归档、分类、标签、关于等导航时,链接地址为:https://xxx.github.io/%20,页面出现404错误。

解决方案

链接中的%20代表空格,修改主题配置文件_config.yml,将||之前的所有空格删掉,问题解决。

乱码二

点击“日志”导航时,链接地址为:https://xxx.github.io/%20,页面出现404错误。

解决方案

在 themes\next\layout_macro 下找到 sidebar.swig 文件,找到如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
{% if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts">
{% if theme.menu.archives %}
<a href="{{ url_for(theme.menu.archives).split('||')[0] | trim }}">
{% else %}
<a href="{{ url_for(config.archive_dir) }}">
{% endif %}
<span class="site-state-item-count">{{ site.posts.length }}</span>
<span class="site-state-item-name">{{ __('state.posts') }}</span>
</a>
</div>
{% endif %}

1
<a href="{{ url_for(theme.menu.archives).split('||')[0] | trim }}">

替换为

1
<a href="{{ url_for(theme.menu.archives.split('||')[0]) | trim }}">