diff --git a/public/s/css/f0ck.css b/public/s/css/f0ck.css index 6d47944..899bc41 100644 --- a/public/s/css/f0ck.css +++ b/public/s/css/f0ck.css @@ -474,6 +474,12 @@ html, body { overscroll-behavior-y: contain; overflow: overlay; font-size: 14px; + height: 100%; +} +@supports (-moz-appearance:none) { + html, body { + height: auto !important; + } } .noscript-badge { @@ -570,6 +576,7 @@ div#posts > a:hover::after { } .navbar { + position: -webkit-sticky; position: sticky; top: 0; padding: 0; @@ -1532,7 +1539,6 @@ table.table { min-width: max-content; } table.table thead tr { - text-align: left; font-weight: bolder; border-bottom: 1px solid var(--accent); } @@ -1541,6 +1547,7 @@ table.table tr { } table.table th, table.table td { padding: 7px 15px; + text-align: center; } table.table tbody tr:nth-of-type(odd) { background-color: var(--badge-tag); diff --git a/src/inc/lib.mjs b/src/inc/lib.mjs index ff6bfea..780878d 100644 --- a/src/inc/lib.mjs +++ b/src/inc/lib.mjs @@ -64,8 +64,17 @@ export default new class { if(env.tag) link.push("tag", env.tag); if(env.user) link.push("user", env.user, env.type ?? 'f0cks'); if(env.mime.length > 2) link.push(env.mime); - if(env.page) link.push("p", env.page); - return link.join("/"); + + let tmp = link.length === 0 ? '/' : link.join('/'); + if(!tmp.endsWith('/')) + tmp = tmp + '/'; + if(!tmp.startsWith('/')) + tmp = '/' + tmp; + + return { + main: tmp, + path: env.path ? env.path : '' + }; }; parseTag(tag) { if(!tag) diff --git a/src/inc/routeinc/f0cklib.mjs b/src/inc/routeinc/f0cklib.mjs index c7270a1..3c26ac9 100644 --- a/src/inc/routeinc/f0cklib.mjs +++ b/src/inc/routeinc/f0cklib.mjs @@ -161,7 +161,7 @@ export default { for(let i = Math.max(1, act_page - 3); i <= Math.min(act_page + 3, pages); i++) cheat.push(i); - const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' }); + const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks', path: 'p/' }); data = { success: true, @@ -172,11 +172,10 @@ export default { prev: (act_page > 1) ? act_page - 1 : null, next: (act_page < pages) ? act_page + 1 : null, page: act_page, - cheat: cheat, - uff: false + cheat: cheat }, - link: link, - tmp: tmp + link, + tmp }; return data; }, @@ -279,7 +278,7 @@ export default { const tags = await lib.getTags(itemid); const cheat = [...new Set(items.slice(Math.max(0, item - 3), item + 4).map(i => i.id))]; - const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' }); + const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks', path: '' }); const favorites = await db` select "user".user, "user_options".avatar from "favorites" @@ -327,12 +326,11 @@ export default { next: items[item + 1]?.id, prev: items[item - 1]?.id, page: actitem.id, - cheat: cheat, - uff: true + cheat: cheat }, phrase: cfg.websrv.phrases[~~(Math.random() * cfg.websrv.phrases.length)], - link: link, - tmp: tmp + link, + tmp }; return data; }, diff --git a/src/inc/routes/search.mjs b/src/inc/routes/search.mjs index 28f52fd..2fe2d65 100644 --- a/src/inc/routes/search.mjs +++ b/src/inc/routes/search.mjs @@ -2,42 +2,92 @@ import db from "../sql.mjs"; import lib from "../lib.mjs"; import search from "../routeinc/search.mjs"; +const _eps = 20; + export default (router, tpl) => { router.get(/^\/search(\/)?$/, lib.auth, async (req, res) => { let ret; - let tag = req.url.qs?.tag; - if(Object.keys(req.url.qs).length > 0) { - let rows; + let tag = req.url.qs.tag ?? []; + let page = req.url.qs.page ?? 1; + let total = 0; + let pagination, link; + + if(tag.length > 1) { + if(tag.startsWith('src:')) { + total = (await db` + select count(*) as total + from "items" + where src ilike ${'%' + tag.substring(4) + '%'} + group by "items".id, "tags".tag + `).length; + } + else { + total = (await db` + select count(*) as total + from "tags" + left join "tags_assign" on "tags_assign".tag_id = "tags".id + left join "items" on "items".id = "tags_assign".item_id + where "tags".tag ilike ${'%' + tag + '%'} + group by "items".id, "tags".tag + `).length; + } + + const pages = +Math.ceil(total / _eps); + const act_page = Math.min(pages, page || 1); + const offset = Math.max(0, (act_page - 1) * _eps); if(tag.startsWith('src:')) { - tag = tag.substring(4); ret = await db` select * from "items" - where src ilike ${'%' + tag + '%'} - limit 500 + where src ilike ${'%' + tag.substring(4) + '%'} + group by "items".id, "tags".tag + offset ${offset} + limit ${_eps} `; } else { - rows = await db` + const rows = await db` select "items".id, "items".username, "items".mime, "tags".tag from "tags" left join "tags_assign" on "tags_assign".tag_id = "tags".id left join "items" on "items".id = "tags_assign".item_id where "tags".tag ilike ${'%' + tag + '%'} - limit 500 + group by "items".id, "tags".tag + offset ${offset} + limit ${_eps} `; ret = search(rows, tag); } + + const cheat = []; + for(let i = Math.max(1, act_page - 3); i <= Math.min(act_page + 3, pages); i++) + cheat.push(i); + + pagination = { + start: 1, + end: pages, + prev: (act_page > 1) ? act_page - 1 : null, + next: (act_page < pages) ? act_page + 1 : null, + page: act_page, + cheat: cheat, + uff: false + }; + link = { + main: `/search/?tag=${tag}`, + path: '&page=' + }; } - + res.reply({ body: tpl.render("search", { result: ret, totals: await lib.countf0cks(), searchstring: tag, - session: req.session, - tmp: null + count: total, + tmp: null, + pagination, + link }, req) }); }); diff --git a/views/index.html b/views/index.html index 0563074..a18189d 100644 --- a/views/index.html +++ b/views/index.html @@ -1,10 +1,10 @@ @include(snippets/header)