DEV Community

Jason Guo
Jason Guo

Posted on

Building a Zero-Account Chapter Reader with localStorage Resume in Astro

Static sites are ideal for long-form public-domain literature: every chapter gets a permanent, cacheable URL, fast TTFB, and clean typography. The downside of static chapter pages is reader continuity — once someone closes their tab on Chapter 19 of a 61-chapter novel, they rarely remember which chapter they were on next week.

While upgrading the free Jane Austen online reading library (311 chapters across seven works, built with Astro and Pagefind), I added a lightweight, zero-account reading-progress and chapter-jump layer in under 80 lines of vanilla TypeScript.

1. Storing per-novel and site-wide progress in localStorage

Each static chapter page emits minimal data-* attributes on its <article> element:

<article
  data-reading-page
  data-novel-id="pride-and-prejudice"
  data-novel-title="Pride and Prejudice"
  data-chapter-num="12"
  data-chapter-title="Chapter 12"
  data-total-chapters="61"
  data-chapter-url="/novels/pride-and-prejudice/read/12/"
>
Enter fullscreen mode Exit fullscreen mode

On page load, a tiny inline script updates a single JSON key (austen-reading-progress) with both lastRead and a byNovel map, wrapped in try/catch so strict private-browsing modes never throw:

const state = raw ? JSON.parse(raw) : { byNovel: {} };
state.lastRead = entry;
state.byNovel[entry.novelId] = entry;
localStorage.setItem('austen-reading-progress', JSON.stringify(state));
Enter fullscreen mode Exit fullscreen mode

2. Progressive enhancement on the reading hub

On the main reading index and the Jane Austen novels directory, the server renders clean static HTML with a hidden data-continue-banner and hidden per-novel data-novel-resume chips. Returning readers see a one-click Continue reading banner and a quick novel + chapter-number jump form, while first-time visitors and crawlers see zero layout shift.

3. Contextual companion links without bloating the reading view

Instead of cluttering the prose with popups, each chapter page queries Astro's content collections at build time to render a compact footer linking to the novel's character profiles, plot summary, and Jane Austen heroines comparison — keeping the reading column calm while making cross-referencing effortless.

The whole feature ships with zero external JS libraries, preserves 100% static HTML caching, and gives readers a practical reason to come back to a static literary site.

Top comments (0)