Release ani-cli-web 0.26.0

This commit is contained in:
Dymas
2026-05-15 23:56:11 +02:00
parent a6ef93cc95
commit 6b1e0ce7f0
13 changed files with 5667 additions and 3440 deletions
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Shared page-shell helpers for inline HTML templates."""
PAGE_LINKS = (
("search", "Search", "/"),
("config", "Config", "/config"),
("watchlist", "Watchlist", "/watchlist"),
)
BROWSER_API_HELPER = r"""
async function api(path, options = {}) {
const headers = new Headers(options.headers || {});
if (options.body && !headers.has("Content-Type")) {
headers.set("Content-Type", "application/json");
}
const response = await fetch(path, {
...options,
headers
});
const raw = await response.text();
let data = {};
if (raw) {
try {
data = JSON.parse(raw);
} catch (_error) {
data = { error: raw };
}
}
if (!response.ok) throw new Error(data.error || response.statusText || "Request failed");
return data;
}
"""
BROWSER_POLL_HELPER = r"""
function startSerialPoll(callback, intervalMs) {
let inFlight = false;
return window.setInterval(async () => {
if (inFlight) return;
inFlight = true;
try {
await callback();
} finally {
inFlight = false;
}
}, intervalMs);
}
"""
def render_sidebar_brand(note, badge, badge_id=""):
badge_attr = f' id="{badge_id}"' if badge_id else ""
return (
' <div class="topline">\n'
' <div class="brand-wrap">\n'
' <h1>ani-cli <span class="brand-word">web</span></h1>\n'
f" <p class=\"shell-note\">{note}</p>\n"
" </div>\n"
f" <span class=\"badge\"{badge_attr}>{badge}</span>\n"
" </div>\n"
)
def render_page_links(active_page):
links = []
for key, label, href in PAGE_LINKS:
class_name = "page-link active" if key == active_page else "page-link"
links.append(f' <a class="{class_name}" href="{href}">{label}</a>')
return " <div class=\"page-links\">\n" + "\n".join(links) + "\n </div>\n"