diff options
author | Shotaro Aoki <ikoamu@gmail.com> | 2024-07-03 22:50:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-03 22:50:04 +0900 |
commit | 3a618f8defb382a76e19c9255bb60262e12421f1 (patch) | |
tree | 41f71df13dca696179d8a6600a5065d02e20809c /generate_graphdata.js | |
parent | 7d5ed8cbfc4ebad59200305f84b97c70adfccc2c (diff) | |
parent | 50a675492ef1dbb2a5b388ff5fa81f6f9e0af7ae (diff) |
Merge pull request #21 from ikoamu/feat-cite
add cite links
Diffstat (limited to 'generate_graphdata.js')
-rw-r--r-- | generate_graphdata.js | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/generate_graphdata.js b/generate_graphdata.js index 0a627a8..62896e3 100644 --- a/generate_graphdata.js +++ b/generate_graphdata.js @@ -65,15 +65,27 @@ GROUP BY nodes.id `; -const queryLinks = ` +const queryIdLinks = ` SELECT - type, dest as target, source + type, + dest as target, + source FROM links WHERE type = '"id"' `; +const queryCites = ` +SELECT + citations.node_id as citeNodeId, + citations.cite_key as citeKey, + refs.node_id as refNodeId +FROM + citations +LEFT JOIN refs ON citations.cite_key = refs.ref +` + const queryTags = ` SELECT tags.tag @@ -88,27 +100,40 @@ const graphdata = { data: {}, }; db.all(queryNodes, (_, nodes) => - db.all(queryLinks, (_, links) => - db.all(queryTags, (_, tags) => { - graphdata.data.nodes = nodes.map(node => { - const splitTags = node.tags?.split(',') ?? [null]; - const olp = node.olp?.replace(/\(\"|\"\)/g, '').split(' ') ?? null; - return{ - ...node, - olp, - tags: splitTags, - file: getFilename(node.file), - properties: parseProperties(node.properties), - }; - }); - graphdata.data.links = links; - graphdata.data.tags = tags.length ? tags.map(t => t.tag) : null; - - fs.writeFile('graphdata.json', JSON.stringify(removeQuotesFromObject(graphdata)), (err) => { - if (err) throw err; - console.log('The file has been saved!'); - }); - }), + db.all(queryIdLinks, (_, links) => + db.all(queryCites, (_, cites) => + db.all(queryTags, (_, tags) => { + graphdata.data.nodes = nodes.map(node => { + const splitTags = node.tags?.split(',') ?? [null]; + const olp = node.olp?.replace(/\(\"|\"\)/g, '').split(' ') ?? null; + return{ + ...node, + olp, + tags: splitTags, + file: getFilename(node.file), + properties: parseProperties(node.properties), + }; + }); + graphdata.data.links = [ + ...links, + ...cites.map(cite => cite.refNodeId ? ({ + type: 'ref', + source: cite.citeNodeId, + target: cite.refNodeId, + }) : ({ + type: 'cite', + source: cite.citeNodeId, + target: cite.citeKey, + })), + ]; + graphdata.data.tags = tags.length ? tags.map(t => t.tag) : null; + + fs.writeFile('graphdata.json', JSON.stringify(removeQuotesFromObject(graphdata)), (err) => { + if (err) throw err; + console.log('The file has been saved!'); + }); + }), + ) ), ); |