"""Server-rendered share/landing page for /a/. A *pointer* page (never a republished article): the story's own title, "why it's uplifting" note, and image, wrapped with rich OpenGraph/Twitter meta and a prominent link to the original source. Social scrapers don't run JS, so this is plain server-rendered HTML. All dynamic values are HTML-escaped. """ from __future__ import annotations from html import escape from .newsimg import display_url def _tag(name: str, content: str | None, attr: str = "property") -> str: if not content: return "" return f'' # --- Shared top bar ----------------------------------------------------------------- # A static replica of the SPA's HubBar so server-rendered share pages (/a/, the # digest) carry the SAME toolbar as the rest of the site. These pages can't run the # Svelte component, so this is kept in sync with frontend/src/lib/components/HubBar.svelte # (+ HubShell's borderless Back) BY HAND — change both together. `active` highlights a # section ('' = none, as on an article). The account glyph is the signed-out state; # _TOP_BAR_JS swaps in the cached avatar for signed-in readers, just like HubBar. _TOP_NAV = (("/", "Home", "home"), ("/news", "News", "news"), ("/play", "Games", "games"), ("/art", "Art", "art")) def _nav_links(active: str) -> str: return "".join(f'{label}' for href, label, k in _TOP_NAV) def _top_bar_html(active: str = "") -> str: return ( '
' 'upbeatBytes' '
' f'' '' '' '' '
' f'' ) def _back_link_html(label: str = "Back") -> str: return ('') # Ported verbatim from HubBar.svelte's {_top_bar_html()}
{_back_link_html()}
{src_click} {_BACK_JS} {_TOP_BAR_JS} {poll} """ def render_digest(items: list[dict], base_url: str, brief_date: str | None) -> str: """A shareable, indexable 'today's good news, summarized' page.""" lead_img = next((i.get("image_url") for i in items if i.get("image_url")), None) intro = "The day's calm, constructive news — summarized in plain English, so you can get the gist and go deeper only if you want." page_url = f"{base_url}/today" cards = "" for it in items: aid = it["id"] title = escape((it.get("title") or "").strip()) source = escape((it.get("source_name") or "the source").strip()) src_url = escape(it.get("canonical_url") or base_url) gist = escape((it.get("summary") or it.get("reason_text") or it.get("description") or "").strip()) cards += ( '" ) meta = "\n".join(filter(None, [ _tag("og:site_name", "upbeatBytes"), _tag("og:type", "website"), _tag("og:title", "Today's good news, summarized"), _tag("og:description", intro), _tag("og:url", page_url), _tag("og:image", lead_img), _tag("twitter:card", "summary_large_image" if lead_img else "summary", attr="name"), _tag("twitter:title", "Today's good news, summarized", attr="name"), _tag("twitter:description", intro, attr="name"), _tag("twitter:image", lead_img, attr="name"), ])) return f""" Today's good news, summarized · upbeatBytes {meta} {_top_bar_html()}

Today's good news

{escape(intro)}{f' · {escape(brief_date)}' if brief_date else ''}

{cards}

Browse more on upbeatBytes →

{_TOP_BAR_JS} """ def render_not_found(base_url: str) -> str: return f""" Story not found · upbeatBytes upbeatBytes

That story isn't here

It may have moved on — the good news refreshes often.

← Back to upbeatBytes """