From 8faa84d56730bd1fc35b10d3d29db424691e3af5 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 4 Jun 2022 16:58:22 +0200 Subject: Generic stats and select --- info.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'info.js') diff --git a/info.js b/info.js index 95813b6..2d8382e 100644 --- a/info.js +++ b/info.js @@ -1,30 +1,34 @@ const fs = require("fs").promises +const criteriaKeys = ["tag", "group", "artist", "character", "parody"] 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 => {data.title = dirent.name; return data}) .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)) + .filter(([title, data]) => title && data)) + //.filter(([title, data]) => (title == data.title) == !shortNames)) .then(doujins => Object.fromEntries(doujins)) -module.exports.tags = _ => { - const tags = {"*": []} +module.exports.criteria = _ => { + const criteria = Object.fromEntries(criteriaKeys.map(key => [key, {["*"]: []}])) return module.exports.doujins() .then(doujins => Object.values(doujins)) .then(doujins => doujins - .forEach(doujin => { - tags["*"].push(doujin.title) + .forEach(doujin => + criteriaKeys.forEach(crit => { + criteria[crit]["*"].push(doujin.title) - doujin.tag && doujin.tag.forEach(tag => { - tags[tag] = tags[tag] || [] - tags[tag].push(doujin.title) + doujin[crit] && doujin[crit].forEach(val => { + criteria[crit][val] = criteria[crit][val] || [] + criteria[crit][val].push(doujin.title) + }) }) - })) - .then(_ => tags) + )) + .then(_ => criteria) } -- cgit v1.2.3