fix(heading-link): detect repeat heading per post

This commit is contained in:
Ming Di Leom 2024-06-08 02:46:12 +00:00
parent fd36210579
commit 772df1da56
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 3 additions and 3 deletions

View File

@ -9,16 +9,16 @@
const { slugize, stripHTML, unescapeHTML: unescape } = require('hexo-util')
const anchorId = (str, transformOption) => {
return slugize(stripHTML(unescape(str)).trim(), { transform: transformOption });
return slugize(stripHTML(unescape(str)).trim(), { transform: transformOption })
}
hexo.extend.filter.register('marked:renderer', function (renderer) {
const { config } = this
const headingId = {}
renderer.heading = function (text, level) {
const { modifyAnchors } = config.marked
const transformOption = modifyAnchors;
const transformOption = modifyAnchors
let id = anchorId(text, transformOption)
const headingId = {};
// Add a number after id if repeated
if (headingId[id]) {