From f8d04a6f3e3cba4bb2ec034c7771373b18b34bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 26 May 2024 12:42:38 +0900 Subject: [PATCH] perf: streamline getting min and max heading level --- lib/plugins/helper/toc.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/plugins/helper/toc.ts b/lib/plugins/helper/toc.ts index 94fc8401c1..f933e177e8 100644 --- a/lib/plugins/helper/toc.ts +++ b/lib/plugins/helper/toc.ts @@ -114,8 +114,9 @@ function getAndTruncateTocObj(str: string, options: {min_depth: number, max_dept return data; } - const min = Math.min(...data.map(item => item.level)); - const max = Math.max(...data.map(item => item.level)); + const levels = data.map(item => item.level); + const min = Math.min(...levels); + const max = Math.max(...levels); for (let currentLevel = max; data.length > max_items && currentLevel > min; currentLevel--) { data = data.filter(item => item.level < currentLevel);