aboutsummaryrefslogtreecommitdiff
path: root/info.js
diff options
context:
space:
mode:
Diffstat (limited to 'info.js')
-rw-r--r--info.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/info.js b/info.js
new file mode 100644
index 0000000..95813b6
--- /dev/null
+++ b/info.js
@@ -0,0 +1,30 @@
+const fs = require("fs").promises
+
+module.exports.doujins = shortNames => fs.readdir(".", {encoding: "utf8", withFileTypes: true})
+ .then(doujins => doujins
+ .map(dirent => fs.readFile(`${dirent.name}/metadata.json`)
+ .then(data => JSON.parse(data.toString()))
+ .then(data => [dirent.name, data])
+ .catch(_ => [])))
+ .then(promises => Promise.all(promises))
+ .then(doujins => doujins
+ .filter(([title, data]) => title && data)
+ .filter(([title, data]) => (title == data.title) == !shortNames))
+ .then(doujins => Object.fromEntries(doujins))
+
+module.exports.tags = _ => {
+ const tags = {"*": []}
+
+ return module.exports.doujins()
+ .then(doujins => Object.values(doujins))
+ .then(doujins => doujins
+ .forEach(doujin => {
+ tags["*"].push(doujin.title)
+
+ doujin.tag && doujin.tag.forEach(tag => {
+ tags[tag] = tags[tag] || []
+ tags[tag].push(doujin.title)
+ })
+ }))
+ .then(_ => tags)
+}