Web pages: a link to any address opens as an article, as Wikipedia's do
A url link now opens in the app instead of the browser. The server fetches the page (robots.txt honoured, public addresses only, size and time caps), keeps a snapshot on disk until it is reloaded, and cuts it into a lead and sections: by its headings, else by pseudo-headings, else in chunks, or by a model when asked (s), within a daily budget. The pane has its own amber ground, the author and date in its head when the page gives them, and the source in its foot. W opens the original, R reads it again. See docs/pages.md. Pictures and videos are kept, in web pages and in Wikipedia articles: pictures through the server (only addresses seen in a page that was read), videos as a still that loads the player on a click. A section that is only a link (a target, no text, no sections) opens as its article at once, and L opens a target to the right of the node's own pane, never under it. Article text is sized to read like the reader's own. Panes: a pane that already has all its column can give beside the others' tabs no longer peeks over them on hover, and the curves of tabs under a peeking pane are no longer drawn over it. The keypress timing test judges each of its two passes on its own, so a stall from outside the app does not fail it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
a3f25fbdcc
commit
f8c6576ea1
58 files changed
+8606
-367
No files matched your search
+227
@@ -0,0 +1,227 @@
|
||||
/**
|
||||
* 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. Nothing is written on it: annotations are for
|
||||
* Wikipedia's text and the reader's own. 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, type Range } from "../core/text";
|
||||
import { PaneCtx, useForkMark } from "./Links";
|
||||
import { sameAux, store, type WRow } from "./store";
|
||||
import { Blocks, Problem, WikiPage, WikiView, backLabel } from "./Wiki";
|
||||
import { articleText } 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) ? <WebView host={host} {...o} /> : <WikiView host={host} {...o} />;
|
||||
}
|
||||
|
||||
/** The column's article page, Wikipedia's or a web page's. */
|
||||
export function ArticlePage() {
|
||||
if (!store.colWiki?.url) return <WikiPage />;
|
||||
return (
|
||||
<article class="wiki-page web">
|
||||
<WebView host="col" />
|
||||
<p class="wiki-back">h at the top, or Back, returns to “{clip(backLabel(), 40)}”.</p>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
/** A piece of the page's text (the lead or a section) as text the keys select in, as an article's is; it carries no annotations. */
|
||||
function WebText({ host, row, html }: { host: string; row: WRow; html: string }) {
|
||||
const at = articleText(html, true);
|
||||
const a = store.aux;
|
||||
const here = a?.kind === "wiki" && a.host === host && sameAux({ ...a, grain: undefined, range: undefined }, { kind: "wiki", host, row });
|
||||
const sel = here && a.grain && a.range ? { grain: a.grain, range: a.range } : null;
|
||||
const link: Range | null = sel && at.links.some((l) => l.range[0] === sel.range[0] && l.range[1] === sel.range[1]) ? sel.range : null;
|
||||
const fork = useForkMark();
|
||||
return (
|
||||
<div class="wiki-text" data-wtext={row.t === "sec" ? row.id : "head"}>
|
||||
<Blocks bs={at.blocks} c={{ text: at.text, notes: [], sel, link, fork }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The ↗ and the site that mark a web page's text, its title, and its byline (author · site · date, only what the page gives). */
|
||||
function Head({ url, title, sub, line, focused, mark }: { url: string; title: string; sub?: string; line?: string; focused: boolean; mark?: string }) {
|
||||
return (
|
||||
<header class={`wiki-head${focused ? " focused" : ""}${mark ? ` ${mark}` : ""}`}>
|
||||
<div class="wiki-brand">
|
||||
<span class="wmark umark">↗</span> {siteOf(url)}
|
||||
</div>
|
||||
<h2>
|
||||
{title}
|
||||
{sub && <span class="wsub"> › {sub}</span>}
|
||||
</h2>
|
||||
{line && <p class="web-byline">{line}</p>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
/** The line every view of a page's text ends with: where it is from, who wrote it, when it was read, what was changed, and the original. */
|
||||
function Attribution({ a }: { a: WebArticle["attribution"] }) {
|
||||
return (
|
||||
<p class="wattr">
|
||||
{attributionText(a)}{" "}
|
||||
<a href={a.url} target="_blank" rel="noopener noreferrer">the original</a>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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<WebArticle["model"]> }) {
|
||||
return (
|
||||
<aside class="web-model" data-model-summary>
|
||||
<p class="web-model-label">Summary written by a model{m.by ? ` (${m.by})` : ""} from the page's openings, at your request; not the author's words</p>
|
||||
<p class="web-model-text">{m.summary}</p>
|
||||
{m.note && <p class="web-model-label">{m.note}</p>}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
/** A page that is not shown: what is known of it, why, and the original in a new tab. */
|
||||
function Unusable({ url, p }: { url: string; p: WebProblem }) {
|
||||
return (
|
||||
<>
|
||||
{p.description && <p class="wiki-desc">{p.description}</p>}
|
||||
<Problem message={p.message} />
|
||||
<p class="web-open">
|
||||
<a href={url} target="_blank" rel="noopener noreferrer" data-original>
|
||||
Open in a new tab
|
||||
</a>{" "}
|
||||
· W does the same
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<section class={`${cls} folded${at({ t: "head" }) ? " focused" : ""}`} data-host={host}>
|
||||
<Head url={h.url} title={s?.title ?? knownTitle(host, h.url)} line={s ? byline(s) : undefined} focused={at({ t: "head" })} mark={mark} />
|
||||
{s?.description && <p class="wiki-summary">{s.description}</p>}
|
||||
<p class="wiki-more">l reads the page here · L opens it in a pane of its own · W the original</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const art = article(h.url);
|
||||
if (art.state === "loading") {
|
||||
return (
|
||||
<section class={cls} data-host={host}>
|
||||
<Head url={h.url} title={knownTitle(host, h.url)} focused={at({ t: "head" })} mark={mark} />
|
||||
<p class="wiki-wait">Reading the page…</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
if (art.state === "failed") {
|
||||
return (
|
||||
<section class={`${cls} unusable`} data-host={host} data-reason={art.reason}>
|
||||
<Head url={h.url} title={art.title ?? knownTitle(host, h.url)} line={art.site && art.site !== siteOf(h.url) ? art.site : undefined} focused={at({ t: "head" })} mark={mark} />
|
||||
<Unusable url={h.url} p={art} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
const v = art.value;
|
||||
const at0 = v.attribution;
|
||||
const sec = h.sec !== null ? v.sections.find((x) => x.id === h.sec) : undefined;
|
||||
const line = byline({ author: at0.author, site: at0.site, published: at0.published });
|
||||
// A section the page no longer has: its pane is closed as the page arrives (store.livePane); never the lead in its place.
|
||||
if (h.sec !== null && !sec) {
|
||||
return (
|
||||
<section class={cls} data-host={host}>
|
||||
<Head url={h.url} title={v.title} line={line} focused={at({ t: "head" })} mark={mark} />
|
||||
<Problem message="This section is no longer in the page." />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
// A section open as a pane to the right is marked: the picked child "showing", another fork "forked".
|
||||
const showing = (id: string): string | undefined => (store.panes ? store.kidMark(tid, (r) => r.kind === "web" && r.sec === id && webKey(r.url) === webKey(h.url)) : undefined);
|
||||
return (
|
||||
<section class={cls} data-host={host} data-outline={v.outline}>
|
||||
<Head url={h.url} title={v.title} sub={sec?.heading} line={line} focused={at({ t: "head" })} mark={mark} />
|
||||
{at0.stale && <p class="wiki-wait">The page no longer answers; this is the copy read before. R tries again.</p>}
|
||||
{!sec && v.model?.summary && <ModelSummary m={v.model} />}
|
||||
{sec || v.lead ? <WebText host={host} row={{ t: "head" }} html={sec ? sec.html : v.lead} /> : null}
|
||||
{!sec && v.outline === "model" && <p class="web-model-label web-arranged">Sections arranged by a model at your request; the page has no headings of its own.</p>}
|
||||
<Rows article={v} host={host} parent={h.sec} nested={!!h.nested} at={at} showing={showing} />
|
||||
<Attribution a={at0} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Rows(props: { article: WebArticle; host: string; parent: string | null; nested: boolean; at: (r: WRow) => boolean; showing: (id: string) => string | undefined }) {
|
||||
const { article: v, host, parent, nested, at, showing } = props;
|
||||
const kids = sectionsUnder(v, parent);
|
||||
if (!kids.length) return null;
|
||||
return (
|
||||
<ul class={`wrows${parent ? " nested" : ""}`}>
|
||||
{kids.map((x) => {
|
||||
const row: WRow = { t: "sec", id: x.id };
|
||||
const open = nested && store.secOpen(host, x.id);
|
||||
const leaf = !sectionsUnder(v, x.id).length;
|
||||
const mark = showing(x.id);
|
||||
return (
|
||||
<li key={x.id} class={`wrow${at(row) ? " focused" : ""}${open ? " open" : ""}${mark ? ` ${mark}` : ""}`}>
|
||||
<div class="row" data-wrow={x.id}>
|
||||
<span class="mark">{open ? "▾" : leaf && !x.html ? "·" : "▸"}</span>
|
||||
<span class="title">{x.heading}</span>
|
||||
</div>
|
||||
{open && (
|
||||
<div class="content">
|
||||
<WebText host={host} row={row} html={x.html} />
|
||||
<Rows {...props} parent={x.id} />
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user