diff options
author | ikoamu <ikoamu@gmail.com> | 2024-01-28 23:11:32 +0900 |
---|---|---|
committer | ikoamu <ikoamu@gmail.com> | 2024-01-28 23:11:32 +0900 |
commit | c67e917a9522515db26bc35276a02a10c4a5d5eb (patch) | |
tree | 05f1609118431e46beca897b7ce291581a85085d /generate_json.js | |
parent | f34d96b8c7caf8821477ec269c911d8a7d1bc73d (diff) |
Refactor generate_json.js to handle multiple tags per node
Diffstat (limited to 'generate_json.js')
-rw-r--r-- | generate_json.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/generate_json.js b/generate_json.js index d1e2701..fd20ae4 100644 --- a/generate_json.js +++ b/generate_json.js @@ -46,7 +46,7 @@ function getFilename(path) { const queryNodes = ` SELECT - tags.tag as tags, + GROUP_CONCAT(tags.tag) AS tags, nodes.properties, nodes.olp, nodes.pos, @@ -75,9 +75,11 @@ WHERE const queryTags = ` SELECT - * + tags.tag FROM tags +GROUP BY + tags.tag `; const graphdata = { @@ -87,14 +89,17 @@ const graphdata = { db.all(queryNodes, (_, nodes) => db.all(queryLinks, (_, links) => db.all(queryTags, (_, tags) => { - graphdata.data.nodes = nodes.map(node => ({ - ...node, - tags: node.tags ?? [null], - file: getFilename(node.file), - properties: parseProperties(node.properties), - })); + graphdata.data.nodes = nodes.map(node => { + const splitTags = node.tags?.split(',') ?? [null]; + return{ + ...node, + tags: splitTags, + file: getFilename(node.file), + properties: parseProperties(node.properties), + }; + }); graphdata.data.links = links; - graphdata.data.tags = tags.length ? tags : null; + graphdata.data.tags = tags.length ? tags.map(t => t.tag) : null; fs.writeFile('graphdata.json', JSON.stringify(removeQuotesFromObject(graphdata)), (err) => { if (err) throw err; |