File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ const filtered = computed(() => {
31
31
return item
32
32
}
33
33
// filter headers
34
- const matchedHeaders = item .headers .filter (matches )
34
+ const matchedHeaders = item .headers .map ( h => h . text ). filter (matches )
35
35
return matchedHeaders .length
36
36
? { text: item .text , link: item .link , headers: matchedHeaders }
37
37
: null
@@ -92,8 +92,8 @@ function slugify(text: string): string {
92
92
>
93
93
<h3 >{{ item.text }}</h3 >
94
94
<ul >
95
- <li v-for =" h of item.headers" :key =" h" >
96
- <a :href =" item.link + '.html#' + slugify(h)" >{{ h }}</a >
95
+ <li v-for =" h of item.headers" :key =" h.anchor " >
96
+ <a :href =" item.link + '.html#' + slugify(h.anchor )" >{{ h.anchor }}</a >
97
97
</li >
98
98
</ul >
99
99
</div >
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ export interface APIGroup {
9
9
items : {
10
10
text : string
11
11
link : string
12
- headers : string [ ]
12
+ headers : {
13
+ anchor : string
14
+ text : string
15
+ } [ ]
13
16
} [ ]
14
17
}
15
18
@@ -34,7 +37,10 @@ export default {
34
37
const headersCache = new Map <
35
38
string ,
36
39
{
37
- headers : string [ ]
40
+ headers : {
41
+ anchor : string
42
+ text : string
43
+ } [ ]
38
44
timestamp : number
39
45
}
40
46
> ( )
@@ -50,15 +56,22 @@ function parsePageHeaders(link: string) {
50
56
51
57
const src = fs . readFileSync ( fullPath , 'utf-8' )
52
58
const h2s = src . match ( / ^ # # [ ^ \n ] + / gm)
53
- let headers : string [ ] = [ ]
59
+ let headers : {
60
+ anchor : string
61
+ text : string
62
+ } [ ] = [ ]
54
63
if ( h2s ) {
55
- headers = h2s . map ( ( h ) =>
56
- h
57
- . slice ( 2 )
58
- . replace ( / < s u p c l a s s = .* / , '' )
59
- . replace ( / \\ < / g, '<' )
60
- . replace ( / ` ( [ ^ ` ] + ) ` / g, '$1' )
61
- . trim ( )
64
+ headers = h2s . map ( ( h ) => {
65
+ const text = h
66
+ . slice ( 2 )
67
+ . replace ( / < s u p c l a s s = .* / , '' )
68
+ . replace ( / \\ < / g, '<' )
69
+ . replace ( / ` ( [ ^ ` ] + ) ` / g, '$1' )
70
+ . replace ( / \{ # ( [ a - z A - Z 0 - 9 - ] + ) \} / g, '' ) // hidden anchor tag
71
+ . trim ( )
72
+ const anchor = h . match ( / \{ # ( [ a - z A - Z 0 - 9 - ] + ) \} / ) ?. [ 1 ] ?? text
73
+ return { text, anchor }
74
+ }
62
75
)
63
76
}
64
77
headersCache . set ( fullPath , {
You can’t perform that action at this time.
0 commit comments