File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = ( { data : { root } } ) => {
2
+ const { page } = root
3
+ const indexKey = page . attributes [ 'index-data' ]
4
+ if ( ! indexKey ) return null
5
+
6
+ const indexData = page . component . asciidoc . attributes [ indexKey ]
7
+ if ( ! indexData ) return null
8
+ const matchComponentVersion = page . attributes [ 'match-component-version' ]
9
+
10
+ try {
11
+ const parsedData = JSON . parse ( indexData )
12
+ const currentPageUrl = page . url
13
+ const currentComponent = page . component . name
14
+ const currentVersion = page . version
15
+
16
+ const filteredData = parsedData . reduce ( ( acc , item ) => {
17
+ if ( item . pages && Array . isArray ( item . pages ) ) {
18
+ const filteredPages = item . pages . filter ( ( page ) => {
19
+ const isNotCurrentPage = page . url !== currentPageUrl
20
+
21
+ // Optional filtering by component and version
22
+ const matchesComponentVersion = ! matchComponentVersion || (
23
+ item . component === currentComponent && item . version === currentVersion
24
+ )
25
+
26
+ return isNotCurrentPage && matchesComponentVersion
27
+ } )
28
+ acc . push ( ...filteredPages )
29
+ }
30
+ return acc
31
+ } , [ ] )
32
+
33
+ return filteredData
34
+ } catch ( error ) {
35
+ console . log (
36
+ `Error parsing JSON attribute "${ indexKey } " in ${ page . url } component. Index page will be empty. Make sure the generate-index-data extension is correctly configured.\n\n ${ error } `
37
+ )
38
+ return null
39
+ }
40
+ }
Original file line number Diff line number Diff line change 36
36
{{> component-home-v2 }}
37
37
{{ else if (eq page.attributes.role 'bloblang-playground')}}
38
38
{{> bloblang-playground }}
39
+ {{ else if (eq page.attributes.role 'index-list')}}
40
+ {{> index-list }}
39
41
{{ else if (eq page.layout 'index')}}
40
42
{{> index }}
41
43
{{ else if (eq page.attributes.role 'related-labs')}}
Original file line number Diff line number Diff line change
1
+ {{{ page.contents }}}
2
+
3
+ {{ #with (get-index-data ) as |indexData |}}
4
+ {{ #if indexData }}
5
+ <ul class =" index" >
6
+ {{ #each indexData }}
7
+ <li class =" index" >
8
+ <a href =" {{{ relativize this.url }}} " >{{{ this.title }}} </a >
9
+ {{ #if (ne this.title this.description )}}
10
+ <p class =" index" >{{{ this.description }}} </p >
11
+ {{ /if }}
12
+ </li >
13
+ {{ /each }}
14
+ </ul >
15
+ {{ else }}
16
+ <p >No index data found.</p >
17
+ {{ /if }}
18
+ {{ /with }}
You can’t perform that action at this time.
0 commit comments