hexojs / hexo-renderer-markdown-it

Markdown-it is a Markdown parser, done right. A faster and CommonMark compliant alternative for Hexo.
MIT License
340 stars 60 forks source link

Do not render anchors in index pages #178

Closed ppwwyyxx closed 1 year ago

ppwwyyxx commented 2 years ago

Currently, anchors are generated even on index pages, e.g.: 2022-02-27_23-40

I think this is not the correct behavior. Contents in index pages, or pages such as /tag/TAG are meant to change over time. Permalink on these pages will not be permantant at all.

renbaoshuo commented 1 year ago

I'm so sorry, it's not a problem with this package. You may need to fix it in the theme.

ppwwyyxx commented 1 year ago

In case anyone is interested, I end up solving it with:

hexo.extend.filter.register('after_post_render', data => {
  const $ = cheerio.load(data.excerpt);
  const anchor = $('a.markdown-anchor');
  if (anchor.length > 0) {
    log.info('Removing excerpt anchor from ' + data.title + ' ...');
    anchor.remove();
  }
  data.excerpt = $.html();
  return data;
});