前言

看到一个源码下载站推荐了一个Hexo主题:Yelee ,皮肤挺讨人喜欢,功能也满足个人需求,就自作聪明进了官网从github仓库下载,结果运行起来首页空白,不显示任何文章。

再回头看下载站推荐的,他们的标题写着完美修复版,原来是站长早知道有坑,看github记录也有好几年没人维护了,╮(╯▽╰)╭

现象

不想截图,就是 post 目录下有文章,但在网站首页不显示出来,直接访问文章链接也能访问,浏览器 F12 可见错误:

1
2
3
4
5
Uncaught SyntaxError: Unexpected token '}'
(index):87 Uncaught ReferenceError: yiliaConfig is not defined
at (index):87
(index):91 Uncaught ReferenceError: yiliaConfig is not defined
at (index):91

已经提示是配置错误了:yiliaConfig is not defined

解决修复

根据错误提示,定位到:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script>
var yiliaConfig = {
fancybox: true,
animate: true,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
fancybox_js: "//cdn.bootcdn.net/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js",
scrollreveal: "//cdn.bootcdn.net/ajax/libs/scrollReveal.js/3.1.4/scrollreveal.min.js",
search:
}
</script>


<script> yiliaConfig.jquery_ui = [false]; </script> //这里报错了

从错误往上翻,可见上面的 yiliaConfig 数组中,search: 未赋值,找到对应的模板按代码搜索,可见其使用的代码为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script>
var yiliaConfig = {
fancybox: <%=theme.fancybox%>,
animate: <%=theme.animate%>,
isHome: <%=is_home()%>,
isPost: <%=is_post()%>,
isArchive: <%=is_archive()%>,
isTag: <%=is_tag()%>,
isCategory: <%=is_category()%>,
fancybox_js: "<%- theme.CDN.fancybox_js %>",
scrollreveal: "<%- theme.CDN.scrollreveal %>",
search: <%= theme.search.on %> //这个和配置对不上
}
</script>

对应的代码还有另外两处,都是用的 <%= theme.search.on %> 方法获取配置,而主题配置 themes/yelee/_config.yml 中写的却是:

1
2
search: 
onload: false

官方源码中提供的这个地方有小bug,简单点直接将该配置改成 on 即可:

1
2
search: 
on: false