Butterfly 主题 Bug

当你想隐藏侧边栏时,可以在设置 aside=false,但这个选项似乎对标签和分类的子页面没有效果,比如 /tags/日记。全局隐藏侧边栏后虽然可以解决,但是主页的侧边栏又没有了……

店长评论区有用 JS 解决的方法,但是我不喜欢,因为要额外引入。今天查看源码解决了,增加几个判断代码就行。

子页面侧边栏仍然存在

解决方法

Hexo 自带判断页面类型的函数,详见条件函数

要用到这两个:

is_tag:检查当前页面是否为标签归档页面

is_category:检查当前页面是否为分类归档页面

打开文件 "\hexo-theme-butterfly\layout\includes\layout.pug",找到第 3 行

1
2
- - var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
+ - var hideAside = !theme.aside.enable || is_tag() || is_category() || page.aside === false ? 'hide-aside' : ''

判断页面是标签或者分类页时,使 hideAside='hide-aside'

再找到第 28 行

1
2
- if theme.aside.enable && page.aside !== false
+ if theme.aside.enable && page.aside !== false && !is_tag() && !is_category()

判断页面为标签或者分类页时,不引入侧边栏。

Hexo 三连即可看见效果,子页面的侧边栏成功去除,点击查看

但是往下滑动页面,这个按钮出来了,还是有 bug。

打开文件 "\hexo-theme-butterfly\layout\includes\rightside.pug"

找到 when 'hideAside' 下一行

1
2
- if aside.enable && aside.button && page.aside !== false
+ if aside.enable && aside.button && !is_tag() && !is_category() && page.aside !== false

大功告成!