added junimo theme, bumped browse to 50

This commit is contained in:
lichenblankie 2026-03-27 10:59:37 -07:00
parent 5ded9f1339
commit cf536a860c
3 changed files with 1637 additions and 10 deletions

View file

@ -116,6 +116,7 @@ def _error(status):
PER_PAGE = 10
BROWSE_PER_PAGE = 50
def _paginate(query, key="p"):
@ -126,10 +127,11 @@ def _paginate(query, key="p"):
return max(1, page)
def _page_nav(page, total, base_url):
if total <= PER_PAGE:
def _page_nav(page, total, base_url, per_page=None):
per_page = per_page or PER_PAGE
if total <= per_page:
return ""
total_pages = (total + PER_PAGE - 1) // PER_PAGE
total_pages = (total + per_page - 1) // per_page
sep = "&" if "?" in base_url else "?"
parts = []
if page > 1:
@ -377,13 +379,13 @@ def handle_add_submit(body):
def handle_pages(query=None):
page = _paginate(query or {})
offset = (page - 1) * PER_PAGE
offset = (page - 1) * BROWSE_PER_PAGE
db = get_db()
try:
total = db.execute("SELECT count(*) FROM pages").fetchone()[0]
rows = db.execute(
"SELECT id, url, title, note FROM pages ORDER BY id DESC LIMIT ? OFFSET ?",
(PER_PAGE, offset),
(BROWSE_PER_PAGE, offset),
).fetchall()
items = ""
for r in rows:
@ -404,7 +406,7 @@ def handle_pages(query=None):
return _respond(
f"<h1>indexed pages ({total})</h1>"
f"<ul>{items}</ul>"
f'{_page_nav(page, total, "/pages")}'
f'{_page_nav(page, total, "/pages", BROWSE_PER_PAGE)}'
f'<p><a href="/export">export</a> | <a href="/import">import</a></p>'
f'<a href="/">back</a>'
)
@ -678,7 +680,7 @@ def handle_tags():
def handle_tag_browse(tag_name, query=None):
page = _paginate(query or {})
offset = (page - 1) * PER_PAGE
offset = (page - 1) * BROWSE_PER_PAGE
db = get_db()
try:
total = db.execute(
@ -690,7 +692,7 @@ def handle_tag_browse(tag_name, query=None):
"JOIN page_tags pt ON p.id = pt.page_id "
"JOIN tags t ON t.id = pt.tag_id "
"WHERE t.name = ? ORDER BY p.id DESC LIMIT ? OFFSET ?",
(tag_name, PER_PAGE, offset),
(tag_name, BROWSE_PER_PAGE, offset),
).fetchall()
items = ""
for r in rows:
@ -707,7 +709,7 @@ def handle_tag_browse(tag_name, query=None):
f'<h1>tag: {esc(tag_name)}</h1>'
f'<p>{total} page(s)</p>'
f'<ul>{items}</ul>'
f'{_page_nav(page, total, f"/tags/{esc(tag_name)}")}'
f'{_page_nav(page, total, f"/tags/{esc(tag_name)}", BROWSE_PER_PAGE)}'
f'<a href="/tags">all tags</a> | <a href="/">back</a>'
)