在8.0.0版本之后,是否可以删除hexo主题中的部分默认布局



我现在正试图在我以前的hexo博客上安装hexo-theme-next的8.0.2版本。

但现在我发现,似乎没有办法删除8.0.2中的默认布局;

在旧版本的hexo-theme-next中,我只需更改.titch文件即可拥有自定义的索引页,但在8.0.2中,我似乎只能在特定位置插入新的部分。

我想要的是改变这个(旧版本index.trick中的部分代码(:

{% 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 %}

还有什么方法可以从默认布局中删除部分吗?

最后,我从主题next社区得到了答案。

如果你想做我上面提到的事情,唯一的方法就是使用jsString.replace方法(当然还有regex规则(;

下面是一个删除默认"powerby"字符串的示例:

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/xxx.js

(如果没有,你应该自己创建/scripts文件夹,并且js文件没有命名规则,只需将它们放在文件夹中,hexo渲染器会在编译时将其插入到你的html中(

最新更新