4

I just updated my Hexo blog to the latest version. After updating, the <!-- more --> tag seems to stop working. Instead of showing an excerpt on the homepage it just shows all the content. I am using the Next theme.

I found an issue on the hexo github: https://github.com/hexojs/hexo/pull/1519

Which looks like the problem I am having. I tried to edit this file locally but nothing happens, still not working.

Is there are npm cache or something I need to clear when I edit a package in node_modules directly?

Thanks

1 Answers1

2

Did you try to remove the node_modules directory and re-run npm install?

Temporarily solution : You have to downgrade to a stable version of Hexo by setting "hexo": "hexo.stable.version" in your package.json or you can add your own filter to do the job in the scripts folder of your theme. This file will be using at the startup of Hexo. Name the file : excerpt.js. The full path will : your-blog/themes/next/scripts/excerpt.js

var rExcerpt = /<!-- ?more ?-->/;

hexo.extend.filter.register('after_post_render', function(data) {
    var content = data.content;

    if (rExcerpt.test(content)){
        data.content = content.replace(rExcerpt, function(match, index){
            data.excerpt = content.substring(0, index).trim();
            data.more = content.substring(index + match.length).trim();

            return '<a id="more"></a>';
        });
    } else {
        data.excerpt = '';
        data.more = content;
    }
});

It should work.

Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52
  • Thanks. I tried deleting the node_modules folder and reinstall but that didn't work. The temporarily solution works! Thanks – user2380892 Oct 19 '15 at 20:19
  • Really strange, the code worked fine . . after I shutdown hexo server and tried again it returned to the old state as if the excerpt.js is not being read anymore. – user2380892 Oct 23 '15 at 11:38
  • yes that's strange. To see if the script is executed : add a console.log in the `excerpt.js` script – Louis Barranqueiro Oct 23 '15 at 11:40
  • Hi, I added a console log in the excerpt.js file. When I run hexo server I see that the log is being printed out. – user2380892 Oct 25 '15 at 09:12