Skip to content

Commit

Permalink
perf: streamline getting min and max heading level
Browse files Browse the repository at this point in the history
  • Loading branch information
KentarouTakeda committed May 26, 2024
1 parent c17db64 commit f8d04a6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/plugins/helper/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f8d04a6

Please sign in to comment.