Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9be1491f0e | ||
|
|
29c1dc64ed | ||
|
|
a27958117f | ||
|
|
56fd5f854d | ||
|
|
932aee4404 | ||
|
|
ca1c0d5a6f | ||
|
|
9cbc4ab59d | ||
|
|
7aa2abbf8f | ||
|
|
eddb3f22f3 | ||
|
|
1702281dbf | ||
|
|
38b894a789 | ||
|
|
06409cdaac | ||
|
|
7ba6094360 | ||
|
|
c59ab2f058 | ||
|
|
078e80591b | ||
|
|
6563eebdba | ||
|
|
cac74ebb6b | ||
|
|
8b1bb6f994 | ||
|
|
3173a113b6 | ||
|
|
a21f919601 | ||
|
|
158b5f1961 | ||
|
|
f9ce0a4f3b | ||
|
|
2d595f8c15 | ||
|
|
b1fc8e24d7 | ||
|
|
c5cf799f68 | ||
|
|
a5edc7b3b6 |
+19
-12
@@ -20,9 +20,12 @@ Struct dumped to disk — separate from the kanta content database, path from
|
|||||||
## What is collected
|
## What is collected
|
||||||
|
|
||||||
The client (`pagerite.js`) POSTs fire-and-forget pings to `/_a` with
|
The client (`pagerite.js`) POSTs fire-and-forget pings to `/_a` with
|
||||||
`{fr, to}` (`fr` = source path):
|
`fr`, `to`, `hide` and `read` as query parameters (`fr` = source path;
|
||||||
|
falsy values are omitted):
|
||||||
|
|
||||||
- **Initial page load**: `to` is the loaded path. This ping is what starts
|
- **Initial page load**: only `to` — the loaded path — is sent, never `fr`
|
||||||
|
(an `fr` equal to `to` would log a bogus self-transition when a session
|
||||||
|
already exists, e.g. a second tab). This ping is what starts
|
||||||
the visit and counts the entry page view — the document GET alone records
|
the visit and counts the entry page view — the document GET alone records
|
||||||
nothing, so bots and admin browsing never register. JS-running crawlers
|
nothing, so bots and admin browsing never register. JS-running crawlers
|
||||||
(Googlebot, GoogleOther, Applebot, ...) do ping, but their User-Agent
|
(Googlebot, GoogleOther, Applebot, ...) do ping, but their User-Agent
|
||||||
@@ -34,7 +37,8 @@ The client (`pagerite.js`) POSTs fire-and-forget pings to `/_a` with
|
|||||||
abuse rules regardless. Reloads are not
|
abuse rules regardless. Reloads are not
|
||||||
visits: the ping is skipped (PerformanceNavigationTiming `reload`), so a
|
visits: the ping is skipped (PerformanceNavigationTiming `reload`), so a
|
||||||
refresh neither counts a second view nor logs a self-transition. The GET
|
refresh neither counts a second view nor logs a self-transition. The GET
|
||||||
handler stashes a cross-origin https `Referer` (origin part only) and any
|
handler stashes a cross-origin https `Referer` (origin part only —
|
||||||
|
unavailable to JS once the page has loaded) and any
|
||||||
`utm_*` query parameters in in-memory IP tables, consumed by the ping that
|
`utm_*` query parameters in in-memory IP tables, consumed by the ping that
|
||||||
starts the visit; internal or absent referers never touch the referer table.
|
starts the visit; internal or absent referers never touch the referer table.
|
||||||
- **Internal fetch-navigations**: `to` is the target path, sent only after
|
- **Internal fetch-navigations**: `to` is the target path, sent only after
|
||||||
@@ -45,16 +49,19 @@ The client (`pagerite.js`) POSTs fire-and-forget pings to `/_a` with
|
|||||||
back), so the exit URL is not necessarily the last trail entry. Outbound
|
back), so the exit URL is not necessarily the last trail entry. Outbound
|
||||||
links are stored by full URL so several links to the same domain remain
|
links are stored by full URL so several links to the same domain remain
|
||||||
distinct.
|
distinct.
|
||||||
- **Excluded**: back/forward (popstate) navigations, navigation involving
|
- **Excluded**: back/forward (popstate) navigations, navigating *to* the
|
||||||
the analytics page itself (`/_a`), and everything while the user has the
|
analytics page (`/_a` — its GET is untracked, and the server rejects it
|
||||||
editor open (`body.editing`). Admin noise, not visits.
|
as a ping target anyway), and everything while the user has the editor
|
||||||
|
open (`body.editing`). Admin noise, not visits. Navigating *away* from
|
||||||
|
`/_a` does ping: the fetch-navigation already GET-ed the target page
|
||||||
|
without the preload header, and without the ping that GET would flush to
|
||||||
|
the crawler list.
|
||||||
- **Admins**: when SSO is in use and the session is known to be an admin,
|
- **Admins**: when SSO is in use and the session is known to be an admin,
|
||||||
the client still pings but adds `hide=1`. The server then records
|
the client still pings but adds `hide=1`. The server then records
|
||||||
nothing — and if the same client session already had a visit from before
|
nothing — and if the same client session already had a visit from before
|
||||||
logging in, that visit is removed from the JSON along with the counts
|
logging in, that visit is removed from the JSON along with every count
|
||||||
recorded when it was created (site visit, entry view, entry transition).
|
it recorded — an in-memory per-visit log of count events makes full
|
||||||
Views/transitions logged by later pings inside such a visit lack
|
reversal possible. With no auth proxy (dev/test)
|
||||||
per-event timestamps and are left as-is. With no auth proxy (dev/test)
|
|
||||||
"admin" is everyone's state, so `hide` stays 0 and everything is recorded.
|
"admin" is everyone's state, so `hide` stays 0 and everything is recorded.
|
||||||
- The server validates `to`: internal paths must be valid slug paths
|
- The server validates `to`: internal paths must be valid slug paths
|
||||||
("/" or `[a-z0-9_-]` segments), external ones are re-derived to the
|
("/" or `[a-z0-9_-]` segments), external ones are re-derived to the
|
||||||
@@ -273,8 +280,8 @@ its end, disappearing under later pills when long — so the lanes reflect
|
|||||||
the path
|
the path
|
||||||
structure even where index pages are omitted — opposite transition
|
structure even where index pages are omitted — opposite transition
|
||||||
directions joined into organic
|
directions joined into organic
|
||||||
tapered connections whose middle width grows logarithmically with the
|
tapered connections whose middle width grows logarithmically (base 2)
|
||||||
count (uncapped), connections
|
with the daily hit rate (uncapped), connections
|
||||||
carrying less than 1% of the total traffic
|
carrying less than 1% of the total traffic
|
||||||
pruned, as are those whose thin middle would render below ~0.8 px —
|
pruned, as are those whose thin middle would render below ~0.8 px —
|
||||||
fainter strands are invisible and only their wide end flares would show; beads are simulated one by one in JS (requestAnimationFrame) and
|
fainter strands are invisible and only their wide end flares would show; beads are simulated one by one in JS (requestAnimationFrame) and
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Pagerite is a single-user CMS/blog. This document records the initial high-level
|
|||||||
## Editing
|
## Editing
|
||||||
|
|
||||||
- Editing happens **in place**, in two modes opened by two pens:
|
- Editing happens **in place**, in two modes opened by two pens:
|
||||||
- **Page mode** — the 🖊️ next to a page's heading (including 404s, which is how new pages start) opens a CodeMirror Markdown editor docked to the left of the article: the host sits inside `#content` (below the banner, never over the footer), the content shifts right and the sidebar hides while editing. Preview renders server-side per keystroke (no debouncing) straight into the visible article's heading and body.
|
- **Page mode** — the 🖊️ next to a page's heading (including 404s, which is how new pages start) opens a CodeMirror Markdown editor docked to the left of the article: the panel is fixed to the viewport's left edge (its top tracks the banner's bottom until the banner scrolls away), the content shifts right and the sidebar hides while editing. Preview renders server-side per keystroke (no debouncing) straight into the visible article's heading and body.
|
||||||
- **Site mode** — the 🖊️ on the banner opens a panel with the site **brand** (applied to the header live), a **theme** selector (swapping the theme stylesheet in place), **font** picks (heading/body/brand — stored as plain `:root` rows inside the custom CSS, referencing the base stylesheet's per-family font variables), a **site-wide custom CSS** field (injected into `<style id="pagerite-user">` in the live page head and swapped during fetch-navigation), the page's **banner design** selector (inherit / none / any design found on disk, inherited by children), the page's **banner HTML** field (supplementing the design, previewed into the real banner region, so you see exactly which banner you're editing) and the **structure tree**. Everything saves immediately as you edit — no save button, no edit mode.
|
- **Site mode** — the 🖊️ on the banner opens a panel with the site **brand** (applied to the header live), a **theme** selector (swapping the theme stylesheet in place), **font** picks (heading/body/brand — stored as plain `:root` rows inside the custom CSS, referencing the base stylesheet's per-family font variables), a **site-wide custom CSS** field (injected into `<style id="pagerite-user">` in the live page head and swapped during fetch-navigation), the page's **banner design** selector (inherit / none / any design found on disk, inherited by children), the page's **banner HTML** field (supplementing the design, previewed into the real banner region, so you see exactly which banner you're editing) and the **structure tree**. Everything saves immediately as you edit — no save button, no edit mode.
|
||||||
- Clicking a pen again closes the editor (without saving; a dirty preview reloads the page). The pens are `<button>`s wired up by `pagerite.js` — editing is an action, not a navigation. The editor's WebSocket **reconnects automatically** with local text and pending saves preserved. (All users are trusted authors for now; access control later with SSO.)
|
- Clicking a pen again closes the editor (without saving; a dirty preview reloads the page). The pens are `<button>`s wired up by `pagerite.js` — editing is an action, not a navigation. The editor's WebSocket **reconnects automatically** with local text and pending saves preserved. (All users are trusted authors for now; access control later with SSO.)
|
||||||
- **CodeMirror 6** for Markdown editing (no WYSIWYG), title/published controls. Images can be pasted straight into the editor or chosen via a file input: they upload to the content store (`PUT /_api/files/...`) and insert `` at the cursor.
|
- **CodeMirror 6** for Markdown editing (no WYSIWYG), title/published controls. Images can be pasted straight into the editor or chosen via a file input: they upload to the content store (`PUT /_api/files/...`) and insert `` at the cursor.
|
||||||
|
|||||||
+3
-3
@@ -6,18 +6,18 @@ The Vue editor is a single tabbed `EditorShell.vue` mounted in a host div create
|
|||||||
|
|
||||||
The shell hosts four kept-alive tabs (ordered site-wide first — site, structure — then, after a visual break, the per-page tabs — article, banner):
|
The shell hosts four kept-alive tabs (ordered site-wide first — site, structure — then, after a visual break, the per-page tabs — article, banner):
|
||||||
|
|
||||||
- `PageEditor.vue` — CodeMirror + server-rendered preview over WebSocket `/_api/ws/editor`, previewing into the visible article; editor scroll drives the article scroll — while any editor is open the window scroll is locked (`body.editing`), the panel exactly fills the available window height, and only `#main` scrolls; a format bar offers Markdown helpers — bold/italic/code/link/table/image upload, with Ctrl/Cmd-B/I/S bindings — for the hard-to-remember syntax. Edits content and title only, never the path.
|
- `PageEditor.vue` — CodeMirror + server-rendered preview over WebSocket `/_api/ws/editor`, previewing into the visible article; editor and article scrolls are linked proportionally both ways, applied instantly (the window keeps scrolling normally while any editor is open — the panel is fixed to the viewport's left edge, its top tracking the banner's bottom edge until the banner scrolls away — and the panel scrolls internally); a format bar offers Markdown helpers — bold/italic/code/link/table/image upload, with Ctrl/Cmd-B/I/S bindings — for the hard-to-remember syntax. Edits content and title only, never the path.
|
||||||
- `BannerEditor.vue` — per-page banner HTML + banner design selector, previewed into `#page-banner`.
|
- `BannerEditor.vue` — per-page banner HTML + banner design selector, previewed into `#page-banner`.
|
||||||
- `SiteEditor.vue` — site brand + optional custom brand HTML with image/video upload + theme selector + font picker + favicon upload — clicking the preview tile picks a new one — + site-wide custom CSS, CSS injected into `<head id="pagerite-user">`.
|
- `SiteEditor.vue` — site brand + optional custom brand HTML with image/video upload + theme selector + font picker + favicon upload — clicking the preview tile picks a new one — + site-wide custom CSS, CSS injected into `<head id="pagerite-user">`.
|
||||||
- `StructureEditor.vue` — the vue-draggable structure tree with always-editable title/slug inputs per row.
|
- `StructureEditor.vue` — the vue-draggable structure tree with always-editable title/slug inputs per row.
|
||||||
|
|
||||||
Media uploads everywhere use the image icon buttons (pasting into the editor works too). The article, banner and site-settings pens are shorthands that open the shell on the matching tab; once open, clicking a pen switches tabs (and retargets the editors to the current page) instead of closing/remounting. The close button in the tab bar closes the shell (Escape too); tabs have no close buttons of their own. Closing only HIDES the shell — the Vue app stays mounted, so page-editor state (unsaved text included) survives until a real page reload; saving there is explicit (Ctrl+S) and refreshes the page regions in place. Admin panels never reload the page.
|
Media uploads everywhere use the image icon buttons (pasting into the editor works too). The article, banner and site-settings pens are shorthands that open the shell on the matching tab; once open, clicking a pen switches tabs (and retargets the editors to the current page) instead of closing/remounting. The close button in the tab bar closes the shell (Escape too); tabs have no close buttons of their own. Closing only HIDES the shell — the Vue app stays mounted, so page-editor state (unsaved text included) survives until a real page reload; saving there is explicit (Ctrl+S) and refreshes the page regions in place. Admin panels never reload the page.
|
||||||
|
|
||||||
In-place page re-rendering shared by the banner/site/structure tabs lives in `swapdoc.js` (`runScripts`/`loadPlain`: fetch a page, swap the dynamic regions, replaceState). Placeholder texts are reserved for showing the actual default in effect when a field is left empty (e.g. the pending row's slug derived from its title); labels and help are real elements or tooltips, never placeholders.
|
In-place page re-rendering shared by the banner/site/structure tabs lives in `swapdoc.js` (`runScripts`/`loadPlain`: fetch a page, swap the dynamic regions, replaceState). It also exports `dropPageCache`, which the editor tabs call after any save that can alter the rendered HTML of other pages (theme, headings, structure, banners, site brand/CSS, favicon). Dropping the cache while editing avoids re-fetching every page immediately; the public runtime re-preloads visible links once the editor panel closes.
|
||||||
|
|
||||||
## Saving behavior
|
## Saving behavior
|
||||||
|
|
||||||
Everything saves immediately as you edit (brand/title/CSS debounced, slug on commit since it renames the path), theme change swaps the stylesheet in place, tree rows navigate in place without transitions when focused, and the front page is a root-only row whose empty slug is editable like any other.
|
Everything saves immediately as you edit (brand/title/CSS debounced, slug on commit since it renames the path), theme change swaps the stylesheet in place, tree rows navigate in place without transitions when focused, and the front page is a root-only row whose empty slug is editable like any other. Saves that can affect other pages drop the prefetch cache; the cache is rebuilt when the editor panel closes so navigation stays instant.
|
||||||
|
|
||||||
Every non-empty list (and the root) ends with a non-draggable plus footer row (vuedraggable `#footer` slot): clicking it starts a new pending page at that level (its slug placeholder shows the slug derived live from the title being typed), and while dragging it is the list's "end of list" drop target. Committing a pending page PUTs it with empty markdown (creates an empty page that renders with its title — saving never deletes; deletion is the page editor's explicit choice: saving trimmed-empty text issues a REST DELETE), then switches to the page editor tab for the actual writing.
|
Every non-empty list (and the root) ends with a non-draggable plus footer row (vuedraggable `#footer` slot): clicking it starts a new pending page at that level (its slug placeholder shows the slug derived live from the title being typed), and while dragging it is the list's "end of list" drop target. Committing a pending page PUTs it with empty markdown (creates an empty page that renders with its title — saving never deletes; deletion is the page editor's explicit choice: saving trimmed-empty text issues a REST DELETE), then switches to the page editor tab for the actual writing.
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Vue editor app entry, mounts the tabbed `EditorShell`. See `docs/editing.md` for
|
|||||||
|
|
||||||
## `pagerite.js`
|
## `pagerite.js`
|
||||||
|
|
||||||
Public page entry; runs fetch-navigation (backed by an in-memory page cache: every visible internal link is fetched once at load and clicks are then served from JS with no fetch — the current page itself is not refetched, it enters the cache when navigated to — and the editors' `loadPlain` keeps the cache current via a `pagerite:page-fetched` event; articles are `cache-control: no-cache` on the wire), scroll-reveal, OverlayScrollbars on `document.body` (floating, auto-hiding scrollbars that never reserve layout space or shift the page when appearing; native scroll APIs like `window.scrollTo` keep working; themed via the `--os-*` variables in pagerite.css), brand shrink-to-fit (the themed size is the maximum; JS reduces the font-size so a long brand or narrow viewport still fits one line), nav condense-to-fit (the top nav stays on one row: link gaps shrink first, then the side padding, then the font size; `flex-wrap: wrap` remains the no-JS fallback), code copy buttons, and the auth check.
|
Public page entry; runs fetch-navigation (backed by an in-memory page cache: every visible internal link is fetched once at load and clicks are then served from JS with no fetch — the current page itself is not refetched, it enters the cache when navigated to — and the editors' `loadPlain` keeps the cache current via a `pagerite:page-fetched` event; articles are `cache-control: no-cache` on the wire). Editors can drop the entire cache with the `pagerite:drop-page-cache` event when site-wide or page changes (theme, headings, structure, banners, etc.) invalidate the cached HTML of other pages; `main.js` triggers a fresh `pagerite:preload-pages` pass when the editor panel closes so navigation is fast again. Navigation that starts while the editor is open bypasses the cache and fetches the target page on demand. Also runs scroll-reveal, OverlayScrollbars on `document.body` (floating, auto-hiding scrollbars that never reserve layout space or shift the page when appearing; native scroll APIs like `window.scrollTo` keep working; themed via the `--os-*` variables in pagerite.css), brand shrink-to-fit (the themed size is the maximum; JS reduces the font-size so a long brand or narrow viewport still fits one line), nav condense-to-fit (the top nav stays on one row: link gaps shrink first, then the side padding, then the font size; `flex-wrap: wrap` remains the no-JS fallback), code copy buttons, and the auth check.
|
||||||
|
|
||||||
It first probes `GET /auth/api/settings` to detect whether Paskia SSO is available, then `GET /_api/settings` to learn the current session's admin status. The same reverse proxy that gates `/_api` returns 401 for anonymous users, 403 for users without the admin permission, and 200 for admins. When Paskia is detected, a login link (anonymous) or profile link (logged in) is shown in the banner corner; both are plain `<a href="/auth/">` links (Paskia does not support being iframed, so we navigate normally), and a `pageshow` handler re-probes auth when history navigation restores a cached page. Admins also get the page/banner edit pens and a site-settings pen, plus a `modulepreload` warm-up of the editor bundle (the hashed asset is immutable, so it costs nothing). If no Paskia SSO is detected (dev/no proxy), editing is left open. Pages themselves render identically for everyone; the real gate is the auth proxy in front of all of `/_api`.
|
It first probes `GET /auth/api/settings` to detect whether Paskia SSO is available, then `GET /_api/settings` to learn the current session's admin status. The same reverse proxy that gates `/_api` returns 401 for anonymous users, 403 for users without the admin permission, and 200 for admins. When Paskia is detected, a login link (anonymous) or profile link (logged in) is shown in the banner corner; both are plain `<a href="/auth/">` links (Paskia does not support being iframed, so we navigate normally), and a `pageshow` handler re-probes auth when history navigation restores a cached page. Admins also get the page/banner edit pens and a site-settings pen, plus a `modulepreload` warm-up of the editor bundle (the hashed asset is immutable, so it costs nothing). If no Paskia SSO is detected (dev/no proxy), editing is left open. Pages themselves render identically for everyone; the real gate is the auth proxy in front of all of `/_api`.
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ const abuseRows = computed(() => formatAbuseRows(rangeData.value?.abuse || [], c
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<p v-else class="empty">no crawler hits recorded yet</p>
|
|
||||||
|
|
||||||
<div v-if="abuseRows.length" class="visit-table-wrap">
|
<div v-if="abuseRows.length" class="visit-table-wrap">
|
||||||
<table class="visit-table">
|
<table class="visit-table">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { EditorView, basicSetup } from 'codemirror'
|
|||||||
import { EditorState } from '@codemirror/state'
|
import { EditorState } from '@codemirror/state'
|
||||||
import { html } from '@codemirror/lang-html'
|
import { html } from '@codemirror/lang-html'
|
||||||
import { cmHighlight, cmTheme } from './cmtheme'
|
import { cmHighlight, cmTheme } from './cmtheme'
|
||||||
import { loadPlain, runScripts } from './swapdoc'
|
import { dropPageCache, loadPlain, runScripts } from './swapdoc'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pagePath: { type: String, default: '' },
|
pagePath: { type: String, default: '' },
|
||||||
@@ -215,6 +215,8 @@ function onMessage(ev) {
|
|||||||
} else if (msg.type === 'saved') {
|
} else if (msg.type === 'saved') {
|
||||||
saveError.value = ''
|
saveError.value = ''
|
||||||
pendingSave = null
|
pendingSave = null
|
||||||
|
// Banner HTML/design changes affect the rendered page; invalidate prefetches.
|
||||||
|
dropPageCache()
|
||||||
refreshOnSave?.()
|
refreshOnSave?.()
|
||||||
refreshOnSave = null
|
refreshOnSave = null
|
||||||
} else if (msg.type === 'error') {
|
} else if (msg.type === 'error') {
|
||||||
|
|||||||
+45
-15
@@ -4,9 +4,9 @@
|
|||||||
// (/_api/ws/editor). Docked left of the article on the page itself.
|
// (/_api/ws/editor). Docked left of the article on the page itself.
|
||||||
// The socket connects when the editor is opened and reconnects with
|
// The socket connects when the editor is opened and reconnects with
|
||||||
// exponential backoff after a failure; unsaved text and pending saves
|
// exponential backoff after a failure; unsaved text and pending saves
|
||||||
// survive a disconnect. Editor scroll drives the article scroll (while
|
// survive a disconnect. Editor and article (window) scrolls are linked
|
||||||
// editing the window scroll is locked and only #main scrolls), keeping the
|
// proportionally both ways (syncWindowToEditor / syncEditorToWindow).
|
||||||
// rendered article at the cursor's position. Saving (💾 / Ctrl+S) is explicit
|
// Saving (💾 / Ctrl+S) is explicit
|
||||||
// and refreshes the page regions in place — never a reload — so the editor
|
// and refreshes the page regions in place — never a reload — so the editor
|
||||||
// state (unsaved text included) also survives closing the shell; it is lost
|
// state (unsaved text included) also survives closing the shell; it is lost
|
||||||
// only on a real page reload.
|
// only on a real page reload.
|
||||||
@@ -15,7 +15,7 @@ import { EditorView, basicSetup } from 'codemirror'
|
|||||||
import { EditorState } from '@codemirror/state'
|
import { EditorState } from '@codemirror/state'
|
||||||
import { markdown } from '@codemirror/lang-markdown'
|
import { markdown } from '@codemirror/lang-markdown'
|
||||||
import { cmHighlight, cmTheme } from './cmtheme'
|
import { cmHighlight, cmTheme } from './cmtheme'
|
||||||
import { loadPlain } from './swapdoc'
|
import { dropPageCache, loadPlain } from './swapdoc'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pagePath: { type: String, default: '' },
|
pagePath: { type: String, default: '' },
|
||||||
@@ -113,7 +113,9 @@ async function saveAndRefresh() {
|
|||||||
await save()
|
await save()
|
||||||
dirty.value = false
|
dirty.value = false
|
||||||
// Refresh the page regions from the server so nav/sidebar changes apply
|
// Refresh the page regions from the server so nav/sidebar changes apply
|
||||||
// (never a reload: the editor keeps its state).
|
// (never a reload: the editor keeps its state). Drop the prefetch cache
|
||||||
|
// first: heading/title changes affect navigation on every page.
|
||||||
|
dropPageCache()
|
||||||
loadPlain(path.value)
|
loadPlain(path.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,20 +309,42 @@ function onEditorShown() {
|
|||||||
if (dirty.value) requestRender()
|
if (dirty.value) requestRender()
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncScroll() {
|
// Bidirectional proportional scroll sync between the CodeMirror scroller
|
||||||
// Editor scroll drives the article: keep the rendered page at the same
|
// and the window (the article's scroller, also while editing). Both
|
||||||
// proportional position as the cursor area in the editor. While editing
|
// directions apply instantly (never smooth — a smooth window scroll feeds
|
||||||
// the window scroll is locked and #main is the scrolling element.
|
// its intermediate positions back into the editor and fights the user's
|
||||||
|
// scrolling) and coalesce to one update per frame. Loops are broken two
|
||||||
|
// ways: a driver flag held until one frame AFTER the write (the scroll
|
||||||
|
// event a programmatic write dispatches arrives asynchronously — clearing
|
||||||
|
// the flag in the writing frame would let the echo through and the two
|
||||||
|
// directions would chase each other, which showed up as random jumping
|
||||||
|
// whenever layout shifted the proportional targets mid-scroll), and a 1px
|
||||||
|
// tolerance so residual rounding is a no-op. When the panel's height
|
||||||
|
// changes mid-scroll (its top tracks the banner), the page is the driver:
|
||||||
|
// the editor is re-matched to the page's position, never vice versa.
|
||||||
|
function syncWindowToEditor() {
|
||||||
if (syncingScroll || !view) return
|
if (syncingScroll || !view) return
|
||||||
const main = document.getElementById('main')
|
|
||||||
if (!main) return
|
|
||||||
syncingScroll = true
|
syncingScroll = true
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const scroller = view.scrollDOM
|
const scroller = view.scrollDOM
|
||||||
const max = scroller.scrollHeight - scroller.clientHeight
|
const max = scroller.scrollHeight - scroller.clientHeight
|
||||||
const pct = max > 0 ? scroller.scrollTop / max : 0
|
const pct = max > 0 ? scroller.scrollTop / max : 0
|
||||||
main.scrollTop = pct * (main.scrollHeight - main.clientHeight)
|
const y = pct * Math.max(0, document.documentElement.scrollHeight - innerHeight)
|
||||||
syncingScroll = false
|
if (Math.abs(scrollY - y) > 1) scrollTo({ top: y, behavior: 'instant' })
|
||||||
|
requestAnimationFrame(() => { syncingScroll = false })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncEditorToWindow() {
|
||||||
|
if (syncingScroll || !view) return
|
||||||
|
syncingScroll = true
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const scroller = view.scrollDOM
|
||||||
|
const pageMax = Math.max(0, document.documentElement.scrollHeight - innerHeight)
|
||||||
|
const pct = pageMax > 0 ? scrollY / pageMax : 0
|
||||||
|
const top = pct * Math.max(0, scroller.scrollHeight - scroller.clientHeight)
|
||||||
|
if (Math.abs(scroller.scrollTop - top) > 1) scroller.scrollTop = top
|
||||||
|
requestAnimationFrame(() => { syncingScroll = false })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,7 +403,11 @@ onMounted(() => {
|
|||||||
}),
|
}),
|
||||||
parent: editorEl.value,
|
parent: editorEl.value,
|
||||||
})
|
})
|
||||||
view.scrollDOM.addEventListener('scroll', syncScroll)
|
view.scrollDOM.addEventListener('scroll', syncWindowToEditor)
|
||||||
|
// Page → editor: window scroll (and resizes, e.g. the panel growing when
|
||||||
|
// the banner scrolls away) re-match the editor to the page's position.
|
||||||
|
addEventListener('scroll', syncEditorToWindow, { passive: true })
|
||||||
|
addEventListener('resize', syncEditorToWindow)
|
||||||
// Opening the editor means you want to write: start focused.
|
// Opening the editor means you want to write: start focused.
|
||||||
view.focus()
|
view.focus()
|
||||||
window.__pageritePageEditor = {
|
window.__pageritePageEditor = {
|
||||||
@@ -399,6 +427,8 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
view?.destroy()
|
view?.destroy()
|
||||||
delete window.__pageritePageEditor
|
delete window.__pageritePageEditor
|
||||||
|
removeEventListener('scroll', syncEditorToWindow)
|
||||||
|
removeEventListener('resize', syncEditorToWindow)
|
||||||
removeEventListener('keydown', onKeydown)
|
removeEventListener('keydown', onKeydown)
|
||||||
removeEventListener('pagerite:editor-shown', onEditorShown)
|
removeEventListener('pagerite:editor-shown', onEditorShown)
|
||||||
})
|
})
|
||||||
@@ -606,7 +636,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
/* CodeMirror sits inside a bordered box, like a dialog's input area, with
|
/* CodeMirror sits inside a bordered box, like a dialog's input area, with
|
||||||
a slight margin to the panel edges. Wheel scroll stays in the editor and
|
a slight margin to the panel edges. Wheel scroll stays in the editor and
|
||||||
drives the article (syncScroll) instead of double-scrolling. */
|
drives the article (syncWindowToEditor) instead of double-scrolling. */
|
||||||
.editor {
|
.editor {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { EditorState } from '@codemirror/state'
|
|||||||
import { css } from '@codemirror/lang-css'
|
import { css } from '@codemirror/lang-css'
|
||||||
import { html } from '@codemirror/lang-html'
|
import { html } from '@codemirror/lang-html'
|
||||||
import { cmHighlight, cmTheme } from './cmtheme'
|
import { cmHighlight, cmTheme } from './cmtheme'
|
||||||
import { loadPlain, runScripts } from './swapdoc'
|
import { dropPageCache, loadPlain, runScripts } from './swapdoc'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pagePath: { type: String, default: '' },
|
pagePath: { type: String, default: '' },
|
||||||
@@ -110,6 +110,7 @@ async function uploadFavicon(file) {
|
|||||||
const { path: url } = await res.json()
|
const { path: url } = await res.json()
|
||||||
favicon.value = url
|
favicon.value = url
|
||||||
applyFavicon(url)
|
applyFavicon(url)
|
||||||
|
dropPageCache()
|
||||||
} else {
|
} else {
|
||||||
saveError.value = `⚠️ ${await errorDetail(res)}`
|
saveError.value = `⚠️ ${await errorDetail(res)}`
|
||||||
}
|
}
|
||||||
@@ -234,6 +235,7 @@ async function saveSettings(opts = {}) {
|
|||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
saveError.value = ''
|
saveError.value = ''
|
||||||
|
dropPageCache()
|
||||||
} else {
|
} else {
|
||||||
saveError.value = '⚠️ changes could not be saved'
|
saveError.value = '⚠️ changes could not be saved'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import { inject, onActivated, onMounted, onUnmounted, provide, ref, watch } from 'vue'
|
import { inject, onActivated, onMounted, onUnmounted, provide, ref, watch } from 'vue'
|
||||||
import StructureTree from './StructureTree.vue'
|
import StructureTree from './StructureTree.vue'
|
||||||
import { slugify } from './slugify'
|
import { slugify } from './slugify'
|
||||||
import { loadPlain } from './swapdoc'
|
import { dropPageCache, loadPlain } from './swapdoc'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pagePath: { type: String, default: '' },
|
pagePath: { type: String, default: '' },
|
||||||
@@ -144,6 +144,7 @@ async function commitPending() {
|
|||||||
}
|
}
|
||||||
pending.value = null
|
pending.value = null
|
||||||
await refreshPages()
|
await refreshPages()
|
||||||
|
dropPageCache()
|
||||||
await navigate(newPath)
|
await navigate(newPath)
|
||||||
// Hand over to the page editor tab for the actual writing.
|
// Hand over to the page editor tab for the actual writing.
|
||||||
shell?.switchMode('page')
|
shell?.switchMode('page')
|
||||||
@@ -171,6 +172,8 @@ async function postStructure(op) {
|
|||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
saveError.value = ''
|
saveError.value = ''
|
||||||
|
// Structure changes alter navigation on every page; drop prefetches.
|
||||||
|
dropPageCache()
|
||||||
loadPlain(path.value) // refresh menus and content from the server
|
loadPlain(path.value) // refresh menus and content from the server
|
||||||
} else {
|
} else {
|
||||||
saveError.value = `⚠️ ${await errorDetail(res)}`
|
saveError.value = `⚠️ ${await errorDetail(res)}`
|
||||||
@@ -234,6 +237,7 @@ async function removePage(node) {
|
|||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
saveError.value = ''
|
saveError.value = ''
|
||||||
refreshPages()
|
refreshPages()
|
||||||
|
dropPageCache()
|
||||||
const p = node.path
|
const p = node.path
|
||||||
if (p === path.value || (p && path.value.startsWith(`${p}/`))) {
|
if (p === path.value || (p && path.value.startsWith(`${p}/`))) {
|
||||||
// The current page was deleted — or reduced to a category, which now
|
// The current page was deleted — or reduced to a category, which now
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
* so the visual scale can normalize against a one-week reference.
|
* so the visual scale can normalize against a one-week reference.
|
||||||
*/
|
*/
|
||||||
import { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'
|
||||||
import { DAY, WEEK } from './analytics/time.js'
|
import { DAY } from './analytics/time.js'
|
||||||
import { formatCount } from './analytics/format.js'
|
import { formatCount, formatReadTime } from './analytics/format.js'
|
||||||
import {
|
import {
|
||||||
TNODE_W,
|
TNODE_W,
|
||||||
TNODE_H,
|
TNODE_H,
|
||||||
@@ -22,9 +22,10 @@ const props = defineProps({
|
|||||||
pageTree: { type: Array, default: null },
|
pageTree: { type: Array, default: null },
|
||||||
})
|
})
|
||||||
|
|
||||||
const visualScale = computed(() => {
|
const dayScale = computed(() => {
|
||||||
const { t0, t1 } = props.window
|
const { t0, t1 } = props.window
|
||||||
if (t0 != null && t1 != null) return WEEK / (t1 - t0)
|
// Convert raw counts to a daily hit rate (hits/day).
|
||||||
|
if (t0 != null && t1 != null) return DAY / (t1 - t0)
|
||||||
// 'all': scale by the actual data span, but never less than the 30-day
|
// 'all': scale by the actual data span, but never less than the 30-day
|
||||||
// minimum the plot enforces, so sparse young data is not over-amplified.
|
// minimum the plot enforces, so sparse young data is not over-amplified.
|
||||||
const times = new Set()
|
const times = new Set()
|
||||||
@@ -34,12 +35,12 @@ const visualScale = computed(() => {
|
|||||||
const arr = [...times]
|
const arr = [...times]
|
||||||
if (arr.length < 2) return 1
|
if (arr.length < 2) return 1
|
||||||
const span = Math.max(...arr) - Math.min(...arr)
|
const span = Math.max(...arr) - Math.min(...arr)
|
||||||
return WEEK / Math.max(span, 30 * DAY)
|
return DAY / Math.max(span, 30 * DAY)
|
||||||
})
|
})
|
||||||
|
|
||||||
const graph = computed(() =>
|
const graph = computed(() =>
|
||||||
props.data
|
props.data
|
||||||
? buildTransitionGraph(props.data, props.pageTree, props.data.visits || [], visualScale.value)
|
? buildTransitionGraph(props.data, props.pageTree, props.data.visits || [], dayScale.value)
|
||||||
: null,
|
: null,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ const live = [] // { e, p } — beads in flight, p = progress 0..1
|
|||||||
let lastTick = 0
|
let lastTick = 0
|
||||||
|
|
||||||
const MAX_BEAD_RATE = 120 // upper bound on total beads per second
|
const MAX_BEAD_RATE = 120 // upper bound on total beads per second
|
||||||
const TRAVERSAL_S = 1.5 // seconds to cross any segment, end to end
|
const TRAVERSAL_S = 0.4 // seconds to cross any segment, end to end
|
||||||
|
|
||||||
const syncBeads = (flows) => {
|
const syncBeads = (flows) => {
|
||||||
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||||
@@ -150,7 +151,7 @@ onBeforeUnmount(() => cancelAnimationFrame(rafId))
|
|||||||
const fitsPill = (label, fontPx = 19) => label.length * 0.52 * fontPx <= TNODE_W - 16
|
const fitsPill = (label, fontPx = 19) => label.length * 0.52 * fontPx <= TNODE_W - 16
|
||||||
|
|
||||||
const countLabel = (n) =>
|
const countLabel = (n) =>
|
||||||
n.readMin ? `${formatCount(n.views)}×${n.readMin}m` : formatCount(n.views)
|
n.readSec ? `${formatCount(n.views)}×${formatReadTime(n.readSec)}` : formatCount(n.views)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ const viewChart = computed(() => buildChart(viewSeries.value, now.value))
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<section v-for="c in [
|
<section v-for="c in [
|
||||||
{ ylabel: 'visits', chart: visitChart, legend: true, empty: 'no visits recorded yet' },
|
{ ylabel: 'visits', chart: visitChart, legend: true },
|
||||||
{ ylabel: 'views', chart: viewChart, legend: false, empty: 'no views recorded yet' },
|
{ ylabel: 'views', chart: viewChart, legend: false },
|
||||||
]" :key="c.ylabel">
|
]" :key="c.ylabel">
|
||||||
<template v-if="c.chart">
|
<template v-if="c.chart">
|
||||||
<svg class="chart" :viewBox="`${-MARGIN_L} 0 ${VIEW_W} ${VIEW_H}`"
|
<svg class="chart" :viewBox="`${-MARGIN_L} 0 ${VIEW_W} ${VIEW_H}`"
|
||||||
@@ -116,7 +116,6 @@ const viewChart = computed(() => buildChart(viewSeries.value, now.value))
|
|||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
</template>
|
</template>
|
||||||
<p v-else class="empty">{{ c.empty }}</p>
|
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ export function yScale(maxValue) {
|
|||||||
* and each run of candidates keeps only its best-scoring bucket as an
|
* and each run of candidates keeps only its best-scoring bucket as an
|
||||||
* edge). Each edge-delimited segment is then smoothed independently: every
|
* edge). Each edge-delimited segment is then smoothed independently: every
|
||||||
* bucket spreads its count with a fixed Gaussian sigma chosen so N events
|
* bucket spreads its count with a fixed Gaussian sigma chosen so N events
|
||||||
* in a single bucket peak at N events per unit, clipped to the segment and
|
* in a single bucket peak at N events per unit. Mass past a detected change
|
||||||
* renormalized so total visitor count is preserved exactly. The unit is
|
* point is dropped (kernel renormalized); mass past a true series edge is
|
||||||
|
* mirrored back, so the curve doesn't fall where data simply ends. Either
|
||||||
|
* way total visitor count is preserved exactly. The unit is
|
||||||
* one hour on the week view and one day on the month+ views, so the
|
* one hour on the week view and one day on the month+ views, so the
|
||||||
* smoothing time scale follows the range. The raw series is drawn faintly
|
* smoothing time scale follows the range. The raw series is drawn faintly
|
||||||
* behind the curve for reference. Operates on raw counts.
|
* behind the curve for reference. Operates on raw counts.
|
||||||
@@ -110,28 +112,42 @@ export function smooth(counts, binMinutes, unitMinutes, {
|
|||||||
|
|
||||||
// Process each discontinuity-delimited regime independently so the
|
// Process each discontinuity-delimited regime independently so the
|
||||||
// Gaussian cannot see through a detected boundary. Each input bin spreads
|
// Gaussian cannot see through a detected boundary. Each input bin spreads
|
||||||
// its count with the fixed sigma; the kernel is renormalized after
|
// its count with the fixed sigma. Mass that would fall past a detected
|
||||||
// clipping to the segment, preserving total visitor count apart from
|
// change point is dropped and the kernel renormalized; mass that would
|
||||||
// floating-point error.
|
// fall past a true series edge (first/last bin) is mirrored back into the
|
||||||
|
// segment, as if the data continued as its own reflection, so constant or
|
||||||
|
// rising data doesn't produce a spurious falling edge. Total visitor count
|
||||||
|
// is preserved apart from floating-point error.
|
||||||
const bounds = [0, ...edges, n]
|
const bounds = [0, ...edges, n]
|
||||||
const smoothed = new Float64Array(n)
|
const smoothed = new Float64Array(n)
|
||||||
for (let b = 0; b < bounds.length - 1; b++) {
|
for (let b = 0; b < bounds.length - 1; b++) {
|
||||||
const lo = bounds[b]
|
const lo = bounds[b]
|
||||||
const length = bounds[b + 1] - lo
|
const length = bounds[b + 1] - lo
|
||||||
|
const mirrorLeft = lo === 0
|
||||||
|
const mirrorRight = lo + length === n
|
||||||
const segment = counts.slice(lo, lo + length)
|
const segment = counts.slice(lo, lo + length)
|
||||||
for (let j = 0; j < length; j++) {
|
for (let j = 0; j < length; j++) {
|
||||||
const count = segment[j]
|
const count = segment[j]
|
||||||
if (!count) continue
|
if (!count) continue
|
||||||
const start = Math.max(0, j - radius)
|
// Collect (target bin, weight) pairs over the full kernel, folding
|
||||||
const end = Math.min(length, j + radius + 1)
|
// mirrored mass at series edges and dropping mass past change points.
|
||||||
|
const spread = new Map()
|
||||||
let weightSum = 0
|
let weightSum = 0
|
||||||
for (let i = start; i < end; i++) {
|
for (let i = j - radius; i <= j + radius; i++) {
|
||||||
const d = i - j
|
let k = i
|
||||||
weightSum += Math.exp(-0.5 * (d / sigmaBins) ** 2)
|
// Fold repeatedly for segments shorter than the kernel radius.
|
||||||
|
while (k < 0 || k >= length) {
|
||||||
|
if (k < 0 && mirrorLeft) k = -k - 1
|
||||||
|
else if (k >= length && mirrorRight) k = 2 * length - 1 - k
|
||||||
|
else { k = null; break }
|
||||||
}
|
}
|
||||||
for (let i = start; i < end; i++) {
|
if (k === null) continue
|
||||||
const d = i - j
|
const w = Math.exp(-0.5 * ((i - j) / sigmaBins) ** 2)
|
||||||
smoothed[lo + i] += count * Math.exp(-0.5 * (d / sigmaBins) ** 2) / weightSum
|
spread.set(k, (spread.get(k) || 0) + w)
|
||||||
|
weightSum += w
|
||||||
|
}
|
||||||
|
for (const [k, w] of spread) {
|
||||||
|
smoothed[lo + k] += count * w / weightSum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,9 +63,24 @@ export function sumRange(raw, t0, t1) {
|
|||||||
export function weeklySeries(buckets) {
|
export function weeklySeries(buckets) {
|
||||||
const raw = rawTimes(buckets)
|
const raw = rawTimes(buckets)
|
||||||
const times = Object.keys(raw).map(Number)
|
const times = Object.keys(raw).map(Number)
|
||||||
if (!times.length) return null
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const thisMonday = mondayUTC(now)
|
const thisMonday = mondayUTC(now)
|
||||||
|
if (!times.length) {
|
||||||
|
const points = []
|
||||||
|
const end = Math.min(thisMonday + WEEK, Math.floor(now / MIN5) * MIN5 + MIN5)
|
||||||
|
for (let t = thisMonday; t < end; t += MIN5) {
|
||||||
|
points.push({ t, count: 0 })
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
series: [{ points, label: `Week ${isoWeek(thisMonday)}`, opacity: 1, area: true }],
|
||||||
|
t0: thisMonday,
|
||||||
|
t1: thisMonday + WEEK,
|
||||||
|
rate: HOUR / MIN5,
|
||||||
|
binMinutes: 5,
|
||||||
|
unitMinutes: 60,
|
||||||
|
unit: 'hour',
|
||||||
|
}
|
||||||
|
}
|
||||||
const oldest = Math.min(...times)
|
const oldest = Math.min(...times)
|
||||||
// Weeks back as far as the data reaches: difference in Monday indices.
|
// Weeks back as far as the data reaches: difference in Monday indices.
|
||||||
const available = (thisMonday - mondayUTC(oldest)) / WEEK + 1
|
const available = (thisMonday - mondayUTC(oldest)) / WEEK + 1
|
||||||
@@ -113,13 +128,27 @@ export function weeklySeries(buckets) {
|
|||||||
export function rollingSeries(buckets, rangeKey) {
|
export function rollingSeries(buckets, rangeKey) {
|
||||||
const raw = rawTimes(buckets)
|
const raw = rawTimes(buckets)
|
||||||
const times = Object.keys(raw).map(Number)
|
const times = Object.keys(raw).map(Number)
|
||||||
if (!times.length) return null
|
|
||||||
const { span, bucket, minSpan = 0 } = RANGES[rangeKey]
|
const { span, bucket, minSpan = 0 } = RANGES[rangeKey]
|
||||||
const t1 = Date.now()
|
const t1 = Date.now()
|
||||||
const earliest = Math.min(...times)
|
|
||||||
const t0 = Math.floor((span != null
|
const t0 = Math.floor((span != null
|
||||||
? t1 - span
|
? t1 - span
|
||||||
: Math.min(earliest, t1 - minSpan)) / DAY) * DAY
|
: Math.min(times.length ? Math.min(...times) : Infinity, t1 - minSpan)) / DAY) * DAY
|
||||||
|
if (!times.length) {
|
||||||
|
const bucketMs = t1 - t0 <= 31 * DAY ? Math.min(bucket, 6 * HOUR) : bucket
|
||||||
|
const points = []
|
||||||
|
for (let t = t0; t < t1; t += bucketMs) {
|
||||||
|
points.push({ t, count: 0 })
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
series: [{ points, label: '', opacity: 1, area: true }],
|
||||||
|
t0,
|
||||||
|
t1,
|
||||||
|
rate: DAY / bucketMs,
|
||||||
|
binMinutes: bucketMs / 60e3,
|
||||||
|
unitMinutes: 24 * 60,
|
||||||
|
unit: 'day',
|
||||||
|
}
|
||||||
|
}
|
||||||
// The bucket follows the actual window length, not the range key: when
|
// The bucket follows the actual window length, not the range key: when
|
||||||
// "all" is capped to its 30-day minimum it covers the very window "month"
|
// "all" is capped to its 30-day minimum it covers the very window "month"
|
||||||
// does, and daily bins would draw a different curve over the same data
|
// does, and daily bins would draw a different curve over the same data
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
* directions into straight connections (middle width = total
|
* directions into straight connections (middle width = total
|
||||||
* count; connectors flare into the node pills at both ends and wrap
|
* count; connectors flare into the node pills at both ends and wrap
|
||||||
* around their backs, surrounding them; the pills are drawn on top). Connection width grows
|
* around their backs, surrounding them; the pills are drawn on top). Connection width grows
|
||||||
* logarithmically with the count (a single count renders as a ~1 px
|
* logarithmically with the daily hit rate (base-2 log, one hit/day
|
||||||
* line, uncapped growth); connections carrying less than 1% of the total
|
* renders zero width, each doubling adds a fixed step, uncapped);
|
||||||
|
* connections carrying less than 1% of the total
|
||||||
* traffic are pruned, which naturally keeps the graph under ~100
|
* traffic are pruned, which naturally keeps the graph under ~100
|
||||||
* connections. Animated beads flow along every edge in each direction,
|
* connections. Animated beads flow along every edge in each direction,
|
||||||
* emitted at time intervals inversely proportional (linear) to the
|
* emitted at time intervals inversely proportional (linear) to the
|
||||||
@@ -122,26 +123,28 @@ const pillTangent = (s, margin = 0) => {
|
|||||||
return [(x2 - x1) / m, (y2 - y1) / m]
|
return [(x2 - x1) / m, (y2 - y1) / m]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edge width (half-width of the thin middle) grows logarithmically with
|
// Edge width: half-width = WIDTH_GROWTH * log2(daily / DAILY_REF),
|
||||||
// the count. The constants are scaled down by ~10× so busy ranges (day,
|
// where `daily` is the connection's hit rate in hits/day (callers scale
|
||||||
// year) do not overwhelm the graph with fat connectors. Connections whose
|
// raw counts by DAY / range). DAILY_REF hits/day renders zero width;
|
||||||
// thin middle would render below MIN_WMID are culled entirely: fainter
|
// WIDTH_GROWTH is the half-width added per doubling of the rate.
|
||||||
// strands are practically invisible and only their wide end flares would
|
// Connections whose thin middle would render below MIN_WMID are culled
|
||||||
// show. Connections carrying less than PRUNE_FRACTION of the total traffic
|
// entirely (fainter strands are practically invisible), as are those
|
||||||
// are likewise not drawn (this also keeps the graph under ~100 connections).
|
// carrying less than PRUNE_FRACTION of the total traffic (this also
|
||||||
const WMID_MIN = 0.2
|
// keeps the graph under ~100 connections).
|
||||||
const WIDTH_GROWTH = 0.15
|
const WIDTH_GROWTH = 1.4 // half-width px per doubling of the daily rate
|
||||||
|
const DAILY_REF = 0.8 // hits/day at which the width is zero
|
||||||
const PRUNE_FRACTION = 0.01
|
const PRUNE_FRACTION = 0.01
|
||||||
// ~0.8 px full width at natural size (1 viewBox unit = 1 px).
|
// ~0.8 px full width at natural size (1 viewBox unit = 1 px).
|
||||||
const MIN_WMID = 0.4
|
const MIN_WMID = 0.4
|
||||||
|
|
||||||
// Beads: each edge direction emits beads at count * BEAD_RATE beads per
|
// Beads: each edge direction emits beads at dailyRate * BEAD_RATE beads
|
||||||
// second (linear in the count). The rate is reduced ~10× across all time
|
// per second (linear in the daily hit rate). The rate is much reduced
|
||||||
// scales to keep the animation lightweight. The component simulates every
|
// from real time to keep the animation lightweight. The component
|
||||||
// bead independently in JS with a constant traversal time per edge (speed
|
// simulates every bead independently in JS with a constant traversal
|
||||||
// relative to span length), with no limit on beads in flight.
|
// time per edge (speed relative to span length), with no limit on beads
|
||||||
|
// in flight.
|
||||||
export const BEAD_R = 3.2
|
export const BEAD_R = 3.2
|
||||||
const BEAD_RATE = 0.012 // beads per second per recorded transition
|
const BEAD_RATE = 0.0084 // beads per second per hit/day
|
||||||
const FLOW_OFFSET = 3 // lane offset to the right of the travel direction
|
const FLOW_OFFSET = 3 // lane offset to the right of the travel direction
|
||||||
|
|
||||||
const MAX_EXT_IN = 8 // referer nodes in the top row
|
const MAX_EXT_IN = 8 // referer nodes in the top row
|
||||||
@@ -256,8 +259,8 @@ function sortByNav(root, navOrder) {
|
|||||||
walk(root)
|
walk(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute median reading time per article in whole minutes. */
|
/** Compute median reading time per article in seconds. */
|
||||||
function buildReadMinutes(visits) {
|
function buildReadSeconds(visits) {
|
||||||
const times = {}
|
const times = {}
|
||||||
for (const v of visits || []) {
|
for (const v of visits || []) {
|
||||||
for (const [path, sec] of Object.entries(v.read || {})) {
|
for (const [path, sec] of Object.entries(v.read || {})) {
|
||||||
@@ -266,19 +269,19 @@ function buildReadMinutes(visits) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const minutes = {}
|
const seconds = {}
|
||||||
for (const [path, arr] of Object.entries(times)) {
|
for (const [path, arr] of Object.entries(times)) {
|
||||||
arr.sort((a, b) => a - b)
|
arr.sort((a, b) => a - b)
|
||||||
const mid = Math.floor(arr.length / 2)
|
const mid = Math.floor(arr.length / 2)
|
||||||
const median =
|
const median =
|
||||||
arr.length % 2 ? arr[mid] : (arr[mid - 1] + arr[mid]) / 2
|
arr.length % 2 ? arr[mid] : (arr[mid - 1] + arr[mid]) / 2
|
||||||
minutes[path] = Math.max(1, Math.round(median / 60))
|
seconds[path] = Math.round(median)
|
||||||
}
|
}
|
||||||
return minutes
|
return seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute view counts, labels and hidden flags for each node. */
|
/** Compute view counts, labels and hidden flags for each node. */
|
||||||
function annotateNodes(nodes, viewsData, titles, readMinutes) {
|
function annotateNodes(nodes, viewsData, titles, readSeconds) {
|
||||||
const viewCount = (p) => {
|
const viewCount = (p) => {
|
||||||
let n = 0
|
let n = 0
|
||||||
for (const c of Object.values(viewsData?.[p] || {})) n += c
|
for (const c of Object.values(viewsData?.[p] || {})) n += c
|
||||||
@@ -287,7 +290,7 @@ function annotateNodes(nodes, viewsData, titles, readMinutes) {
|
|||||||
|
|
||||||
for (const n of nodes) {
|
for (const n of nodes) {
|
||||||
n.views = viewCount(n.path)
|
n.views = viewCount(n.path)
|
||||||
n.readMin = readMinutes[n.path] || 0
|
n.readSec = readSeconds[n.path] || 0
|
||||||
// Article title inside the pill (clipped at the pill border on
|
// Article title inside the pill (clipped at the pill border on
|
||||||
// render), slug as fallback for pages missing from the site tree.
|
// render), slug as fallback for pages missing from the site tree.
|
||||||
n.label = titles.get(n.path) || (n.path === '/' ? '🏠︎' : n.path.split('/').pop())
|
n.label = titles.get(n.path) || (n.path === '/' ? '🏠︎' : n.path.split('/').pop())
|
||||||
@@ -621,12 +624,12 @@ function buildRibbon(a, b, ab, ba, wMid, external = false) {
|
|||||||
* to inside the target node (beads render under the node pills, so
|
* to inside the target node (beads render under the node pills, so
|
||||||
* they emerge from and vanish beneath the nodes rather than popping in
|
* they emerge from and vanish beneath the nodes rather than popping in
|
||||||
* at the surround), plus the emission interval (seconds between beads,
|
* at the surround), plus the emission interval (seconds between beads,
|
||||||
* inverse of count * BEAD_RATE). Each segment is offset to the
|
* inverse of the daily hit rate * BEAD_RATE). Each segment is offset to the
|
||||||
* right-hand side of its travel direction, so opposing flows on the same
|
* right-hand side of its travel direction, so opposing flows on the same
|
||||||
* edge run on parallel lanes instead of colliding. The component turns
|
* edge run on parallel lanes instead of colliding. The component turns
|
||||||
* these into independently simulated beads.
|
* these into independently simulated beads.
|
||||||
*/
|
*/
|
||||||
function buildFlows(a, b, ab, ba, visualScale = 1) {
|
function buildFlows(a, b, ab, ba, dayScale = 1) {
|
||||||
const len = Math.hypot(b.x - a.x, b.y - a.y) || 1
|
const len = Math.hypot(b.x - a.x, b.y - a.y) || 1
|
||||||
const ux = (b.x - a.x) / len
|
const ux = (b.x - a.x) / len
|
||||||
const uy = (b.y - a.y) / len
|
const uy = (b.y - a.y) / len
|
||||||
@@ -649,7 +652,7 @@ function buildFlows(a, b, ab, ba, visualScale = 1) {
|
|||||||
x2: a.x + toT * ux + s * rx,
|
x2: a.x + toT * ux + s * rx,
|
||||||
y2: a.y + toT * uy + s * ry,
|
y2: a.y + toT * uy + s * ry,
|
||||||
len: span,
|
len: span,
|
||||||
interval: 1 / (count * BEAD_RATE * visualScale),
|
interval: 1 / (count * BEAD_RATE * dayScale),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const flows = []
|
const flows = []
|
||||||
@@ -661,14 +664,14 @@ function buildFlows(a, b, ab, ba, visualScale = 1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Half-width for a connection middle: logarithmic in the count, anchored
|
* Half-width for a connection middle: base-2 logarithmic in the daily
|
||||||
* at WMID_MIN, uncapped. Absolute on purpose — cool routes stay visible
|
* hit rate, zero at DAILY_REF hits/day, uncapped. Absolute on purpose —
|
||||||
* regardless of how hot the hottest connection is. Callers cull results
|
* cool routes stay visible regardless of how hot the hottest connection
|
||||||
* below MIN_WMID.
|
* is. Callers cull results below MIN_WMID.
|
||||||
*/
|
*/
|
||||||
const scaledWidth = (count) => {
|
const scaledWidth = (daily) => {
|
||||||
if (count <= 0) return 0
|
if (daily <= 0) return 0
|
||||||
return WMID_MIN + WIDTH_GROWTH * Math.log1p(count - 1)
|
return WIDTH_GROWTH * Math.log2(daily / DAILY_REF)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -676,7 +679,7 @@ const scaledWidth = (count) => {
|
|||||||
* pair. Pairs carrying less than PRUNE_FRACTION of the total internal
|
* pair. Pairs carrying less than PRUNE_FRACTION of the total internal
|
||||||
* traffic are pruned (this naturally bounds the graph to ~100 edges).
|
* traffic are pruned (this naturally bounds the graph to ~100 edges).
|
||||||
*/
|
*/
|
||||||
function buildInternalEdges(pairs, byPath, visualScale = 1) {
|
function buildInternalEdges(pairs, byPath, dayScale = 1) {
|
||||||
let total = 0
|
let total = 0
|
||||||
for (const [, [ab, ba]] of pairs) total += ab + ba
|
for (const [, [ab, ba]] of pairs) total += ab + ba
|
||||||
const minCount = total * PRUNE_FRACTION
|
const minCount = total * PRUNE_FRACTION
|
||||||
@@ -689,10 +692,10 @@ function buildInternalEdges(pairs, byPath, visualScale = 1) {
|
|||||||
const a = byPath.get(pf)
|
const a = byPath.get(pf)
|
||||||
const b = byPath.get(pt)
|
const b = byPath.get(pt)
|
||||||
if (a.hidden || b.hidden) continue // unplaced index pages are omitted
|
if (a.hidden || b.hidden) continue // unplaced index pages are omitted
|
||||||
const wMid = scaledWidth((ab + ba) * visualScale)
|
const wMid = scaledWidth((ab + ba) * dayScale)
|
||||||
if (wMid < MIN_WMID) continue
|
if (wMid < MIN_WMID) continue
|
||||||
edges.push(buildRibbon(a, b, ab, ba, wMid))
|
edges.push(buildRibbon(a, b, ab, ba, wMid))
|
||||||
flows.push(...buildFlows(a, b, ab, ba, visualScale))
|
flows.push(...buildFlows(a, b, ab, ba, dayScale))
|
||||||
}
|
}
|
||||||
return { edges, flows }
|
return { edges, flows }
|
||||||
}
|
}
|
||||||
@@ -768,7 +771,7 @@ function collectSourcePairs(visits) {
|
|||||||
* Widths and pruning use the same log scale and traffic-share rule as
|
* Widths and pruning use the same log scale and traffic-share rule as
|
||||||
* internal connections.
|
* internal connections.
|
||||||
*/
|
*/
|
||||||
function buildExternal({ sources, exits }, byPath, innerBounds, visualScale = 1) {
|
function buildExternal({ sources, exits }, byPath, innerBounds, dayScale = 1) {
|
||||||
const extNodes = []
|
const extNodes = []
|
||||||
const edges = []
|
const edges = []
|
||||||
const flows = []
|
const flows = []
|
||||||
@@ -780,7 +783,7 @@ function buildExternal({ sources, exits }, byPath, innerBounds, visualScale = 1)
|
|||||||
const liveExits = exits.filter((p) => byPath.has(p.page))
|
const liveExits = exits.filter((p) => byPath.has(p.page))
|
||||||
if (!liveSources.length && !liveExits.length) return { extNodes, edges, flows }
|
if (!liveSources.length && !liveExits.length) return { extNodes, edges, flows }
|
||||||
|
|
||||||
const width = (count) => scaledWidth(count * visualScale)
|
const width = (count) => scaledWidth(count * dayScale)
|
||||||
|
|
||||||
// Incoming: one source node per identified source, in a row centered
|
// Incoming: one source node per identified source, in a row centered
|
||||||
// above the map, with an edge to each page that source led to. A source
|
// above the map, with an edge to each page that source led to. A source
|
||||||
@@ -826,7 +829,7 @@ function buildExternal({ sources, exits }, byPath, innerBounds, visualScale = 1)
|
|||||||
const wMid = width(p.in)
|
const wMid = width(p.in)
|
||||||
if (wMid < MIN_WMID) continue
|
if (wMid < MIN_WMID) continue
|
||||||
edges.push(buildRibbon(xn, page, p.in, 0, wMid, true))
|
edges.push(buildRibbon(xn, page, p.in, 0, wMid, true))
|
||||||
flows.push(...buildFlows(xn, page, p.in, 0, visualScale))
|
flows.push(...buildFlows(xn, page, p.in, 0, dayScale))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -871,7 +874,7 @@ function buildExternal({ sources, exits }, byPath, innerBounds, visualScale = 1)
|
|||||||
const wMid = width(p.out)
|
const wMid = width(p.out)
|
||||||
if (wMid < MIN_WMID) continue
|
if (wMid < MIN_WMID) continue
|
||||||
edges.push(buildRibbon(page, xn, p.out, 0, wMid, true))
|
edges.push(buildRibbon(page, xn, p.out, 0, wMid, true))
|
||||||
flows.push(...buildFlows(page, xn, p.out, 0, visualScale))
|
flows.push(...buildFlows(page, xn, p.out, 0, dayScale))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -883,25 +886,26 @@ function buildExternal({ sources, exits }, byPath, innerBounds, visualScale = 1)
|
|||||||
* Build the transition map model.
|
* Build the transition map model.
|
||||||
* Returns { nodes, edges, flows, extNodes, arcs, bounds } or null when
|
* Returns { nodes, edges, flows, extNodes, arcs, bounds } or null when
|
||||||
* there is nothing to show. `arcs` holds the branch curves; `nodes` only
|
* there is nothing to show. `arcs` holds the branch curves; `nodes` only
|
||||||
* contains placed (visible) nodes.
|
* contains placed (visible) nodes. `dayScale` converts raw counts to a
|
||||||
|
* daily hit rate (DAY / range ms) for edge widths and bead rates.
|
||||||
*/
|
*/
|
||||||
export function buildTransitionGraph(data, pageTree, visits = [], visualScale = 1) {
|
export function buildTransitionGraph(data, pageTree, visits = [], dayScale = 1) {
|
||||||
const internal = collectInternalTransitions(data?.transitions)
|
const internal = collectInternalTransitions(data?.transitions)
|
||||||
const sources = collectSourcePairs(visits)
|
const sources = collectSourcePairs(visits)
|
||||||
const exits = collectExitPairs(data?.transitions)
|
const exits = collectExitPairs(data?.transitions)
|
||||||
const navOrder = buildNavigationOrder(pageTree)
|
const navOrder = buildNavigationOrder(pageTree)
|
||||||
const titles = buildTitleMap(pageTree)
|
const titles = buildTitleMap(pageTree)
|
||||||
const readMinutes = buildReadMinutes(visits)
|
const readSeconds = buildReadSeconds(visits)
|
||||||
|
|
||||||
if (!internal.length && !navOrder.size) return null
|
if (!internal.length && !navOrder.size) return null
|
||||||
|
|
||||||
const { nodes, byPath, root } = buildNodeTree(internal, navOrder)
|
const { nodes, byPath, root } = buildNodeTree(internal, navOrder)
|
||||||
sortByNav(root, navOrder)
|
sortByNav(root, navOrder)
|
||||||
annotateNodes(nodes, data?.views, titles, readMinutes)
|
annotateNodes(nodes, data?.views, titles, readSeconds)
|
||||||
const { arcs, arcLeft } = layoutGroups(root)
|
const { arcs, arcLeft } = layoutGroups(root)
|
||||||
const placed = nodes.filter((n) => !n.hidden)
|
const placed = nodes.filter((n) => !n.hidden)
|
||||||
const pairs = aggregatePairs(internal)
|
const pairs = aggregatePairs(internal)
|
||||||
const { edges, flows } = buildInternalEdges(pairs, byPath, visualScale)
|
const { edges, flows } = buildInternalEdges(pairs, byPath, dayScale)
|
||||||
|
|
||||||
// Tight bounding box of the placed page nodes, extended to cover the
|
// Tight bounding box of the placed page nodes, extended to cover the
|
||||||
// branch curves running left of the pills; external nodes extend it.
|
// branch curves running left of the pills; external nodes extend it.
|
||||||
@@ -920,7 +924,7 @@ export function buildTransitionGraph(data, pageTree, visits = [], visualScale =
|
|||||||
y1: Math.max(...ys) + MY,
|
y1: Math.max(...ys) + MY,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = buildExternal({ sources, exits }, byPath, bounds, visualScale)
|
const ext = buildExternal({ sources, exits }, byPath, bounds, dayScale)
|
||||||
for (const xn of ext.extNodes) {
|
for (const xn of ext.extNodes) {
|
||||||
bounds.x0 = Math.min(bounds.x0, xn.x - MX)
|
bounds.x0 = Math.min(bounds.x0, xn.x - MX)
|
||||||
bounds.y0 = Math.min(bounds.y0, xn.y - MY)
|
bounds.y0 = Math.min(bounds.y0, xn.y - MY)
|
||||||
|
|||||||
@@ -65,6 +65,11 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::selection {
|
||||||
|
background: color-mix(var(--accent) 30%, transparent);
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
/* Links never underline — including SVG link text, which the UA stylesheet
|
/* Links never underline — including SVG link text, which the UA stylesheet
|
||||||
underlines by default. */
|
underlines by default. */
|
||||||
a {
|
a {
|
||||||
@@ -73,6 +78,10 @@ a {
|
|||||||
|
|
||||||
html {
|
html {
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
|
/* No rubber-band bounce past the page ends (macOS trackpads): the banner
|
||||||
|
parallax in --pry is driven by scrollY and overscroll would let the
|
||||||
|
artwork drift beyond its designed range. */
|
||||||
|
overscroll-behavior: none;
|
||||||
/* Native-scrollbar fallback styling (JS off or before pagerite.js runs):
|
/* Native-scrollbar fallback styling (JS off or before pagerite.js runs):
|
||||||
thin, theme-muted thumb on a transparent track. With JS the scrollbars
|
thin, theme-muted thumb on a transparent track. With JS the scrollbars
|
||||||
are replaced by OverlayScrollbars (see pagerite.js) — floating,
|
are replaced by OverlayScrollbars (see pagerite.js) — floating,
|
||||||
@@ -122,7 +131,11 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
min-height: 11rem;
|
/* Height scales down proportionally on small screens: 13rem at 800px
|
||||||
|
(50rem) viewport, shrinking with the smaller of viewport width/height
|
||||||
|
(vmin) below that, floored at 8rem. */
|
||||||
|
height: clamp(8rem, 26vmin, 13rem);
|
||||||
|
box-sizing: content-box;
|
||||||
background: linear-gradient(135deg, var(--surface), var(--bg));
|
background: linear-gradient(135deg, var(--surface), var(--bg));
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
}
|
}
|
||||||
@@ -187,11 +200,17 @@ body {
|
|||||||
#brand {
|
#brand {
|
||||||
font-family: var(--font-brand);
|
font-family: var(--font-brand);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 2.4rem;
|
/* Scales down proportionally on small screens, same curve as the banner
|
||||||
|
height: 2.4rem at 800px, shrinking with vmin below that. */
|
||||||
|
font-size: clamp(1.4rem, 4.8vmin, 2.4rem);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
/* One line always: pagerite.js shrinks the font size to fit instead of
|
/* One line always: pagerite.js shrinks the font size to fit instead of
|
||||||
wrapping (the themed size is the maximum). */
|
wrapping (the themed size is the maximum). */
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
/* Shrink-wrap to the text: as a flex child of the column-direction
|
||||||
|
#banner it would otherwise stretch full-width, making the empty banner
|
||||||
|
area beside the text a link to the front page. */
|
||||||
|
align-self: flex-start;
|
||||||
margin: auto 1.25rem 0;
|
margin: auto 1.25rem 0;
|
||||||
padding-top: 1.5rem;
|
padding-top: 1.5rem;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
@@ -249,8 +268,6 @@ body {
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr) minmax(0, 78rem) minmax(0, 1fr);
|
grid-template-columns: minmax(0, 1fr) minmax(0, 78rem) minmax(0, 1fr);
|
||||||
/* The docked editor pushes the content (not the header) right. */
|
|
||||||
transition: margin-left 0.25s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Long articles (.multicol is added by pagerite.js based on content length)
|
/* Long articles (.multicol is added by pagerite.js based on content length)
|
||||||
@@ -265,10 +282,9 @@ body:has(.multicol) #content {
|
|||||||
|
|
||||||
body.editing #content {
|
body.editing #content {
|
||||||
margin-left: var(--editor-w);
|
margin-left: var(--editor-w);
|
||||||
padding-left: 1rem;
|
/* No padding/gap here: the article area starts flush at the panel's right
|
||||||
/* gap between the docked editor and the content */
|
edge so that full-bleed .wide images (anchored to that edge below) line
|
||||||
/* No overflow clipping here: .editor-host lives outside this box
|
up with it exactly. */
|
||||||
(negative left), and .wide shrink-wraps to the remaining space. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The sidebar's gutter space is needed by the editor instead. */
|
/* The sidebar's gutter space is needed by the editor instead. */
|
||||||
@@ -276,34 +292,23 @@ body.editing #sidebar {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* While editing, the window itself does not scroll: the editor panel is
|
/* While editing, the window keeps scrolling normally (the overlay
|
||||||
exactly the remaining window height, and only the article area (#main)
|
scrollbars take no layout space, so the vw-based .wide bleed stays exact
|
||||||
scrolls. Without the editor, normal full-page scroll applies. */
|
and no horizontal scrollbar appears). The editor panel is fixed to the
|
||||||
body.editing {
|
viewport's left edge; main.js sets its top each scroll frame — the
|
||||||
height: 100vh;
|
banner's bottom edge while the banner is visible, else the viewport top.
|
||||||
overflow: hidden;
|
The panel scrolls internally. */
|
||||||
}
|
|
||||||
|
|
||||||
body.editing #content {
|
|
||||||
min-height: 0;
|
|
||||||
grid-template-rows: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body.editing #main {
|
|
||||||
height: 100%;
|
|
||||||
min-height: 0;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The editor host lives inside #content: it starts below the banner and
|
|
||||||
ends above the footer. With the page scroll locked while editing, the
|
|
||||||
panel exactly fills that space — the full available window height. */
|
|
||||||
.editor-host {
|
.editor-host {
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
/* main.js: banner bottom while visible, else 0 */
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: calc(0px - var(--editor-w));
|
left: 0;
|
||||||
width: var(--editor-w);
|
width: var(--editor-w);
|
||||||
|
/* Above the sidebar, .edit-link and the banner's top-right pens
|
||||||
|
(z-index 10) while sliding in/out (the host now lives at the end of
|
||||||
|
<body>, so it needs its own stacking level). */
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-root.overlay {
|
.editor-root.overlay {
|
||||||
@@ -381,7 +386,7 @@ body.editing #main {
|
|||||||
#sidebar ul ul {
|
#sidebar ul ul {
|
||||||
gap: 0.5em;
|
gap: 0.5em;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
padding-inline-start: 1em;
|
padding-inline-start: 1.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sidebar ul ul li::before {
|
#sidebar ul ul li::before {
|
||||||
@@ -448,7 +453,7 @@ article h3 {
|
|||||||
lines align. */
|
lines align. */
|
||||||
article ul {
|
article ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding-inline-start: 1em;
|
padding-inline-start: 1.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
article ul li::before {
|
article ul li::before {
|
||||||
@@ -546,6 +551,13 @@ article dd {
|
|||||||
.multicol .colseg {
|
.multicol .colseg {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
break-after: avoid-column;
|
||||||
|
}
|
||||||
|
|
||||||
p,
|
p,
|
||||||
li {
|
li {
|
||||||
break-inside: avoid-column;
|
break-inside: avoid-column;
|
||||||
@@ -805,8 +817,6 @@ div.wide {
|
|||||||
width: 100vw;
|
width: 100vw;
|
||||||
max-width: none;
|
max-width: none;
|
||||||
margin-inline: calc(50% - 50vw);
|
margin-inline: calc(50% - 50vw);
|
||||||
/* Follow the docked editor's margin-left transition smoothly. */
|
|
||||||
transition: margin-left 0.25s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Full bleed means edge to edge — no rounded corners. */
|
/* Full bleed means edge to edge — no rounded corners. */
|
||||||
@@ -822,18 +832,18 @@ body:has(.multicol) figure:has(.wide) {
|
|||||||
margin-inline: calc(-20vw - 1.25rem) 0;
|
margin-inline: calc(-20vw - 1.25rem) 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Editing: shrink the bleed to the space right of the docked editor. */
|
/* Editing: shrink the bleed to the space right of the docked editor. The
|
||||||
|
window keeps its overlay scrollbars while editing, so — unlike a classic
|
||||||
|
scrollbar — they take no layout space and the vw math stays exact. */
|
||||||
body.editing figure:has(.wide) {
|
body.editing figure:has(.wide) {
|
||||||
width: calc(100vw - var(--editor-w));
|
width: calc(100vw - var(--editor-w));
|
||||||
margin-inline: calc(50% - (100vw - var(--editor-w)) / 2);
|
margin-inline: calc(50% - (100vw - var(--editor-w)) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Editing + multicol: the left gutter is 1/5 of the space right of the
|
/* Editing + multicol: the left gutter is 1/5 of the space right of the
|
||||||
editor, and the bleed also crosses #content's 1rem editing gap plus
|
editor, and the bleed also crosses main's 1.25rem left padding. */
|
||||||
main's 1.25rem left padding (the gutter shrink from the padding roughly
|
|
||||||
cancels the rounding): −2rem in total. */
|
|
||||||
body.editing:has(.multicol) figure:has(.wide) {
|
body.editing:has(.multicol) figure:has(.wide) {
|
||||||
margin-inline: calc((100vw - var(--editor-w)) / -5 - 2rem) 0;
|
margin-inline: calc((100vw - var(--editor-w)) / -5 - 1.25rem) 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Narrow windows with a sidebar: below 102rem the symmetric gutters can no
|
/* Narrow windows with a sidebar: below 102rem the symmetric gutters can no
|
||||||
@@ -907,6 +917,42 @@ article h2 {
|
|||||||
(explicit img widths still shrink-wrap), while .wide keeps its full
|
(explicit img widths still shrink-wrap), while .wide keeps its full
|
||||||
viewport bleed. */
|
viewport bleed. */
|
||||||
@media (max-width: 48rem) {
|
@media (max-width: 48rem) {
|
||||||
|
|
||||||
|
/* Nav type shrinks fluidly as space runs out. The nav font-size is
|
||||||
|
em-based both in base and in every theme override, so scaling the
|
||||||
|
banner's font-size (nothing else in the banner is em-sized — brand and
|
||||||
|
gaps use rem) reaches the nav through all themes with a single rule.
|
||||||
|
2.6vw crosses 1rem at ≈38.5rem, so only genuinely narrow viewports
|
||||||
|
shrink. */
|
||||||
|
#banner {
|
||||||
|
font-size: clamp(0.65rem, 2.6vw, 1rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tighter margins/padding/gaps: the 1.25rem side gutter is wasted space
|
||||||
|
on a phone. */
|
||||||
|
#brand {
|
||||||
|
margin-inline: 0.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav {
|
||||||
|
padding: 0.25rem 0.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav ul {
|
||||||
|
gap: 0.15rem 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The editor panel takes over the entire viewport: no space left for
|
||||||
|
the banner or the page content (main.js pins its top to 0 at these
|
||||||
|
widths). */
|
||||||
|
body.editing #content {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-host {
|
||||||
|
width: 100vw;
|
||||||
|
}
|
||||||
|
|
||||||
#content {
|
#content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -918,7 +964,11 @@ article h2 {
|
|||||||
max-height: none;
|
max-height: none;
|
||||||
overflow-y: visible;
|
overflow-y: visible;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
padding: 0.5rem 1rem;
|
padding: 0.4rem 0.8rem;
|
||||||
|
/* Smaller type: the horizontal link strip fits roughly a third more
|
||||||
|
items per line. The nested-list gaps below are em-based and shrink
|
||||||
|
along. */
|
||||||
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only the main level becomes a horizontal wrapping strip; submenus stay
|
/* Only the main level becomes a horizontal wrapping strip; submenus stay
|
||||||
@@ -926,7 +976,7 @@ article h2 {
|
|||||||
#sidebar>ul {
|
#sidebar>ul {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem 1.2rem;
|
gap: 0.3rem 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
figure:has(.right),
|
figure:has(.right),
|
||||||
@@ -1001,11 +1051,11 @@ footer {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Rotating-cube page transition, adapted from termotohtori.fi.
|
/* Rotating-cube page transition. */
|
||||||
FRAGILE: do not tweak; the view-transition pseudo-tree is picky. */
|
|
||||||
::view-transition {
|
::view-transition {
|
||||||
perspective: 1000px;
|
perspective: 1000px;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
|
background: color-mix(var(--bg) 50%, black 50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
::view-transition-group(root),
|
::view-transition-group(root),
|
||||||
|
|||||||
+65
-5
@@ -22,6 +22,57 @@ let host = null
|
|||||||
let app = null
|
let app = null
|
||||||
let savedTitle = null
|
let savedTitle = null
|
||||||
let visible = false
|
let visible = false
|
||||||
|
let slideAnimation = null
|
||||||
|
|
||||||
|
const SLIDE_MS = 250 // keep in sync with the panel slide in pagerite.css
|
||||||
|
|
||||||
|
// The layout switches instantly when .editing toggles — no margin/width
|
||||||
|
// transitions anywhere, so viewport resizes (and the vw-based .wide bleed)
|
||||||
|
// always stay instant. The visible slide is a compositor-only FLIP
|
||||||
|
// transform on #content, running in sync with the panel's own slide
|
||||||
|
// (editor-slide-in / .closing in pagerite.css): both move by --editor-w
|
||||||
|
// over the same duration and easing, so .wide's left edge tracks the
|
||||||
|
// panel's right edge exactly throughout.
|
||||||
|
function setEditingClass(enable) {
|
||||||
|
const content = document.getElementById('content')
|
||||||
|
const before = content.getBoundingClientRect().left
|
||||||
|
document.body.classList.toggle('editing', enable)
|
||||||
|
const delta = before - content.getBoundingClientRect().left
|
||||||
|
slideAnimation?.cancel()
|
||||||
|
if (delta) {
|
||||||
|
slideAnimation = content.animate(
|
||||||
|
{ transform: [`translateX(${delta}px)`, 'translateX(0)'] },
|
||||||
|
{ duration: SLIDE_MS, easing: 'ease' }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The panel is fixed to the viewport's left edge (pagerite.css) but tracks
|
||||||
|
// the page: its top is the banner's bottom edge while the banner is visible
|
||||||
|
// (= #content's top edge), and the viewport top once the banner has
|
||||||
|
// scrolled away. The window keeps scrolling normally while editing.
|
||||||
|
// Below 48rem the panel covers the entire viewport (pagerite.css), so its
|
||||||
|
// top stays 0 regardless of the banner.
|
||||||
|
const narrow = matchMedia('(max-width: 48rem)')
|
||||||
|
function trackPanelTop() {
|
||||||
|
const content = document.getElementById('content')
|
||||||
|
if (host && content) {
|
||||||
|
host.style.top = narrow.matches
|
||||||
|
? '0px'
|
||||||
|
: `${Math.max(0, content.getBoundingClientRect().top)}px`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startTrackingPanel() {
|
||||||
|
trackPanelTop()
|
||||||
|
addEventListener('scroll', trackPanelTop, { passive: true })
|
||||||
|
addEventListener('resize', trackPanelTop)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTrackingPanel() {
|
||||||
|
removeEventListener('scroll', trackPanelTop)
|
||||||
|
removeEventListener('resize', trackPanelTop)
|
||||||
|
}
|
||||||
|
|
||||||
export function openEditor(path, { mode = 'page' } = {}) {
|
export function openEditor(path, { mode = 'page' } = {}) {
|
||||||
if (app) {
|
if (app) {
|
||||||
@@ -36,9 +87,13 @@ export function openEditor(path, { mode = 'page' } = {}) {
|
|||||||
savedTitle = document.title
|
savedTitle = document.title
|
||||||
host = document.createElement('div')
|
host = document.createElement('div')
|
||||||
host.className = 'editor-host'
|
host.className = 'editor-host'
|
||||||
// Docked inside #content: below the banner, next to the article only.
|
// Appended to <body>, not #content: the open/close slide transforms
|
||||||
document.getElementById('content').prepend(host)
|
// #content (setEditingClass), and a transformed element becomes the
|
||||||
document.body.classList.add('editing')
|
// containing block for fixed-position descendants — the panel would be
|
||||||
|
// dragged along with the content instead of sliding on its own.
|
||||||
|
document.body.append(host)
|
||||||
|
setEditingClass(true)
|
||||||
|
startTrackingPanel()
|
||||||
// Which tab is active; pagerite.js uses this to decide whether a pen click
|
// Which tab is active; pagerite.js uses this to decide whether a pen click
|
||||||
// closes the panel or switches tabs.
|
// closes the panel or switches tabs.
|
||||||
document.body.dataset.editorMode = mode
|
document.body.dataset.editorMode = mode
|
||||||
@@ -64,7 +119,8 @@ function showEditor() {
|
|||||||
savedTitle = document.title
|
savedTitle = document.title
|
||||||
host.style.display = ''
|
host.style.display = ''
|
||||||
host.firstElementChild?.classList.remove('closing')
|
host.firstElementChild?.classList.remove('closing')
|
||||||
document.body.classList.add('editing')
|
setEditingClass(true)
|
||||||
|
startTrackingPanel()
|
||||||
visible = true
|
visible = true
|
||||||
dispatchEvent(new CustomEvent('pagerite:editor-shown'))
|
dispatchEvent(new CustomEvent('pagerite:editor-shown'))
|
||||||
}
|
}
|
||||||
@@ -72,7 +128,8 @@ function showEditor() {
|
|||||||
export function closeEditor() {
|
export function closeEditor() {
|
||||||
if (!visible) return
|
if (!visible) return
|
||||||
visible = false
|
visible = false
|
||||||
document.body.classList.remove('editing')
|
stopTrackingPanel()
|
||||||
|
setEditingClass(false)
|
||||||
// dataset.editorMode is kept while hidden: the tabs use it to tell whether
|
// dataset.editorMode is kept while hidden: the tabs use it to tell whether
|
||||||
// a pagerite:editor-shown event targets them.
|
// a pagerite:editor-shown event targets them.
|
||||||
// Slide the panel out in sync with the page shifting back, then hide it.
|
// Slide the panel out in sync with the page shifting back, then hide it.
|
||||||
@@ -80,6 +137,9 @@ export function closeEditor() {
|
|||||||
const h = host
|
const h = host
|
||||||
setTimeout(() => { h.style.display = 'none' }, 250)
|
setTimeout(() => { h.style.display = 'none' }, 250)
|
||||||
dispatchEvent(new CustomEvent('pagerite:editor-hidden'))
|
dispatchEvent(new CustomEvent('pagerite:editor-hidden'))
|
||||||
|
// The editor may have dropped the prefetch cache; warm it again for the
|
||||||
|
// now-final page so navigation stays instant.
|
||||||
|
dispatchEvent(new CustomEvent('pagerite:preload-pages'))
|
||||||
// Restore the server-rendered title for the current URL. Re-fetching makes
|
// Restore the server-rendered title for the current URL. Re-fetching makes
|
||||||
// sure a brand change in the site editor or an in-place navigation leaves
|
// sure a brand change in the site editor or an in-place navigation leaves
|
||||||
// the correct public title behind.
|
// the correct public title behind.
|
||||||
|
|||||||
+117
-64
@@ -53,6 +53,7 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
// pageshow handler below re-probes auth to refresh the pens).
|
// pageshow handler below re-probes auth to refresh the pens).
|
||||||
let ssoAvailable = false;
|
let ssoAvailable = false;
|
||||||
let isAdmin = false;
|
let isAdmin = false;
|
||||||
|
let authReady = false;
|
||||||
let editorMeta = null;
|
let editorMeta = null;
|
||||||
|
|
||||||
// Asset URLs for the on-demand bundles. Dev renders them as
|
// Asset URLs for the on-demand bundles. Dev renders them as
|
||||||
@@ -106,7 +107,19 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removePens() {
|
||||||
|
document.querySelectorAll(".editor-pens, #main article button.edit-link")
|
||||||
|
.forEach((el) => el.remove());
|
||||||
|
}
|
||||||
|
|
||||||
function renderAuthUi() {
|
function renderAuthUi() {
|
||||||
|
// Always start from a clean slate: if the auth probe is still running we
|
||||||
|
// must not show any admin UI, and if it came back negative we must drop
|
||||||
|
// pens that may have been injected while the browser cache made us look
|
||||||
|
// authenticated.
|
||||||
|
removePens();
|
||||||
|
if (!authReady) return;
|
||||||
|
|
||||||
// Editing is open for admins and, as a dev/no-proxy fallback, when no
|
// Editing is open for admins and, as a dev/no-proxy fallback, when no
|
||||||
// Paskia SSO is detected at all.
|
// Paskia SSO is detected at all.
|
||||||
const canEdit = isAdmin || !ssoAvailable;
|
const canEdit = isAdmin || !ssoAvailable;
|
||||||
@@ -115,8 +128,6 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
const onAnalytics = currentPath === "/_a";
|
const onAnalytics = currentPath === "/_a";
|
||||||
const banner = document.getElementById("page-banner");
|
const banner = document.getElementById("page-banner");
|
||||||
if (banner) {
|
if (banner) {
|
||||||
const old = banner.parentElement.querySelector(".editor-pens");
|
|
||||||
if (old) old.remove();
|
|
||||||
const pens = document.createElement("div");
|
const pens = document.createElement("div");
|
||||||
pens.className = "editor-pens";
|
pens.className = "editor-pens";
|
||||||
if (canEdit && !onAnalytics) {
|
if (canEdit && !onAnalytics) {
|
||||||
@@ -137,8 +148,11 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setupAuth() {
|
async function setupAuth() {
|
||||||
|
authReady = false;
|
||||||
|
renderAuthUi();
|
||||||
|
|
||||||
const src = assets["pagerite:editor-src"];
|
const src = assets["pagerite:editor-src"];
|
||||||
if (!src) { pingEntryOnce(); return; }
|
if (!src) { authReady = true; renderAuthUi(); pingEntryOnce(); return; }
|
||||||
editorMeta = {
|
editorMeta = {
|
||||||
src,
|
src,
|
||||||
css: assets["pagerite:editor-css"],
|
css: assets["pagerite:editor-css"],
|
||||||
@@ -180,7 +194,9 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authReady = true;
|
||||||
renderAuthUi();
|
renderAuthUi();
|
||||||
|
placeEditPen();
|
||||||
pingEntryOnce();
|
pingEntryOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,22 +269,19 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
// created page has no pen for commitPending's handover click.
|
// created page has no pen for commitPending's handover click.
|
||||||
renderAuthUi();
|
renderAuthUi();
|
||||||
placeEditPen();
|
placeEditPen();
|
||||||
|
// Preview swaps also wipe the .colseg wrappers (the server render has
|
||||||
|
// none), which would drop the multi-column layout until a full reload;
|
||||||
|
// re-split so columns survive both live editing and closing the editor.
|
||||||
|
const main = document.getElementById("main");
|
||||||
|
if (main) applyMulticol(main);
|
||||||
});
|
});
|
||||||
|
|
||||||
function applyEffects() {
|
|
||||||
(window.requestIdleCallback || setTimeout)(preload);
|
|
||||||
const main = document.getElementById("main");
|
|
||||||
addCopyButtons(main);
|
|
||||||
// Fetch-navigation swaps #main, discarding the article pen and corner
|
|
||||||
// buttons; re-add whichever auth UI is appropriate for this session.
|
|
||||||
renderAuthUi();
|
|
||||||
placeEditPen();
|
|
||||||
fitNav();
|
|
||||||
// Multi-column layout only when there is enough text to justify it.
|
// Multi-column layout only when there is enough text to justify it.
|
||||||
// Split the body into columned segments: h1s, h2s and wide figures are
|
// Split the body into columned segments: h1s, h2s and wide figures are
|
||||||
// full-width separators and never go inside columns.
|
// full-width separators and never go inside columns.
|
||||||
|
function applyMulticol(main) {
|
||||||
const article = main.querySelector("article");
|
const article = main.querySelector("article");
|
||||||
if (article) {
|
if (!article) return;
|
||||||
const body = article.querySelector(".body");
|
const body = article.querySelector(".body");
|
||||||
article.classList.toggle(
|
article.classList.toggle(
|
||||||
"multicol",
|
"multicol",
|
||||||
@@ -302,6 +315,17 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyEffects() {
|
||||||
|
(window.requestIdleCallback || setTimeout)(preload);
|
||||||
|
const main = document.getElementById("main");
|
||||||
|
addCopyButtons(main);
|
||||||
|
// Fetch-navigation swaps #main, discarding the article pen and corner
|
||||||
|
// buttons; re-add whichever auth UI is appropriate for this session.
|
||||||
|
renderAuthUi();
|
||||||
|
placeEditPen();
|
||||||
|
fitNav();
|
||||||
|
applyMulticol(main);
|
||||||
if (reduceMotion.matches) return;
|
if (reduceMotion.matches) return;
|
||||||
for (const el of main.querySelectorAll(
|
for (const el of main.querySelectorAll(
|
||||||
"h2, h3, figure, img, pre, blockquote, table, dl, .task-list-item",
|
"h2, h3, figure, img, pre, blockquote, table, dl, .task-list-item",
|
||||||
@@ -328,6 +352,21 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
pageCache.set(new URL(ev.detail.url, location.href).pathname, ev.detail.html);
|
pageCache.set(new URL(ev.detail.url, location.href).pathname, ev.detail.html);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Editors mutate site-wide state (theme, structure, headings, banners),
|
||||||
|
// which can change the rendered HTML of every cached page. Drop the whole
|
||||||
|
// cache so stale prefetches are never served; the current page is re-fetched
|
||||||
|
// by the editor's own loadPlain and re-cached afterwards. Re-preloading is
|
||||||
|
// deferred until the editor panel closes to avoid hammering the server.
|
||||||
|
addEventListener("pagerite:drop-page-cache", () => {
|
||||||
|
pageCache.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
// When the editor panel closes, warm the cache again for the visible links
|
||||||
|
// on the (now final) page so subsequent navigation stays instant.
|
||||||
|
addEventListener("pagerite:preload-pages", () => {
|
||||||
|
preload();
|
||||||
|
});
|
||||||
|
|
||||||
function preload() {
|
function preload() {
|
||||||
const urls = new Set();
|
const urls = new Set();
|
||||||
for (const a of document.querySelectorAll(
|
for (const a of document.querySelectorAll(
|
||||||
@@ -362,55 +401,76 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
// themes for their own effects (e.g. the purple sun rising faster than
|
// themes for their own effects (e.g. the purple sun rising faster than
|
||||||
// the drift). Event-driven only: perfectly still when the page is idle.
|
// the drift). Event-driven only: perfectly still when the page is idle.
|
||||||
if (!reduceMotion.matches) {
|
if (!reduceMotion.matches) {
|
||||||
let ticking = false;
|
// rAF loop that eases the value toward the live scroll position. Reading
|
||||||
|
// scrollY every frame (rather than only on scroll events) also picks up
|
||||||
|
// the in-between positions of Chrome/macOS momentum scrolling, whose
|
||||||
|
// scroll events fire late and coarsely. The loop idles once settled.
|
||||||
|
let value = Math.min(scrollY * 0.1, 30);
|
||||||
|
let running = false;
|
||||||
const drift = () => {
|
const drift = () => {
|
||||||
ticking = false;
|
const target = Math.min(scrollY * 0.1, 30);
|
||||||
document.documentElement.style.setProperty(
|
value += (target - value) * 0.12;
|
||||||
"--pry", `${Math.min(scrollY * 0.1, 30)}px`,
|
if (Math.abs(target - value) < 0.05) {
|
||||||
);
|
value = target;
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
document.documentElement.style.setProperty("--pry", `${value}px`);
|
||||||
|
if (running) requestAnimationFrame(drift);
|
||||||
};
|
};
|
||||||
addEventListener("scroll", () => {
|
addEventListener("scroll", () => {
|
||||||
if (!ticking) {
|
if (!running) {
|
||||||
ticking = true;
|
running = true;
|
||||||
requestAnimationFrame(drift);
|
requestAnimationFrame(drift);
|
||||||
}
|
}
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Analytics pings ---------------------------------------------------
|
// --- Analytics pings ---------------------------------------------------
|
||||||
// Fire-and-forget POST /_a {fr, to, read}: on the initial page load
|
// Fire-and-forget POSTs to /_a with the fields as query parameters (a
|
||||||
// (starts the visit — the server counts nothing from the document GET
|
// beacon can carry no body, and query args show in server logs next to
|
||||||
// alone), for internal fetch-navigations, for external https exits, and
|
// the document GET they refer to): on the initial page load (starts the
|
||||||
// on window close. ``read`` is the active time (ms) spent on ``fr``.
|
// visit — the server counts nothing from the document GET alone), for
|
||||||
|
// internal fetch-navigations, for external https exits, and on window
|
||||||
|
// close. ``read`` is the active time (ms) spent on ``fr``.
|
||||||
// Reading time pauses after 1 minute of inactivity and resumes on the
|
// Reading time pauses after 1 minute of inactivity and resumes on the
|
||||||
// next mouse/touch/scroll/keyboard event.
|
// next mouse/touch/scroll/keyboard event.
|
||||||
// Excluded: back/forward (popstate never pings), everything while the
|
// Excluded: back/forward (popstate never pings), everything while the
|
||||||
// editor is open (body.editing — admin noise, not visits), and the
|
// editor is open (body.editing — admin noise, not visits), and
|
||||||
// analytics page itself (/_a), even though fetch-navigation treats it
|
// navigations TO the analytics page (/_a — admin machinery, and the
|
||||||
// like a normal article.
|
// server rejects it as a ping target anyway). Navigations AWAY from /_a
|
||||||
|
// must ping: load() already fetched the target page without the preload
|
||||||
|
// header, and without the ping that GET would flush to the crawler list.
|
||||||
// Admins (when SSO is actually in use — with no auth proxy "admin" is
|
// Admins (when SSO is actually in use — with no auth proxy "admin" is
|
||||||
// everyone's state) ping normally but with hide=1: the server then
|
// everyone's state) ping normally but with hide=1: the server then
|
||||||
// records nothing and scrubs any session the same browser accumulated
|
// records nothing and scrubs any session the same browser accumulated
|
||||||
// before logging in, so admins never show up as visits or crawlers.
|
// before logging in, so admins never show up as visits or crawlers.
|
||||||
// See docs/analytics.md.
|
// See docs/analytics.md.
|
||||||
function ping(to, fr = currentPath, read = 0) {
|
|
||||||
if (document.body.classList.contains("editing")) return;
|
// fetch wrapper: every key of ``params`` becomes a query arg on /_a
|
||||||
if ((to && to === "/_a") || fr === "/_a") return;
|
// (falsy values are omitted). Admins get hide=1. ``beacon`` uses
|
||||||
const hide = ssoAvailable && isAdmin ? 1 : 0;
|
// sendBeacon when available, for unload-time pings.
|
||||||
const body = JSON.stringify({
|
function pingFetch(params, { beacon = false } = {}) {
|
||||||
fr, to, hide,
|
const query = new URLSearchParams();
|
||||||
read: Math.max(0, Math.round(read / 1000)),
|
if (ssoAvailable && isAdmin) params = { ...params, hide: 1 };
|
||||||
});
|
for (const [key, value] of Object.entries(params)) {
|
||||||
|
if (value) query.set(key, value);
|
||||||
|
}
|
||||||
|
const url = `/_a?${query}`;
|
||||||
try {
|
try {
|
||||||
fetch("/_a", {
|
if (beacon && navigator.sendBeacon) {
|
||||||
method: "POST",
|
navigator.sendBeacon(url);
|
||||||
keepalive: true,
|
} else {
|
||||||
headers: { "content-type": "application/json" },
|
fetch(url, { method: "POST", keepalive: true });
|
||||||
body,
|
}
|
||||||
});
|
|
||||||
} catch { /* analytics must never break navigation */ }
|
} catch { /* analytics must never break navigation */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ping({ to, fr = currentPath, read = 0, beacon = false } = {}) {
|
||||||
|
if (document.body.classList.contains("editing")) return;
|
||||||
|
if (to === "/_a") return;
|
||||||
|
pingFetch({ fr, to, read: Math.round(read / 1000) }, { beacon });
|
||||||
|
}
|
||||||
|
|
||||||
// Active reading time for the current page. The clock stops after 1 minute
|
// Active reading time for the current page. The clock stops after 1 minute
|
||||||
// without activity and restarts on the next mouse/touch/scroll/keyboard
|
// without activity and restarts on the next mouse/touch/scroll/keyboard
|
||||||
// event.
|
// event.
|
||||||
@@ -454,24 +514,10 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
|
|
||||||
function sendClosePing() {
|
function sendClosePing() {
|
||||||
if (closePingedFor === currentPath) return;
|
if (closePingedFor === currentPath) return;
|
||||||
const read = Math.max(0, Math.round(takeReadTime() / 1000));
|
|
||||||
if (read <= 0) return;
|
|
||||||
const hide = ssoAvailable && isAdmin ? 1 : 0;
|
|
||||||
const body = JSON.stringify({ fr: currentPath, hide, read });
|
|
||||||
const blob = new Blob([body], { type: "application/json" });
|
|
||||||
try {
|
|
||||||
if (navigator.sendBeacon) {
|
|
||||||
navigator.sendBeacon("/_a", blob);
|
|
||||||
} else {
|
|
||||||
fetch("/_a", {
|
|
||||||
method: "POST",
|
|
||||||
keepalive: true,
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch { /* analytics must never break navigation */ }
|
|
||||||
closePingedFor = currentPath;
|
closePingedFor = currentPath;
|
||||||
|
const read = takeReadTime();
|
||||||
|
if (Math.round(read / 1000) <= 0) return;
|
||||||
|
ping({ read, beacon: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const ev of ["mousemove", "mousedown", "touchstart", "touchmove", "scroll", "keydown"]) {
|
for (const ev of ["mousemove", "mousedown", "touchstart", "touchmove", "scroll", "keydown"]) {
|
||||||
@@ -481,6 +527,10 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
|
|
||||||
// The initial page load pings too — it is what starts the visit and
|
// The initial page load pings too — it is what starts the visit and
|
||||||
// counts the entry page view (the document GET alone records nothing).
|
// counts the entry page view (the document GET alone records nothing).
|
||||||
|
// It carries only ``to``: the server attributes the entry to the referer
|
||||||
|
// it saw on the document GET (unavailable to JS once loaded), and an
|
||||||
|
// ``fr`` equal to ``to`` would log a bogus self-transition when a
|
||||||
|
// session already exists (e.g. a second tab).
|
||||||
// Sent once per load, after the auth probes so the admin gate applies;
|
// Sent once per load, after the auth probes so the admin gate applies;
|
||||||
// the pageshow re-probe must not ping again. Reloads are not visits:
|
// the pageshow re-probe must not ping again. Reloads are not visits:
|
||||||
// pinging them would double-count the view and log a self-transition.
|
// pinging them would double-count the view and log a self-transition.
|
||||||
@@ -490,7 +540,7 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
entryPinged = true;
|
entryPinged = true;
|
||||||
const nav = performance.getEntriesByType?.("navigation")[0];
|
const nav = performance.getEntriesByType?.("navigation")[0];
|
||||||
if (nav ? nav.type === "reload" : performance.navigation?.type === 1) return;
|
if (nav ? nav.type === "reload" : performance.navigation?.type === 1) return;
|
||||||
ping(currentPath);
|
ping({ to: currentPath, fr: "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Analytics page mount/unmount --------------------------------------
|
// --- Analytics page mount/unmount --------------------------------------
|
||||||
@@ -536,14 +586,17 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
// --- Fetch navigation ------------------------------------------------
|
// --- Fetch navigation ------------------------------------------------
|
||||||
async function load(url, push = true, back = false) {
|
async function load(url, push = true, back = false) {
|
||||||
// Navigating with the editor open closes it; unsaved edits are lost
|
// Navigating with the editor open closes it; unsaved edits are lost
|
||||||
// (the region swap discards the previewed changes anyway).
|
// (the region swap discards the previewed changes anyway). Cache must be
|
||||||
if (document.body.classList.contains("editing")) {
|
// bypassed for this navigation because the editor may have invalidated
|
||||||
|
// the prefetched copies of other pages.
|
||||||
|
const editing = document.body.classList.contains("editing");
|
||||||
|
if (editing) {
|
||||||
editorModule?.then((m) => m.closeEditor());
|
editorModule?.then((m) => m.closeEditor());
|
||||||
}
|
}
|
||||||
teardownAnalytics();
|
teardownAnalytics();
|
||||||
let doc;
|
let doc;
|
||||||
let finalUrl = url;
|
let finalUrl = url;
|
||||||
const cached = pageCache.get(new URL(url, location.href).pathname);
|
const cached = !editing && pageCache.get(new URL(url, location.href).pathname);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
doc = new DOMParser().parseFromString(cached, "text/html");
|
doc = new DOMParser().parseFromString(cached, "text/html");
|
||||||
} else {
|
} else {
|
||||||
@@ -688,7 +741,7 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
// different links to the same domain stay distinct in analytics.
|
// different links to the same domain stay distinct in analytics.
|
||||||
if (url.protocol === "https:") {
|
if (url.protocol === "https:") {
|
||||||
closePingedFor = currentPath;
|
closePingedFor = currentPath;
|
||||||
ping(url.href, currentPath, takeReadTime());
|
ping({ to: url.href, read: takeReadTime() });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -704,7 +757,7 @@ import "overlayscrollbars/overlayscrollbars.css";
|
|||||||
load(url).then((ok) => {
|
load(url).then((ok) => {
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
closePingedFor = null;
|
closePingedFor = null;
|
||||||
ping(url.pathname, from, takeReadTime());
|
ping({ to: url.pathname, fr: from, read: takeReadTime() });
|
||||||
resetReadTime();
|
resetReadTime();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
// Used by BannerEditor (banner design changes), SiteEditor (theme changes)
|
// Used by BannerEditor (banner design changes), SiteEditor (theme changes)
|
||||||
// and StructureEditor (tree navigation).
|
// and StructureEditor (tree navigation).
|
||||||
|
|
||||||
|
// Drop the public page runtime's in-memory prefetch cache. Editors call this
|
||||||
|
// whenever a site-wide or page change invalidates the cached HTML of other
|
||||||
|
// pages (theme, headings, structure, banner, etc.). The cache is rebuilt by
|
||||||
|
// re-preloading visible links once the editor panel closes.
|
||||||
|
export function dropPageCache() {
|
||||||
|
dispatchEvent(new CustomEvent('pagerite:drop-page-cache'))
|
||||||
|
}
|
||||||
|
|
||||||
export function runScripts(root) {
|
export function runScripts(root) {
|
||||||
// Scripts injected via innerHTML do not execute; re-create them.
|
// Scripts injected via innerHTML do not execute; re-create them.
|
||||||
if (!root) return
|
if (!root) return
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ def main() -> None:
|
|||||||
"pagerite.app:app",
|
"pagerite.app:app",
|
||||||
listen=args.listen,
|
listen=args.listen,
|
||||||
default_port=DEFAULT_PORT,
|
default_port=DEFAULT_PORT,
|
||||||
|
server_header=False,
|
||||||
**dev,
|
**dev,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+45
-20
@@ -316,6 +316,10 @@ class Store:
|
|||||||
pass # legacy schema / corrupt or unreadable file: start fresh
|
pass # legacy schema / corrupt or unreadable file: start fresh
|
||||||
#: client hash -> index of the current visit in data.visits
|
#: client hash -> index of the current visit in data.visits
|
||||||
self.sessions: dict[bytes, int] = {}
|
self.sessions: dict[bytes, int] = {}
|
||||||
|
#: visit index -> count events recorded for that visit, so
|
||||||
|
#: ``_remove_visit`` can reverse all of them — not just the ones
|
||||||
|
#: from the visit's creation. In-memory only, like ``sessions``.
|
||||||
|
self._count_log: dict[int, list[tuple]] = {}
|
||||||
#: ip -> external https origin of the latest document GET carrying
|
#: ip -> external https origin of the latest document GET carrying
|
||||||
#: one, stashed for the visit the client's initial ping starts.
|
#: one, stashed for the visit the client's initial ping starts.
|
||||||
#: Internal or absent referers never touch the table.
|
#: Internal or absent referers never touch the table.
|
||||||
@@ -403,35 +407,44 @@ class Store:
|
|||||||
del table[key]
|
del table[key]
|
||||||
|
|
||||||
def _remove_visit(self, index: int) -> None:
|
def _remove_visit(self, index: int) -> None:
|
||||||
"""Delete a visit and reverse the counts its creation recorded.
|
"""Delete a visit and reverse every count it recorded.
|
||||||
|
|
||||||
Used when a known visitor turns out to be an admin (hide=1 ping):
|
Used when a known visitor turns out to be an admin (hide=1 ping):
|
||||||
the session is scrubbed from the stats. Views/transitions logged
|
the session is scrubbed from the stats. The in-memory
|
||||||
by later pings inside the visit lack per-event timestamps and are
|
``_count_log`` tracks each site-visit/view/transition count the
|
||||||
left as-is.
|
visit produced, so the scrub reverses all of them — including the
|
||||||
|
ones logged by later pings inside the visit.
|
||||||
"""
|
"""
|
||||||
visit = self.data.visits[index]
|
for event in self._count_log.pop(index, ()):
|
||||||
bucket = _bucket(visit.start)
|
kind = event[0]
|
||||||
self._uncount(self.data.site_visits, bucket)
|
if kind == "site":
|
||||||
views = self.data.views.get(visit.entry)
|
self._uncount(self.data.site_visits, event[1])
|
||||||
|
elif kind == "view":
|
||||||
|
views = self.data.views.get(event[1])
|
||||||
if views is not None:
|
if views is not None:
|
||||||
self._uncount(views, bucket)
|
self._uncount(views, event[2])
|
||||||
if not views:
|
if not views:
|
||||||
del self.data.views[visit.entry]
|
del self.data.views[event[1]]
|
||||||
fr_map = self.data.transitions.get(visit.referer or "(direct)")
|
else: # transition
|
||||||
|
_, fr, to, bucket = event
|
||||||
|
fr_map = self.data.transitions.get(fr)
|
||||||
if fr_map is not None:
|
if fr_map is not None:
|
||||||
buckets = fr_map.get(visit.entry)
|
buckets = fr_map.get(to)
|
||||||
if buckets is not None:
|
if buckets is not None:
|
||||||
self._uncount(buckets, bucket)
|
self._uncount(buckets, bucket)
|
||||||
if not buckets:
|
if not buckets:
|
||||||
del fr_map[visit.entry]
|
del fr_map[to]
|
||||||
if not fr_map:
|
if not fr_map:
|
||||||
del self.data.transitions[visit.referer or "(direct)"]
|
del self.data.transitions[fr]
|
||||||
del self.data.visits[index]
|
del self.data.visits[index]
|
||||||
# Sessions store list indices; shift the ones past the removed visit.
|
# Sessions and count logs store list indices; shift the ones past
|
||||||
|
# the removed visit.
|
||||||
for key, i in list(self.sessions.items()):
|
for key, i in list(self.sessions.items()):
|
||||||
if i > index:
|
if i > index:
|
||||||
self.sessions[key] = i - 1
|
self.sessions[key] = i - 1
|
||||||
|
self._count_log = {
|
||||||
|
i - 1 if i > index else i: log for i, log in self._count_log.items()
|
||||||
|
}
|
||||||
|
|
||||||
def _client_ip(self, client_hash: bytes) -> str:
|
def _client_ip(self, client_hash: bytes) -> str:
|
||||||
"""Return the IP stored for ``client_hash``, or "" if missing."""
|
"""Return the IP stored for ``client_hash``, or "" if missing."""
|
||||||
@@ -590,10 +603,18 @@ class Store:
|
|||||||
)
|
)
|
||||||
visit.statuses[entry] = status
|
visit.statuses[entry] = status
|
||||||
self.data.visits.append(visit)
|
self.data.visits.append(visit)
|
||||||
self.sessions[client_hash] = len(self.data.visits) - 1
|
index = len(self.data.visits) - 1
|
||||||
self._count(self.data.site_visits, _bucket(now))
|
self.sessions[client_hash] = index
|
||||||
self._count(self.data.views.setdefault(entry, {}), _bucket(now))
|
bucket = _bucket(now)
|
||||||
self._count_transition(referer or "(direct)", entry, now)
|
fr = referer or "(direct)"
|
||||||
|
self._count(self.data.site_visits, bucket)
|
||||||
|
self._count(self.data.views.setdefault(entry, {}), bucket)
|
||||||
|
self._count_transition(fr, entry, now)
|
||||||
|
self._count_log[index] = [
|
||||||
|
("site", bucket),
|
||||||
|
("view", entry, bucket),
|
||||||
|
("transition", fr, entry, bucket),
|
||||||
|
]
|
||||||
return visit
|
return visit
|
||||||
|
|
||||||
def track_entry(
|
def track_entry(
|
||||||
@@ -763,9 +784,13 @@ class Store:
|
|||||||
else:
|
else:
|
||||||
visit = self.data.visits[index]
|
visit = self.data.visits[index]
|
||||||
now = datetime.now(UTC)
|
now = datetime.now(UTC)
|
||||||
|
bucket = _bucket(now)
|
||||||
|
log = self._count_log.setdefault(index, [])
|
||||||
if target.startswith("/"):
|
if target.startswith("/"):
|
||||||
self._count(self.data.views.setdefault(target, {}), _bucket(now))
|
self._count(self.data.views.setdefault(target, {}), bucket)
|
||||||
|
log.append(("view", target, bucket))
|
||||||
self._count_transition(fr, target, now)
|
self._count_transition(fr, target, now)
|
||||||
|
log.append(("transition", fr, target, bucket))
|
||||||
# First-seen only: repeat pages and repeated exits don't append.
|
# First-seen only: repeat pages and repeated exits don't append.
|
||||||
if visit.entry != target and target not in visit.trail:
|
if visit.entry != target and target not in visit.trail:
|
||||||
visit.trail.append(target)
|
visit.trail.append(target)
|
||||||
|
|||||||
+24
-18
@@ -31,7 +31,14 @@ from xml.sax.saxutils import escape as xml_escape
|
|||||||
|
|
||||||
import blake3
|
import blake3
|
||||||
import msgspec
|
import msgspec
|
||||||
from fastapi import FastAPI, HTTPException, Request, WebSocket, WebSocketDisconnect
|
from fastapi import (
|
||||||
|
FastAPI,
|
||||||
|
HTTPException,
|
||||||
|
Query,
|
||||||
|
Request,
|
||||||
|
WebSocket,
|
||||||
|
WebSocketDisconnect,
|
||||||
|
)
|
||||||
from fastapi.responses import RedirectResponse, Response
|
from fastapi.responses import RedirectResponse, Response
|
||||||
from fastapi_vue import Frontend
|
from fastapi_vue import Frontend
|
||||||
from kanta import Kanta
|
from kanta import Kanta
|
||||||
@@ -802,17 +809,6 @@ def _schedule_analytics_broadcast() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AnalyticsPing(BaseModel):
|
|
||||||
"""Navigation ping from pagerite.js (see docs/analytics.md)."""
|
|
||||||
|
|
||||||
fr: str = ""
|
|
||||||
to: str | None = None
|
|
||||||
#: 1 from admin clients: scrub the session instead of recording it.
|
|
||||||
hide: int = 0
|
|
||||||
#: Active reading time on ``fr`` (ms), if any.
|
|
||||||
read: int = 0
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/_a", response_model=None)
|
@app.get("/_a", response_model=None)
|
||||||
async def analytics_page(request: Request) -> Response:
|
async def analytics_page(request: Request) -> Response:
|
||||||
"""Render the analytics viewer as a normal site page at /_a.
|
"""Render the analytics viewer as a normal site page at /_a.
|
||||||
@@ -831,21 +827,31 @@ async def analytics_page(request: Request) -> Response:
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/_a", status_code=204)
|
@app.post("/_a", status_code=204)
|
||||||
async def analytics_ping(ping: AnalyticsPing, request: Request) -> None:
|
async def analytics_ping(
|
||||||
"""Record a navigation ping ({fr, to}); fire-and-forget, never fails.
|
request: Request,
|
||||||
|
fr: str = Query(""),
|
||||||
|
to: str | None = Query(None),
|
||||||
|
hide: int = Query(0),
|
||||||
|
read: int = Query(0),
|
||||||
|
) -> None:
|
||||||
|
"""Record a navigation ping (?fr=&to=&hide=&read=); fire-and-forget.
|
||||||
|
|
||||||
|
The initial page-load ping carries only ``to``: the entry is attributed
|
||||||
|
to the referer/UTM tags stashed by the document GET (see _track_entry),
|
||||||
|
which JS cannot see once the page has loaded.
|
||||||
|
|
||||||
The reverse-DNS and DB-IP geoip lookups happen in a background task so
|
The reverse-DNS and DB-IP geoip lookups happen in a background task so
|
||||||
the response is never delayed by slow DNS or the first MMDB decompress.
|
the response is never delayed by slow DNS or the first MMDB decompress.
|
||||||
"""
|
"""
|
||||||
ip = _client_ip(request)
|
ip = _client_ip(request)
|
||||||
visit_index, flushed_clients = analytics_store.ping(
|
visit_index, flushed_clients = analytics_store.ping(
|
||||||
ping.fr,
|
fr,
|
||||||
ping.to,
|
to,
|
||||||
ip,
|
ip,
|
||||||
request.headers.get("user-agent", ""),
|
request.headers.get("user-agent", ""),
|
||||||
request.headers.get("accept-language", ""),
|
request.headers.get("accept-language", ""),
|
||||||
hide=bool(ping.hide),
|
hide=bool(hide),
|
||||||
read=ping.read,
|
read=read,
|
||||||
)
|
)
|
||||||
if visit_index is not None:
|
if visit_index is not None:
|
||||||
visit = analytics_store.data.visits[visit_index]
|
visit = analytics_store.data.visits[visit_index]
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
SVG from the active palette (var(--accent)), so one SVG serves light
|
SVG from the active palette (var(--accent)), so one SVG serves light
|
||||||
and dark — and other themes too. */
|
and dark — and other themes too. */
|
||||||
|
|
||||||
#banner {
|
|
||||||
min-height: 15rem;
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Artwork colors, light mode */
|
/* Artwork colors, light mode */
|
||||||
.cb-bg0 {
|
.cb-bg0 {
|
||||||
stop-color: #ffffff;
|
stop-color: #ffffff;
|
||||||
|
|||||||
@@ -32,18 +32,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::selection {
|
|
||||||
background: var(--accent);
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Genuinely large solid brand with a soft blue shadow overlapping the
|
/* Genuinely large solid brand with a soft blue shadow overlapping the
|
||||||
artwork — conservative, but unmissable. */
|
artwork — conservative, but unmissable. */
|
||||||
#brand {
|
#brand {
|
||||||
font-size: clamp(4rem, 11vw, 8.5rem);
|
font-size: clamp(4rem, 11vw, 8.5rem);
|
||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
letter-spacing: -0.04em;
|
letter-spacing: -0.04em;
|
||||||
line-height: 1;
|
line-height: 1.1;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
color: var(--accent2);
|
color: var(--accent2);
|
||||||
filter: drop-shadow(0 0.4rem 1.4rem rgb(10 92 255 / 0.3));
|
filter: drop-shadow(0 0.4rem 1.4rem rgb(10 92 255 / 0.3));
|
||||||
@@ -140,7 +135,3 @@ pre {
|
|||||||
img {
|
img {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
::view-transition {
|
|
||||||
background: var(--bg);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/* Eyes banner design: a canvas critter watching the cursor from the
|
/* Eyes banner design: a canvas critter watching the cursor from the
|
||||||
grass (banner.html — markup + styles + script inlined by the backend
|
grass (banner.html — markup + styles + script inlined by the backend
|
||||||
into #page-banner). Fixed-height stage matching the canvas. */
|
into #page-banner). The canvas fills the banner; the scene composes
|
||||||
|
against the 13rem layout box and extends flat grass into any overflow
|
||||||
|
a theme adds below (summer's cross-fade strip). */
|
||||||
|
|
||||||
#banner {
|
/* Opt out of the base parallax (scale overscan + --pry drift): it lands on
|
||||||
height: 240px;
|
the design wrapper the backend puts around banner.html, and scaling from
|
||||||
|
the bottom edge would crop the top of the composed scene — pushing the
|
||||||
|
critter out of view — while this canvas animates on its own. */
|
||||||
|
#page-banner>[data-design="eyes"] {
|
||||||
|
transform: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,13 @@
|
|||||||
<style>
|
<style>
|
||||||
#eyes {
|
#eyes {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 240px;
|
/* 13rem — the banner's layout height, correct from the first frame,
|
||||||
|
before any external stylesheet has sized #page-banner. Themes that
|
||||||
|
extend the banner past the layout box (summer's overflow fade) raise
|
||||||
|
--eyes-h to 100% so the canvas follows the taller stage; the script
|
||||||
|
still composes the scene against the 13rem box and only extends the
|
||||||
|
meadow, so the scene itself never shifts. */
|
||||||
|
height: var(--eyes-h, 13rem);
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -10,32 +16,51 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const c = document.getElementById('eyes')
|
const c = document.getElementById('eyes')
|
||||||
const ctx = c.getContext('2d')
|
const ctx = c.getContext('2d')
|
||||||
const DPR = devicePixelRatio || 1
|
|
||||||
|
|
||||||
const fit = () => {
|
// Sync the backing store to the canvas' laid-out size. Checked every
|
||||||
const w = Math.max(1, c.clientWidth)
|
// frame: this inline script runs before the stylesheets that size
|
||||||
const h = Math.max(1, c.clientHeight)
|
// #page-banner, so observers/load events can still miss the transition.
|
||||||
c.width = Math.round(w * DPR)
|
// Assigning width/height also clears the canvas. DPR is read here, not
|
||||||
c.height = Math.round(h * DPR)
|
// captured: it changes with browser zoom.
|
||||||
|
const syncSize = () => {
|
||||||
|
const DPR = devicePixelRatio || 1
|
||||||
|
const w = Math.round(Math.max(1, c.clientWidth) * DPR)
|
||||||
|
const h = Math.round(Math.max(1, c.clientHeight) * DPR)
|
||||||
|
if (c.width !== w || c.height !== h) {
|
||||||
|
c.width = w
|
||||||
|
c.height = h
|
||||||
|
}
|
||||||
ctx.setTransform(DPR, 0, 0, DPR, 0, 0)
|
ctx.setTransform(DPR, 0, 0, DPR, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fit()
|
|
||||||
addEventListener('resize', fit)
|
|
||||||
|
|
||||||
let mx = 0
|
let mx = 0
|
||||||
let my = 0
|
let my = 0
|
||||||
let lastMove = 0
|
let lastMove = 0
|
||||||
|
|
||||||
addEventListener('mousemove', e => {
|
// Mouse and touch tracked with separate listeners (pointer events arrive
|
||||||
|
// too late on some mobile browsers). Passive listeners: a drag on the
|
||||||
|
// banner still scrolls the page — on browsers that stop delivering
|
||||||
|
// touchmove once scrolling takes over, the gaze just follows until then.
|
||||||
|
const track = (x, y) => {
|
||||||
const r = c.getBoundingClientRect()
|
const r = c.getBoundingClientRect()
|
||||||
|
|
||||||
// Convert viewport coordinates into the canvas' CSS-pixel coordinate
|
// Convert viewport coordinates into the canvas' CSS-pixel coordinate
|
||||||
// system. This remains correct with browser zoom, CSS transforms, etc.
|
// system. This remains correct with browser zoom, CSS transforms, etc.
|
||||||
mx = (e.clientX - r.left) * c.clientWidth / r.width
|
mx = (x - r.left) * c.clientWidth / r.width
|
||||||
my = (e.clientY - r.top) * c.clientHeight / r.height
|
my = (y - r.top) * c.clientHeight / r.height
|
||||||
lastMove = performance.now()
|
lastMove = performance.now()
|
||||||
})
|
}
|
||||||
|
|
||||||
|
addEventListener('mousemove', e => track(e.clientX, e.clientY))
|
||||||
|
|
||||||
|
const trackTouch = e => {
|
||||||
|
const t = e.touches[0]
|
||||||
|
|
||||||
|
if (t) track(t.clientX, t.clientY)
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListener('touchstart', trackTouch, { passive: true })
|
||||||
|
addEventListener('touchmove', trackTouch, { passive: true })
|
||||||
|
|
||||||
let gx = 0.5
|
let gx = 0.5
|
||||||
let gy = 0.5
|
let gy = 0.5
|
||||||
@@ -54,7 +79,7 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
const ridgeY = (x, w, h) =>
|
const ridgeY = (x, w, h) =>
|
||||||
h * 0.72 +
|
h * 0.83 +
|
||||||
Math.sin(x * 0.012) * 10 +
|
Math.sin(x * 0.012) * 10 +
|
||||||
Math.sin(x * 0.003 + 1.4) * 16 +
|
Math.sin(x * 0.003 + 1.4) * 16 +
|
||||||
Math.sin(x * 0.02 + 0.7) * 3
|
Math.sin(x * 0.02 + 0.7) * 3
|
||||||
@@ -114,7 +139,7 @@
|
|||||||
|
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
const x = (i + 0.5) * w / 5
|
const x = (i + 0.5) * w / 5
|
||||||
const y = h * 0.58 + Math.sin(i * 1.7) * 8
|
const y = h * 0.69 + Math.sin(i * 1.7) * 8
|
||||||
|
|
||||||
ctx.fillStyle = '#5f8d4e'
|
ctx.fillStyle = '#5f8d4e'
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
@@ -307,7 +332,10 @@
|
|||||||
ctx.moveTo(0, h)
|
ctx.moveTo(0, h)
|
||||||
ctx.lineTo(0, ridgeY(0, w, h))
|
ctx.lineTo(0, ridgeY(0, w, h))
|
||||||
|
|
||||||
for (let x = 0; x <= w; x += 8)
|
// Sample one step PAST the right edge (x <= w + 8): stopping at w would
|
||||||
|
// leave the path closing with a visible vertical drop at the edge
|
||||||
|
// whenever the width isn't a multiple of the 8px step.
|
||||||
|
for (let x = 0; x <= w + 8; x += 8)
|
||||||
ctx.lineTo(x, ridgeY(x, w, h))
|
ctx.lineTo(x, ridgeY(x, w, h))
|
||||||
|
|
||||||
ctx.lineTo(w, h)
|
ctx.lineTo(w, h)
|
||||||
@@ -319,7 +347,7 @@
|
|||||||
ctx.moveTo(0, h)
|
ctx.moveTo(0, h)
|
||||||
ctx.lineTo(0, ridgeY(0, w, h) + 10)
|
ctx.lineTo(0, ridgeY(0, w, h) + 10)
|
||||||
|
|
||||||
for (let x = 0; x <= w; x += 8)
|
for (let x = 0; x <= w + 8; x += 8)
|
||||||
ctx.lineTo(x, ridgeY(x, w, h) + 10)
|
ctx.lineTo(x, ridgeY(x, w, h) + 10)
|
||||||
|
|
||||||
ctx.lineTo(w, h)
|
ctx.lineTo(w, h)
|
||||||
@@ -362,8 +390,17 @@
|
|||||||
const dt = Math.min(now - prev, 100) / 16.7
|
const dt = Math.min(now - prev, 100) / 16.7
|
||||||
prev = now
|
prev = now
|
||||||
|
|
||||||
|
syncSize()
|
||||||
|
|
||||||
const w = c.clientWidth
|
const w = c.clientWidth
|
||||||
const h = c.clientHeight
|
// Compose the scene against the banner's layout box, not the canvas:
|
||||||
|
// a theme may extend #page-banner past #banner (e.g. summer overflows
|
||||||
|
// the artwork into the page for a masked cross-fade), and the critter
|
||||||
|
// must stay in the visible part. The overflow strip is filled with the
|
||||||
|
// flat meadow color below — a hard canvas edge would show through the
|
||||||
|
// fade, a grass extension just blends.
|
||||||
|
const h = Math.min(c.clientHeight,
|
||||||
|
c.closest('#banner')?.clientHeight || c.clientHeight)
|
||||||
const R = Math.min(h * 0.11, 38)
|
const R = Math.min(h * 0.11, 38)
|
||||||
|
|
||||||
if (now > nextMove && !hidePhase) {
|
if (now > nextMove && !hidePhase) {
|
||||||
@@ -399,6 +436,16 @@
|
|||||||
vy *= Math.pow(0.85, dt)
|
vy *= Math.pow(0.85, dt)
|
||||||
yoff += vy * dt
|
yoff += vy * dt
|
||||||
|
|
||||||
|
// Clip the scene to the composed area: the ducking critter travels
|
||||||
|
// below it, and the overflow strip is only flat meadow painted after —
|
||||||
|
// without the clip the critter would leave trails there as it sinks.
|
||||||
|
// Clipping against grass-on-grass is invisible, so the duck still
|
||||||
|
// reads as sinking into the meadow.
|
||||||
|
ctx.save()
|
||||||
|
ctx.beginPath()
|
||||||
|
ctx.rect(0, 0, w, h)
|
||||||
|
ctx.clip()
|
||||||
|
|
||||||
drawBackground(w, h)
|
drawBackground(w, h)
|
||||||
|
|
||||||
const cx0 = gx * w
|
const cx0 = gx * w
|
||||||
@@ -415,6 +462,18 @@
|
|||||||
drawCritter(cx0, eyeY, R, now, dt)
|
drawCritter(cx0, eyeY, R, now, dt)
|
||||||
drawForeground(w, h)
|
drawForeground(w, h)
|
||||||
|
|
||||||
|
ctx.restore()
|
||||||
|
|
||||||
|
// Extend the meadow into any overflow below the composed scene, with
|
||||||
|
// the same two layers drawForeground leaves at the bottom (base grass
|
||||||
|
// plus the dark under-band) so the joint is invisible.
|
||||||
|
if (c.clientHeight > h) {
|
||||||
|
ctx.fillStyle = '#69ae4b'
|
||||||
|
ctx.fillRect(0, h, w, c.clientHeight - h)
|
||||||
|
ctx.fillStyle = 'rgba(48,102,34,0.18)'
|
||||||
|
ctx.fillRect(0, h, w, c.clientHeight - h)
|
||||||
|
}
|
||||||
|
|
||||||
requestAnimationFrame(frame)
|
requestAnimationFrame(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,6 @@
|
|||||||
(inlined by the backend into #page-banner), in neutral dark greys that
|
(inlined by the backend into #page-banner), in neutral dark greys that
|
||||||
follow the page's color scheme. */
|
follow the page's color scheme. */
|
||||||
|
|
||||||
/* Bezier-swept banner with wide orange stripes (inlined SVG), separated
|
|
||||||
from the page by a straight orange blade. */
|
|
||||||
#banner {
|
|
||||||
height: 13rem;
|
|
||||||
border-bottom: 4px solid var(--accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Banner artwork dark tones: neutral greys in light mode (retinted to the
|
/* Banner artwork dark tones: neutral greys in light mode (retinted to the
|
||||||
page's violet family by the dark-scheme block below). */
|
page's violet family by the dark-scheme block below). */
|
||||||
.nb-base {
|
.nb-base {
|
||||||
@@ -44,6 +37,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
|
|
||||||
/* Banner dark tones tinted to the same violet family as the page. */
|
/* Banner dark tones tinted to the same violet family as the page. */
|
||||||
.nb-base {
|
.nb-base {
|
||||||
fill: #100d18;
|
fill: #100d18;
|
||||||
|
|||||||
@@ -63,13 +63,19 @@
|
|||||||
|
|
||||||
::selection {
|
::selection {
|
||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
color: var(--ink);
|
}
|
||||||
|
|
||||||
|
/* Any banner used is separated from page by a thick orange line */
|
||||||
|
#banner {
|
||||||
|
border-bottom: 4px solid var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Oversized outlined brand, spilling off the banner edge: orange stroke,
|
/* Oversized outlined brand, spilling off the banner edge: orange stroke,
|
||||||
solid black fill. */
|
solid black fill. */
|
||||||
#brand {
|
#brand {
|
||||||
font-size: 10rem;
|
/* Scales down proportionally below ~1000px: 10rem at a 62.5rem viewport,
|
||||||
|
shrinking with vmin (smaller of viewport width/height) below that. */
|
||||||
|
font-size: clamp(2.5rem, 16vmin, 10rem);
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
letter-spacing: 0.04em;
|
letter-spacing: 0.04em;
|
||||||
@@ -206,7 +212,3 @@ pre {
|
|||||||
img {
|
img {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
::view-transition {
|
|
||||||
background: var(--bg);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,7 +15,3 @@
|
|||||||
.banner-fade {
|
.banner-fade {
|
||||||
stop-color: var(--bg);
|
stop-color: var(--bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#banner {
|
|
||||||
min-height: 13rem;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
--font-heading: var(--font-fraunces);
|
--font-heading: var(--font-fraunces);
|
||||||
}
|
}
|
||||||
|
|
||||||
::selection {
|
|
||||||
background: var(--accent2);
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Oversized tilted brand in the sky→violet gradient. */
|
/* Oversized tilted brand in the sky→violet gradient. */
|
||||||
#brand {
|
#brand {
|
||||||
font-size: clamp(3.2rem, 9vw, 7.5rem);
|
font-size: clamp(3.2rem, 9vw, 7.5rem);
|
||||||
@@ -91,7 +86,3 @@ blockquote {
|
|||||||
pre {
|
pre {
|
||||||
--code-bg: var(--surface);
|
--code-bg: var(--surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
::view-transition {
|
|
||||||
background: #000;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* Stars banner design: a drifting starfield (banner.html — canvas + script
|
/* Stars banner design: a drifting starfield (banner.html — canvas + script
|
||||||
inlined by the backend into #page-banner). Fixed-height stage matching
|
inlined by the backend into #page-banner). The canvas takes the banner's
|
||||||
the canvas. */
|
13rem layout height directly so it never renders unclipped before the
|
||||||
|
main stylesheet loads; the starfield scales to any height. The design's
|
||||||
#banner {
|
opt-out of theme banner overflow/fade effects also lives in banner.html's
|
||||||
height: 240px;
|
inline <style>, so it applies atomically with the markup (this file would
|
||||||
}
|
load a beat later and let the overflow flash through mid-transition). */
|
||||||
|
|||||||
@@ -2,27 +2,47 @@
|
|||||||
<style>
|
<style>
|
||||||
#stars {
|
#stars {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 240px;
|
/* 13rem — the banner's layout height, not 100%: a percentage only
|
||||||
|
resolves after the main stylesheet sizes #page-banner, and until
|
||||||
|
then the canvas would render at its intrinsic height, unclipped,
|
||||||
|
over the page. (This design always opts out of theme overflows —
|
||||||
|
below — so the layout height is always the right one.) */
|
||||||
|
height: 13rem;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The night sky stays a windowed stage: undo the summer theme's banner
|
||||||
|
overflow/cross-fade — a starfield must not bleed into a daylit page.
|
||||||
|
Kept in this inlined <style> (not banner.css) so the opt-out applies
|
||||||
|
atomically with the markup; a separate stylesheet can arrive a beat
|
||||||
|
later and let the overflow flash through mid-transition. Later in
|
||||||
|
document order than theme.css, so same-specificity rules win. */
|
||||||
|
#page-banner {
|
||||||
|
inset: 0;
|
||||||
|
mask-image: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script><!--
|
<script><!--
|
||||||
(() => {
|
(() => {
|
||||||
const c = document.getElementById('stars')
|
const c = document.getElementById('stars')
|
||||||
const ctx = c.getContext('2d')
|
const ctx = c.getContext('2d')
|
||||||
const DPR = devicePixelRatio || 1
|
|
||||||
|
|
||||||
const fit = () => {
|
// Sync the backing store to the canvas' laid-out size. Checked every
|
||||||
const w = Math.max(1, c.clientWidth)
|
// frame: this inline script runs before the stylesheets that size
|
||||||
const h = Math.max(1, c.clientHeight)
|
// #page-banner, so observers/load events can still miss the transition.
|
||||||
c.width = Math.round(w * DPR)
|
// Assigning width/height also clears the canvas. DPR is read here, not
|
||||||
c.height = Math.round(h * DPR)
|
// captured: it changes with browser zoom.
|
||||||
|
const syncSize = () => {
|
||||||
|
const DPR = devicePixelRatio || 1
|
||||||
|
const w = Math.round(Math.max(1, c.clientWidth) * DPR)
|
||||||
|
const h = Math.round(Math.max(1, c.clientHeight) * DPR)
|
||||||
|
if (c.width !== w || c.height !== h) {
|
||||||
|
c.width = w
|
||||||
|
c.height = h
|
||||||
|
}
|
||||||
ctx.setTransform(DPR, 0, 0, DPR, 0, 0)
|
ctx.setTransform(DPR, 0, 0, DPR, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fit()
|
|
||||||
addEventListener('resize', fit)
|
|
||||||
|
|
||||||
const stars = Array.from({ length: 110 }, () => ({
|
const stars = Array.from({ length: 110 }, () => ({
|
||||||
x: Math.random(),
|
x: Math.random(),
|
||||||
y: Math.random(),
|
y: Math.random(),
|
||||||
@@ -33,6 +53,7 @@
|
|||||||
let prev = performance.now()
|
let prev = performance.now()
|
||||||
;(function frame(now) {
|
;(function frame(now) {
|
||||||
if (!c.isConnected) return
|
if (!c.isConnected) return
|
||||||
|
syncSize()
|
||||||
const w = c.clientWidth
|
const w = c.clientWidth
|
||||||
const h = c.clientHeight
|
const h = c.clientHeight
|
||||||
const dt = Math.min(now - prev, 100)
|
const dt = Math.min(now - prev, 100)
|
||||||
|
|||||||
@@ -2,10 +2,6 @@
|
|||||||
backend into #page-banner) — rolling hills, leafy bushes, swaying
|
backend into #page-banner) — rolling hills, leafy bushes, swaying
|
||||||
flowers, drifting clouds and a sun that rises as you scroll. */
|
flowers, drifting clouds and a sun that rises as you scroll. */
|
||||||
|
|
||||||
#banner {
|
|
||||||
min-height: 15rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The artwork fades into the page background at its bottom edge. */
|
/* The artwork fades into the page background at its bottom edge. */
|
||||||
.summer-fade {
|
.summer-fade {
|
||||||
stop-color: var(--bg);
|
stop-color: var(--bg);
|
||||||
@@ -44,9 +40,17 @@
|
|||||||
animation: summer-sun 9s ease-in-out infinite alternate;
|
animation: summer-sun 9s ease-in-out infinite alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
#page-banner .cloud-a { animation: summer-drift 56s ease-in-out infinite alternate; }
|
#page-banner .cloud-a {
|
||||||
#page-banner .cloud-b { animation: summer-drift 73s ease-in-out infinite alternate-reverse; }
|
animation: summer-drift 56s ease-in-out infinite alternate;
|
||||||
#page-banner .cloud-c { animation: summer-drift 64s ease-in-out infinite alternate; }
|
}
|
||||||
|
|
||||||
|
#page-banner .cloud-b {
|
||||||
|
animation: summer-drift 73s ease-in-out infinite alternate-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-banner .cloud-c {
|
||||||
|
animation: summer-drift 64s ease-in-out infinite alternate;
|
||||||
|
}
|
||||||
|
|
||||||
#page-banner .flower {
|
#page-banner .flower {
|
||||||
transform-box: fill-box;
|
transform-box: fill-box;
|
||||||
@@ -55,21 +59,42 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Stagger the sway so the meadow doesn't move in lockstep. */
|
/* Stagger the sway so the meadow doesn't move in lockstep. */
|
||||||
#page-banner .flower:nth-child(3n) { animation-delay: -1.7s; }
|
#page-banner .flower:nth-child(3n) {
|
||||||
#page-banner .flower:nth-child(3n + 1) { animation-delay: -3.1s; animation-duration: 6s; }
|
animation-delay: -1.7s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-banner .flower:nth-child(3n + 1) {
|
||||||
|
animation-delay: -3.1s;
|
||||||
|
animation-duration: 6s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes summer-sun {
|
@keyframes summer-sun {
|
||||||
from { opacity: 0.22; }
|
from {
|
||||||
to { opacity: 0.38; }
|
opacity: 0.22;
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
opacity: 0.38;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes summer-drift {
|
@keyframes summer-drift {
|
||||||
from { transform: translateX(-1.6%); }
|
from {
|
||||||
to { transform: translateX(1.6%); }
|
transform: translateX(-1.6%);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: translateX(1.6%);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes summer-sway {
|
@keyframes summer-sway {
|
||||||
from { transform: rotate(-2.6deg); }
|
from {
|
||||||
to { transform: rotate(2.6deg); }
|
transform: rotate(-2.6deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: rotate(2.6deg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
/* Every color is sampled (or text-darkened) from banner.svg. */
|
/* Every color is sampled (or text-darkened) from banner.svg. */
|
||||||
--bg: #e6f4cf;
|
--bg: #e6f4cf;
|
||||||
|
--sky: #d9f1ff;
|
||||||
/* pale meadow — the banner fades into this */
|
/* pale meadow — the banner fades into this */
|
||||||
--surface: #f8fbf0;
|
--surface: #f8fbf0;
|
||||||
--text: #2c4a2f;
|
--text: #2c4a2f;
|
||||||
@@ -56,15 +57,33 @@ body {
|
|||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
::selection {
|
/* No separation between banner and page: the frame loses its background,
|
||||||
background: var(--sun);
|
border and shadow, and the artwork overflows into the document below,
|
||||||
color: #3d5223;
|
masked by a transparency gradient so it cross-fades into the body's fixed
|
||||||
|
meadow gradient. A plain color match is impossible — both sides are
|
||||||
|
gradients, and the parallax drift keeps the banner side moving. */
|
||||||
|
#banner {
|
||||||
|
background: none;
|
||||||
|
border-bottom: 0;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The banner frame ties into the meadow beneath it. */
|
#page-banner {
|
||||||
#banner {
|
inset: 0 0 -6rem;
|
||||||
border-bottom-color: #4f913b30;
|
/* Paints over the page background in the overlap, but never swallows its
|
||||||
box-shadow: 0 0.3rem 1rem #4f913b22;
|
clicks. */
|
||||||
|
pointer-events: none;
|
||||||
|
mask-image: linear-gradient(180deg, #000 calc(100% - 6rem), transparent);
|
||||||
|
/* Canvas banner designs (eyes) default to the 13rem layout height; here
|
||||||
|
they must fill the taller overflow stage so their meadow extension
|
||||||
|
reaches through the fade strip. */
|
||||||
|
--eyes-h: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The mask above replaced the SVG's flat-color bottom fade (meadowFade) —
|
||||||
|
fading to a single --bg would reintroduce a seam against the gradient. */
|
||||||
|
#page-banner .summer-fade {
|
||||||
|
stop-opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cheerful oversized tilted brand in a sky→grass→flower gradient. */
|
/* Cheerful oversized tilted brand in a sky→grass→flower gradient. */
|
||||||
@@ -114,14 +133,26 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Content sits in a soft wash of sunlit meadow rather than on a white
|
/* Content sits in a soft wash of sunlit meadow rather than on a white
|
||||||
card. */
|
card. The wash lives on a pseudo-element so it can carry a vertical
|
||||||
|
mask: it fades in from transparent over the strip where the banner
|
||||||
|
artwork overflows into the page, so the two never fight — no matter
|
||||||
|
which side paints on top. */
|
||||||
main {
|
main {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
main::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
z-index: -1;
|
||||||
background: linear-gradient(90deg,
|
background: linear-gradient(90deg,
|
||||||
transparent,
|
transparent,
|
||||||
#f0f8dc80 15%,
|
#f0f8dc80 15%,
|
||||||
#f0f8dc8c 50%,
|
#f0f8dc8c 50%,
|
||||||
#f0f8dc80 85%,
|
#f0f8dc80 85%,
|
||||||
transparent);
|
transparent);
|
||||||
|
mask-image: linear-gradient(180deg, transparent, #000 6rem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The sidebar is a piece of the same meadow: glassy green with a light
|
/* The sidebar is a piece of the same meadow: glassy green with a light
|
||||||
@@ -131,6 +162,8 @@ main {
|
|||||||
border-right: 1px solid #ffffff80;
|
border-right: 1px solid #ffffff80;
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
box-shadow: 0 0.3rem 1rem #4f913b1f;
|
box-shadow: 0 0.3rem 1rem #4f913b1f;
|
||||||
|
border-radius: 1rem;
|
||||||
|
margin-inline: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sidebar a {
|
#sidebar a {
|
||||||
@@ -260,8 +293,7 @@ figcaption,
|
|||||||
background: linear-gradient(160deg, #eef7dd, #d9eec5);
|
background: linear-gradient(160deg, #eef7dd, #d9eec5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page transition exposes summer color around the rotating
|
|
||||||
snapshots. */
|
|
||||||
::view-transition {
|
::view-transition {
|
||||||
background: var(--bg);
|
/* Override to mid sky shade instead of the darker --bg we otherwise get */
|
||||||
|
background: var(--sky);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user