user2380892
user2380892

Reputation: 69

Hexo excerpt <!-- more --> not working after update

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

Upvotes: 4

Views: 1382

Answers (1)

Louis Barranqueiro
Louis Barranqueiro

Reputation: 10238

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.

Upvotes: 2

Related Questions