首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在8.0.0版本之后,是否可以删除hexo-theme next中的部分默认布局?

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

Stack Overflow用户
提问于 2020-11-07 21:59:10
回答 1查看 43关注 0票数 1

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

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

在旧版本的hexo-theme-next中,我只能将.twig文件更改为具有自定义索引页,但在8.0.2版本中,我似乎只能在特定位置插入新节。

我想要的是这样更改(旧版本index.twig中的部分代码):

代码语言:javascript
复制
{% block class %}index posts-expand{% endblock %}

如下所示:

代码语言:javascript
复制
{% block class %}

{%- if config.content.mode == normala %}

index posts-expand

{%- elif config.content.mode == montage %}

index posts-montage

{%- endif %}

{% endblock %}

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

EN

回答 1

Stack Overflow用户

发布于 2020-11-16 01:05:53

最后,我从theme-next社区得到了答案。

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

下面是一个删除默认“power-by”字符串的示例:

代码语言:javascript
复制
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中)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64728435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档