summaryrefslogtreecommitdiff
path: root/pages/index.tsx
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-08-16 19:09:53 +0200
committerThomas F. K. Jorna <[email protected]>2021-08-16 19:09:53 +0200
commitbd31703d8627d3c8e046d62223a08d295f0e9578 (patch)
tree4aa1dcacae871734170b77e51adb16f87b235792 /pages/index.tsx
parentf6f68f67080bfe3c7dda641e2576ab37e6e58b8f (diff)
fix: #67, correctly skip non-node headlines
Diffstat (limited to 'pages/index.tsx')
-rw-r--r--pages/index.tsx21
1 files changed, 10 insertions, 11 deletions
diff --git a/pages/index.tsx b/pages/index.tsx
index 12f9f74..21a0738 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -113,25 +113,22 @@ export function GraphPage() {
}
return headingNodes.map((headingNode) => {
const smallerHeadings = nodesInFile.filter((node) => {
- if (node.level >= headingNode.level) {
+ if (
+ node.level >= headingNode.level ||
+ node.pos >= headingNode.pos ||
+ !headingNode.olp?.includes(node.title) ||
+ node.level >= headingNode.level - headingNode.olp.reverse().indexOf(node.title)
+ ) {
return false
}
return true
})
- const smallerPos = smallerHeadings.map((node) => {
- if (node.pos >= headingNode.pos) {
- return 0
- }
- return node.pos
- })
- const target = nodesInFile.find((node) => {
- return node.pos === Math.max(...smallerPos)
- })
+ const target = smallerHeadings.slice(-1)[0]
return {
source: headingNode.id,
- target: target!.id,
+ target: target?.id || fileNode.id,
type: 'heading',
}
})
@@ -173,6 +170,7 @@ export function GraphPage() {
title: sourceId,
level: 0,
pos: 0,
+ olp: null,
})
return { ...link, type: 'bad' }
}
@@ -185,6 +183,7 @@ export function GraphPage() {
title: targetId,
level: 0,
pos: 0,
+ olp: null,
})
return { ...link, type: 'bad' }
}