0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Lightweight reading statistics — word count, reading time, and last-modified date. SSR-adoptable.
Overview
The <page-stats> component displays reading statistics for a target content element. It computes word count and estimated reading time, and can show the last-modified date.
It is designed for SSR adoption: if the SSG pre-renders stats at build time, the component detects existing markup and adopts it without re-rendering.
ID of the target content element to analyze. Without it the component only adopts existing markup.
data-wpm
number
238
Words per minute for reading time. The same default is used by <page-info>, so both always agree. Chinese and Japanese text is timed at 500 characters per minute instead.
data-show
comma-separated list
reading-time
Which stats to show, in this fixed order: reading-time, word-count, last-modified. Unknown tokens are ignored. last-modified reads <meta name="last-modified">, then <meta property="article:modified_time">, and is left out when neither exists.
Reading-time text. {n} is the minute value formatted with Intl.NumberFormat in the document language (5 min, 5分).
data-label-words
template
{n} words / {n} word
Word-count text. Add data-label-words-one, -two, -few, -many or -zero for languages whose Intl.PluralRules categories need different wording.
Changing any of these attributes recomputes the stats.
What is counted
Words are found with Intl.Segmenter (word granularity) in the target's language, so languages that do not put spaces between words, such as Japanese, Chinese and Thai, are counted correctly.
Counted: code blocks and the content of closed <details>, because readers can open and read both. Add data-stats-ignore to leave a block out.
Numbers, plurals and relative dates use the language of the closest [lang] ancestor (usually <html lang>). The absolute date is in the title of the <time>.
Usage
CSR — Auto-computed
Point data-for at a content element and the component computes stats on connect. The <dl> it renders is marked data-generated, so it is replaced on the next recompute.
Render stats at build time. The component adopts an existing <dl> without data-generated and does not re-render it:
HTML
<page-stats><dlclass="page-stats-list"><div><dtclass="visually-hidden">Reading time</dt><dd><timedatetime="PT5M">5 min read</time></dd></div></dl></page-stats>
Other languages
A Japanese page: words are segmented, timed by characters, and the labels are supplied with data-label-*.
Without JavaScript, pre-rendered stats are visible and useful. The <time> element with datetime is machine-readable. With JavaScript, the component computes stats dynamically from the target element.
Accessibility
Labels use class="visually-hidden" to provide screen reader context while keeping the visual display compact. The <dl> structure groups each label-value pair semantically via <div>. The middle-dot separator between items is decorative CSS content with empty alternative text, so it is not announced.