我现在正尝试在我以前的hexo博客上安装8.0.2版本的hexo-theme-next。
但现在我发现,在8.0.2中似乎没有办法删除默认布局;
在旧版本的hexo-theme-next中,我只能将.twig文件更改为具有自定义索引页,但在8.0.2版本中,我似乎只能在特定位置插入新节。
我想要的是这样更改(旧版本index.twig中的部分代码):
{% block class %}index posts-expand{% endblock %}如下所示:
{% block class %}
{%- if config.content.mode == normala %}
index posts-expand
{%- elif config.content.mode == montage %}
index posts-montage
{%- endif %}
{% endblock %}还有什么方法可以从默认布局中删除部分吗?
发布于 2020-11-16 01:05:53
最后,我从theme-next社区得到了答案。
如果你想做我上面提到的事情,唯一的方法是使用js String.replace方法(当然还有正则规则);
下面是一个删除默认“power-by”字符串的示例:
let removeRedundantString = (str) => {
str = str.replace(/(<div class="powered-by">).*(<\/div>)/s, ``);
str = str.replace(/(<span class="with-love">).*(<span class="author")/s, `$2`);
return str
}
hexo.extend.filter.register('after_render:html', (str, data) => {
//here data is an object that have information about your blog within
// you can try console.log data to see is inside it.
if (data.config.theme_config.no_hexo_credit) {
str = removeRedundantString(str);
}
return str;
})您应该将这些代码作为文件保存在Hexo根目录/scripts中,就像这样
/scripts/xxx.js
(如果你没有,你应该自己创建/scripts文件夹,而且你的js文件没有命名规则,只要把它们放在这个文件夹里,hexo渲染器会在编译时把它插入到你的html中)
https://stackoverflow.com/questions/64728435
复制相似问题