add tag page

This commit is contained in:
x
2025-03-19 19:49:59 +01:00
parent b29537d6d8
commit 69ca852379
3 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import db from "../../inc/sql.mjs";
import cfg from "../../inc/config.mjs";
import f0cklib from "../routeinc/f0cklib.mjs";
export default (router, tpl) => {
router.get(/^\/tags$/, async (req, res) => {
const phrase = cfg.websrv.phrases[~~(Math.random() * cfg.websrv.phrases.length)];
const toptags = await db`
SELECT t.id, t.tag, COUNT(DISTINCT ta.item_id) AS total_items
FROM tags t
LEFT JOIN tags_assign ta ON t.id = ta.tag_id
GROUP BY t.id, t.tag
ORDER BY total_items DESC
LIMIT 500
;
`;
res.reply({
body: tpl.render('tags', {
toptags,
phrase,
tmp: null
}, req)
});
});
return router;
};