Skip to content

Commit cd5cc5f

Browse files
committed
update for Page Anchor component
1 parent 2ef64f5 commit cd5cc5f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pages/[...slug].vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ onMounted(() => {
121121
<template #sidebarTop />
122122
</TwoColLayoutWStickySideBar>
123123

124-
<page-anchor
124+
<PageAnchor
125125
v-if="h2Array.length >= 3"
126126
:section-titles="h2Array"
127127
/>

plugins/get-headers.client.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Find all elements with class name "section-header2" or "section-header3"
2+
// Loop through each section-header element and push it into the array
3+
// Excludes the section-header2 More Information which is a visually-hidden element above the divider-way-finder in the Flexible Block component
4+
5+
function getHeadersMethod() {
6+
const elements = document.querySelectorAll('.section-header2, .section-header3, section-header4')
7+
8+
const h2Array = []
9+
10+
elements.forEach((element) => {
11+
if (element.textContent !== 'More Information') {
12+
h2Array.push(element.textContent)
13+
}
14+
})
15+
16+
// console.log('The plugin has been mounted!')
17+
// console.log('h2Array:', h2Array)
18+
19+
return h2Array
20+
}
21+
22+
export default defineNuxtPlugin(() => {
23+
return {
24+
provide: {
25+
getHeaders: {
26+
getHeadersMethod
27+
// Make plugin available to all components
28+
}
29+
}
30+
}
31+
})

0 commit comments

Comments
 (0)