Generalize pagination to work with things other than search
This commit is contained in:
+2
-1
@@ -20,11 +20,12 @@ module.exports.GET = async (req, res) => {
|
||||
}
|
||||
|
||||
// Search, if we have a query.
|
||||
const path = `/search?q=${url.search.q}&`
|
||||
const {limit, offset} = pagination.getValuesToPaginate({ currentPage: p, perPage: PER_PAGE })
|
||||
const results = await ds.search(db, q, limit, offset)
|
||||
const count = await ds.searchCount(db, q)
|
||||
const totalPages = pagination.getTotalPages({ totalItems: count, perPage: PER_PAGE })
|
||||
const out = await page.render('search', { q, rawQ: url.search.q, p, results, count, totalPages })
|
||||
const out = await page.render('search', { path, q, p, results, count, totalPages })
|
||||
return send(res, 200, out)
|
||||
//return send(res, 200, { results, count })
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<% if (i == p) { %>
|
||||
<span><%- i %></span>
|
||||
<% } else { %>
|
||||
<a href="/search?q=<%= q %>&p=<%= i %>"><%- i %></a>
|
||||
<a href="<%- path %>p=<%= i %>"><%- i %></a>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user