From 18858f7dece44a0f0e554361de8cff34dfeb2816 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:23:30 +0530 Subject: [PATCH] chore: simplify code --- src/client/theme-default/composables/outline.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/client/theme-default/composables/outline.ts b/src/client/theme-default/composables/outline.ts index 857fb1410cb5..74e72a0f106b 100644 --- a/src/client/theme-default/composables/outline.ts +++ b/src/client/theme-default/composables/outline.ts @@ -5,6 +5,8 @@ import type { Header } from '../../shared' import { throttleAndDebounce } from '../support/utils' import { useAside } from './aside' +const ignoreRE = /\b(?:VPBadge|header-anchor|footnote-ref|ignore-header)\b/ + // cached list of anchor elements from resolveHeaders const resolvedHeaders: { element: HTMLHeadElement; link: string }[] = [] @@ -45,14 +47,7 @@ function serializeHeader(h: Element): string { let ret = '' for (const node of h.childNodes) { if (node.nodeType === 1) { - if ( - (node as Element).classList.contains('VPBadge') || - (node as Element).classList.contains('header-anchor') || - (node as Element).classList.contains('footnote-ref') || - (node as Element).classList.contains('ignore-header') - ) { - continue - } + if (ignoreRE.test((node as Element).className)) continue ret += node.textContent } else if (node.nodeType === 3) { ret += node.textContent