Skip to content

Commit ba5fb69

Browse files
committed
feat: add id to NqHeadline for linking
1 parent ad69705 commit ba5fb69

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/nimiq-vitepress-theme/src/components/NqHeadline.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ const computedAlign = computed(() => {
2424
return align
2525
return frontmatter.value.layout === 'home' ? 'center' : 'left'
2626
})
27+
28+
const headingId = computed(() => {
29+
if (!title.value)
30+
return undefined
31+
return title.value
32+
.toLowerCase()
33+
.replace(/[^\w\s-]/g, '')
34+
.replace(/\s+/g, '-')
35+
.replace(/-+/g, '-')
36+
.trim()
37+
})
2738
</script>
2839

2940
<template>
3041
<div
42+
:id="headingId"
3143
flex="~ col" nq-component="headline"
3244
:class="{ 'items-start': computedAlign === 'left',
3345
'items-center': computedAlign === 'center',

0 commit comments

Comments
 (0)