Skip to content

Commit bde33a7

Browse files
committed
refactor: Use String.matchAll to catch all pattern
1 parent 6f7747b commit bde33a7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pages/curriculum/[lessonSlug]/[subLessonSlug].tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,17 @@ export const getStaticProps: GetStaticProps<any, Slugs> = async context => {
181181
)
182182

183183
const { content } = matter(source)
184-
const headings = content?.match(/^(#+)\s+(.*)$/gm)?.map(heading => {
185-
// istanbul ignore next
186-
const [, hashes, text] = heading.match(/^(#+)\s+(.*)$/) || []
187-
return { text, depth: hashes.length }
188-
})
184+
const headings = [...content.matchAll(/^(#+)\s+(.*)$/gm)].map(
185+
([, hashes, text]) => ({
186+
text,
187+
depth: hashes.length
188+
})
189+
)
189190

190191
return {
191192
...sourceAndFrontMatter,
192193
subLessonSlug: slug.subLessonSlug,
193-
headings: headings || []
194+
headings
194195
}
195196
})
196197
)

0 commit comments

Comments
 (0)