h at the top, or Back, returns to “{clip(backLabel(), 40)}”.
/**
* A web page shown as an article view, the way Wiki.tsx shows a Wikipedia article: its lead is
* its text, its sections are rows (in a pane a section opens as the next pane; on the column's page
* it opens in place), its links are Tab stops (one to an article opens the article, in the link's
* own language; one to another page opens that page), and its figures show through the server's
* media route. It is never stored in the library: it comes from /api/page/article, read once by
* the server and kept in its cache (server/page.ts).
*
* It takes the article views' structure and classes (`.wiki`, `.wiki-head`, `.wiki-text`, `.wrows`)
* with a `.web` modifier: an amber ground and a ↗ at the head instead of Wikipedia's W, so it is
* always clear whose text this is. Its head names the site, the title and who wrote it; its foot
* says where it is from, when it was read and what was changed. A page that cannot be shown says
* why in plain words and offers the original. Its text takes annotations as Wikipedia's does (the
* same keys, the same notes, kept under the page's node in the library: src/core/article.ts); a
* note whose words a newer copy lacks is listed as detached, and on a page that cannot be shown
* every note is. What a model made of it at the reader's request (s) is marked as the model's: its
* summary above the lead (the page's own opening still follows), a line when the sections are the
* model's, and the foot.
*/
import { useContext } from "preact/hooks";
import { clip } from "../core/text";
import { PaneCtx, useForkMark } from "./Links";
import { sameAux, store, type SecId, type Source, type WRow } from "./store";
import { ArticleTextView, Detached, Problem, WikiPage, WikiView, backLabel, detachedIn } from "./Wiki";
import { article, attributionText, byline, cachedSummary, sectionsUnder, siteOf, webKey, type WebArticle, type WebProblem } from "./web";
/**
* What an article view under a node is drawn as. `own`: the view is its pane's own (a section that
* is only a link, shown as its article), not an inset under the node's text. `headFocused`: its
* head is focused because the node is (that pane's head, as a node's pane has).
*/
export interface ViewOpts {
own?: boolean;
headFocused?: boolean;
}
/** Any article view by its host: a web page's, or Wikipedia's. */
export function ArticleView({ host, ...o }: { host: string } & ViewOpts) {
return store.isWeb(host) ? h at the top, or Back, returns to “{clip(backLabel(), 40)}”.
{title}
{sub && › {sub}}
{line && }
{attributionText(a)}{" "} the original
); } /** The summary a model wrote of the page, set apart and labelled so it is never taken for the page's own words. */ function ModelSummary({ m }: { m: NonNullable{p.description}
}Open in a new tab {" "} · W does the same
> ); } /** The title a page goes by before it has arrived: the link's own, else its site. */ function knownTitle(host: string, url: string): string { const h = store.viewHost(host); const r = h?.embedded ? store.targetOf(h.embedded) : undefined; if (r?.kind === "url" && r.title) return r.title; if (host === "col" && store.colWiki?.url === url && store.colWiki.title !== siteOf(url)) return store.colWiki.title; return siteOf(url); } /** One web page's view. `host` says which (see Aux in store.ts). */ export function WebView({ host, own, headFocused }: { host: string } & ViewOpts) { const tid = useContext(PaneCtx); const fork = useForkMark(); const h = store.viewHost(host); if (h?.src !== "web") return null; // Under a node, the page opened in a pane of its own (L) is marked at this head, where its curve starts. const mark = h.embedded ? fork?.(webKey(h.url)) : undefined; const a = store.aux; const at = (row: WRow) => (row.t === "head" && !!headFocused) || (!!a && a.kind === "wiki" && a.host === host && !a.grain && sameAux(a, { kind: "wiki", host, row })); const cls = `wiki web${h.embedded && !own ? " embedded" : ""}`; // Under a section, folded: what the server's cache knows of it (never a request to the site), until l opens it. if (store.folded(h.embedded)) { const sum = cachedSummary(h.url); const s = sum.state === "ready" ? sum.value : null; return ({s.description}
}l reads the page here · L opens it in a pane of its own · W the original
); } const art = article(h.url); if (art.state === "loading") { return (Reading the page…
); } if (art.state === "failed") { return (The page no longer answers; this is the copy read before. R tries again.
} {!sec && v.model?.summary &&Sections arranged by a model at your request; the page has no headings of its own.
}