From 62b2f016677480f741bd1bd995e7e88c6e971093 Mon Sep 17 00:00:00 2001 From: rohitdhakane Date: Sat, 4 Jan 2025 14:35:13 +0530 Subject: [PATCH] fix: [BUG] Blog Table of contents links not working #3540 --- scripts/build-post-list.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/build-post-list.js b/scripts/build-post-list.js index 44b7273c2106..c24a6e4e9f0c 100644 --- a/scripts/build-post-list.js +++ b/scripts/build-post-list.js @@ -172,10 +172,9 @@ async function walkDirectories( } } -// Matches heading IDs in two formats: -// 1. {#my-heading-id} -// 2. -const HEADING_ID_REGEX = /[\s]*(?:\{#([a-zA-Z0-9\-_]+)\}|my heading id +const anchorTagRegex =/')[1]?.trim() || ''; + } if (typeof str !== 'string') return ''; if (!str.trim()) return ''; - let slug = ''; - - // Match heading IDs like {# myHeadingId} - const idMatch = str.match(HEADING_ID_REGEX); - const [, headingId, anchorId] = idMatch || []; - slug = (headingId || anchorId || '').trim(); - - // If no valid ID is found, return an empty string - return slug; + return str + .toLowerCase() + .trim() + .replace(/\s+/g, '-') // Replace spaces with hyphens + .replace(/[^\w\-]+/g, ''); // Remove non-alphanumeric characters except hyphens } async function isDirectory(dir) {