1

I am now trying to install Version 8.0.2 of hexo-theme-next on my old hexo blog.

But now I found that there seem no way to remove default layout in 8.0.2;

In old version of hexo-theme-next,I can just change the .twig file to have a customized index page, but with 8.0.2, It seems that I can only insert new section into specific location.

What I want is like change this(part of code in old-version index.twig):

{% block class %}index posts-expand{% endblock %}

Into this:

{% block class %}

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

index posts-expand

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

index posts-montage

{%- endif %}

{% endblock %}

is there still any way to remove section from default layout?

Mizok.H
  • 423
  • 5
  • 15

1 Answers1

0

Finally I got an answer from theme-next community.

If you want to do things I mention above, the only way is to use js String.replace method(and of course with regex rule);

Here is an example which remove the default 'power-by' string:

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;
})

and you should save these code as files inside Hexo root directory/scripts, just like

/scripts/xxx.js

(You should create /scripts folder by yourself if you don't have it, and there is no naming rule for your js file, just put them in the folder, and hexo renderer will insert it into your html when compiling)

Mizok.H
  • 423
  • 5
  • 15