Skip to content

Commit

Permalink
fix: clear title cache after rendering of a post (#184)
Browse files Browse the repository at this point in the history
* fix: clear title cache after rendering of a post
* chore: add test case for #184
  • Loading branch information
renbaoshuo committed Aug 27, 2022
1 parent 5ab33d1 commit 242bf09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/anchors.js
Expand Up @@ -22,7 +22,7 @@ const renderPermalink = function(slug, opts, tokens, idx) {
const anchor = function(md, opts) {
Object.assign(opts, { renderPermalink });

const titleStore = {};
let titleStore = {};
const originalHeadingOpen = md.renderer.rules.heading_open;
const slugOpts = { transform: opts.case, ...opts };

Expand Down Expand Up @@ -58,6 +58,10 @@ const anchor = function(md, opts) {
? originalHeadingOpen.apply(this, args)
: self.renderToken.apply(self, args);
};

md.core.ruler.push('clear_anchor_title_store', () => {
titleStore = {};
});
};

module.exports = anchor;
17 changes: 17 additions & 0 deletions test/index.js
Expand Up @@ -194,6 +194,23 @@ describe('Hexo Renderer Markdown-it', () => {
result.should.equal('<h2 id="foo_bar">foo BAR</h2>\n');
});

it('multiple posts anchor id', () => {
hexo.config.markdown.anchors = {
level: 2,
collisionSuffix: 'ver',
permalink: true,
permalinkClass: 'header-anchor',
permalinkSymbol: '¶'
};
const expected = readFileSync('./test/fixtures/outputs/anchors.html', 'utf8');
const renderer = new Renderer(hexo);
const result = renderer.parser.render(source);
const result2 = renderer.parser.render(source);

result.should.eql(expected);
result2.should.eql(expected);
});

describe('permalinkSide', () => {
const text = '## foo';

Expand Down

0 comments on commit 242bf09

Please sign in to comment.