版本8.0.0之后是否可以在hexo-theme-next中删除部分默认布局?

问题描述

我现在正在尝试在旧的hexo博客上安装hexo-theme-next的8.0.2版本。

但是现在我发现似乎无法删除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 %}

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

解决方法

最后,我从主题下一步社区得到了答案。

如果您想做我上面提到的事情,唯一的方法是使用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/xxx.js

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