File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
apps/website/src/components/toc Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -36,20 +36,23 @@ export const TableOfContent = component$<TableOfContentProps>((props) => {
36
36
function deltaToStrg (
37
37
currNode : Node ,
38
38
nextNode : Node ,
39
- ) : 'same level' | 'down one level' | 'up one level' {
39
+ ) : 'same level' | 'down one level' | 'up one level' | 'upwards discontinuous' {
40
40
const delta = currNode . level - nextNode . level ;
41
+ if ( delta > 1 ) {
42
+ return 'upwards discontinuous' ;
43
+ }
41
44
if ( delta === 1 ) {
42
45
return 'up one level' ;
43
46
}
47
+ if ( delta === 0 ) {
48
+ return 'same level' ;
49
+ }
44
50
if ( delta === - 1 ) {
45
51
return 'down one level' ;
46
52
}
47
53
48
- if ( delta === 0 ) {
49
- return 'same level' ;
50
- }
51
54
throw new Error (
52
- `bad headings: are not continous from: #${ currNode . id } to #${ nextNode . id } ` ,
55
+ `bad headings: are downwards discontinous from: #${ currNode . id } to #${ nextNode . id } bc from ${ currNode . level } to ${ nextNode . level } ` ,
53
56
) ;
54
57
}
55
58
function getTree ( nodes : ContentHeading [ ] ) {
@@ -64,6 +67,14 @@ function getTree(nodes: ContentHeading[]) {
64
67
childrenMap . set ( nextNode . level , nextNode . children ) ;
65
68
const deltaStrg = deltaToStrg ( currNode , nextNode ) ;
66
69
switch ( deltaStrg ) {
70
+ case 'upwards discontinuous' : {
71
+ const delta = currNode . level - nextNode . level ;
72
+ if ( childrenMap . has ( delta - 1 ) ) {
73
+ const nthParent = childrenMap . get ( delta - 1 ) ;
74
+ nthParent ?. push ( nextNode ) ;
75
+ }
76
+ break ;
77
+ }
67
78
case 'up one level' : {
68
79
const grandParent = childrenMap . get ( currNode . level - 2 ) ;
69
80
grandParent ?. push ( nextNode ) ;
You can’t perform that action at this time.
0 commit comments