Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

Long Articles

The components that help a reader through a long page: a contents list, heading links, a progress bar, reading time, footnotes, a reading mode and read-aloud.

How the pieces fit

A long article needs the same few aids every time: a way to see its shape, a way to link to one part, a sense of how far there is to go, and somewhere for the asides. Each aid is a separate component. All of them work from the article's own markup, so the only thing they share is an element id and a sound heading order.

Scroll the demo. The bar at the top fills as you read the article, the contents list marks the section in view, each heading shows a link when you point at it, and the two footnotes are collected at the end.

Which component does what

ComponentGives the readerNeeds from you
<page-toc> A contents list that marks the section in view Headings that have an id
<heading-links> A link beside each heading that copies the section's address To be wrapped around the headings
<reading-progress> A bar across the top or bottom of the window that fills while reading Nothing, or the id of the article to measure
<page-stats> Reading time, word count, last-modified date The id of the article to count
<foot-note> and <foot-notes> Numbered references, a notes list with links back, a preview on hover or focus The note text, written where it applies
<reader-view> A reading mode with text-size controls and an optional paged, multi-column view To be wrapped around the article
<text-reader> The article read aloud, with the current word marked The id of the article to read

Contents and heading links

<page-toc> builds its list from the headings inside the element that scope selects (main by default) at the levels in levels (h2,h3 by default). It lists only headings that have an id, because a contents entry has to link somewhere.

<heading-links> supplies those ids. For each heading inside it that has none, it makes one from the heading text, then adds the permalink. Use the two together and you never write a heading id by hand. If you want an address to stay the same when a heading is reworded, give that heading an id yourself and both components keep it.

  • To leave a heading out of both, put data-toc-ignore on it or on an element around it.
  • The contents list updates when headings are added, removed or hidden. Call refresh() on it if you change heading text in place.
  • For a short page, orientation="horizontal" turns the list into a single scrolling row to place above the article.
  • To have a contents list that works before any script loads, write the list of links inside <page-toc> yourself. The component then adds only the tracking.

Progress and reading time

<reading-progress> with no attributes tracks the scroll of the whole document. Give it data-for with an article's id to measure that article alone, which is what you want when a page has a long header, comments or a footer. data-position="bottom" moves the bar to the bottom edge. The bar is decoration and is hidden from assistive technology, which already knows the scroll position.

<page-stats> counts the words in the element named by data-for and divides by 238 words a minute, or the rate in data-wpm. Chinese and Japanese text is timed by characters. Choose what to show with data-show: any of reading-time, word-count and last-modified. The date is the page's last-modified tag (see Page Metadata), never the file date the server reports.

Mark anything that should not count, such as a related-links block inside the article, with data-stats-ignore.

If your build already knows the numbers, write the list inside <page-stats> and leave off data-for. The component keeps your markup as it is. The <page-stats> page shows the markup.

Footnotes

Write each note inline, at the point it refers to, in a <foot-note>. Put one <foot-notes> after the text. The component replaces each note with a numbered reference and moves the note text into a list, with a link back from each note. Before the script runs, and if it never does, the note reads in place in parentheses.

A second <foot-note> with data-ref cites an earlier note again without repeating its text. data-mode="sidenotes" on <foot-notes> places each note in the margin beside its reference, which suits a wide page with few notes.

Other ways to read

Two components change how the article is taken in. Both are optional and both leave the article markup alone.

<reader-view> wraps the article and adds a bar with text-size buttons and a switch between two modes. scroll is the article as usual. pages covers the window and lays the text out in columns that turn like pages, with Escape to leave. Text size and column count are remembered per page in the reader's browser.

<text-reader> reads the element named by for aloud, using the speech voices built into the browser, and marks each word as it is spoken. It reads paragraphs and list items by default. Set selectors to include headings or other elements. variant="icon" gives a single button that fits a toolbar. Where the browser has no speech support the component hides itself.

For a link that returns to the top, add data-back-to-top to an anchor. It stays hidden until the reader has scrolled about one screen down.

↑