如何解决cannot get archives%7C%7C%20archive的问题

放上博客网址关于cannot get archives的问题 | 星辰塔

今天碰到个问题,hexo的next主题,在点击头像下面的 日志 时无法正常跳转,反而显示
cannot get archives%7C%7C%20archive
在网上找了很久答案都不满意,最后终于找到解决方法了
思路在下面,不想看的的到文末看结论就行了

思路

首先我们要知道 %7C是|的编码,%20是空格的编码
所以上面的报错实际上是
cannot get archives|| archive
其中archives|| archive有没有觉得很眼熟?
没错,我们在next的主题配置中有这样一段代码

1
2
3
4
5
6
7
menu:
  home: /|| home
  about: /2022/01/26/关于本站点/|| user
  tags: /tags/|| tags
  categories: /categories/|| th
  archives: /archives/|| archive

所以这里就有了第一个解决方法
把最后一行改为archives: /archives/即删掉后面的部分,但是这种方法很明显有问题
因为|| archive是一种格式,后面表示的是图标,删掉的话你的博客里面的“归档”就没有图标了

然后再想想
头像下面的日志不能再次打开,但是下面的分类和标签却可以正常打开,
这三个部分都属于 sidebar(侧边栏?)
所以我想问题出在sidebar的文件中
打开 \themes\next\layout_macro\sidebar.swig
因为我没学过这种语言,所以只能用对比的方法来找问题
我们找到有关 archive(日志) categorie(分类) tags(标签)的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{% 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 %}
 
{% if site.categories.length > 0 %}
  {% set categoriesPageQuery = site.pages.find({type: 'categories'}, {lean: true}) %}
  {% set hasCategoriesPage = categoriesPageQuery.length > 0 %}
  <div class="site-state-item site-state-categories">
    {% if hasCategoriesPage %}<a href="{{ url_for(categoriesPageQuery[0].path) }}">{% endif %}
      <span class="site-state-item-count">{{ site.categories.length }}</span>
      <span class="site-state-item-name">{{ __('state.categories') }}</span>
    {% if hasCategoriesPage %}</a>{% endif %}
  </div>
{% endif %}

{% if site.tags.length > 0 %}
  {% set tagsPageQuery = site.pages.find({type: 'tags'}, {lean: true}) %}
  {% set hasTagsPage = tagsPageQuery.length > 0 %}
  <div class="site-state-item site-state-tags">
    {% if hasTagsPage %}<a href="{{ url_for(tagsPageQuery[0].path) }}">{% endif %}
      <span class="site-state-item-count">{{ site.tags.length }}</span>
      <span class="site-state-item-name">{{ __('state.tags') }}</span>
    {% if hasTagsPage %}</a>{% endif %}
  </div>
{% endif %}

查了一下url_for是转码用的,可能和跳转有关,我们来看一下这三条语句

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

芜湖,一对比几乎可以确定问题出在这儿,第一行的代码格式与下两行明显不一样,其中的||正好对应%7C%7C
我们直接把第一行的格式修改的和下面两行差不多

1
<a href="{{ url_for(theme.menu.archives[0].path) }}">

再测试,成功!花了一晚上时间想这个好难啊QAQ

结论

打开\themes\next\layout_macro\sidebar.swig
找到archive段中的

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

修改为

1
<a href="{{ url_for(theme.menu.archives[0].path) }}">

即可

  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值