Skip to content

Add Reading Progress Bar plugin#7

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-reading-progress-bar
Draft

Add Reading Progress Bar plugin#7
Copilot wants to merge 4 commits intomainfrom
copilot/add-reading-progress-bar

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 14, 2026

Implements a reading progress bar plugin for Statiq blog posts, based on Jeremy Davis's approach.

New classes

  • ReadingProgressBarModuleParallelModule that processes .md documents and adds a ReadingProgressBar metadata key containing a self-contained HTML fragment (fixed-position <div>, CSS loaded from an embedded stylesheet, scroll-driven JS loaded from an embedded script file). Bar color is configurable via ProgressBarColor in appsettings.json (default: #0085A1), applied via the --rpb-color CSS custom property.
  • ReadingProgressBarConfiguratorIConfigurator<Bootstrapper> that inserts the module into the Content pipeline at position 3, mirroring ReadingTimeConfigurator.

Embedded resources

The CSS and JavaScript are maintained as separate files inside the plugin assembly:

  • ReadingProgressBar/reading-progress-bar.css — Bar styles using var(--rpb-color, #0085A1) for the configurable colour.
  • ReadingProgressBar/reading-progress-bar.js — Scroll handler using addEventListener to avoid overwriting other scroll event handlers on the page.

The module reads these at runtime via Assembly.GetManifestResourceStream() and injects the content inline, prefixed with a small :root { --rpb-color: ... } rule for the configured colour.

Template integration

Add to your post layout inside <body>:

@Html.Raw(Model.GetString("ReadingProgressBar"))

Optional configuration

"ProgressBarColor": "#0085A1"

Sample project

The sample project has been updated to demonstrate the plugin end-to-end:

  • sample/Program.cs — Explicitly registers both ReadingTimeConfigurator and ReadingProgressBarConfigurator on the bootstrapper.
  • sample/appsettings.json — Includes "ProgressBarColor": "#0085A1" to demonstrate the configurable bar colour.
  • sample/input/posts/_layout.cshtml — Renders the progress bar via @Html.Raw(Model.GetString("ReadingProgressBar")) and declares @model IDocument.
  • sample/input/posts/_ViewStart.cshtml — Corrected file casing (Linux case-sensitive filesystem) and cleaned up verbatim string prefix.
  • sample/input/posts/_ViewImports.cshtml — Added @using Statiq.Common to make IMetadata extension methods available across all Razor views in the posts directory.

The site generates successfully with the reading progress bar injected at the top of every blog post:

Original prompt

This section details on the original issue you should resolve

<issue_title>Reading Progress Bar</issue_title>
<issue_description>Adding a reading-progress bar to blog posts from @ Jeremy Davis

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: AlexHedley <1573469+AlexHedley@users.noreply.github.com>
Copilot AI changed the title [WIP] Add reading progress bar to blog posts Add Reading Progress Bar plugin Mar 14, 2026
Copilot AI requested a review from AlexHedley March 14, 2026 09:34
@AlexHedley
Copy link
Copy Markdown
Owner

@copilot update the site project in the sample folder to use the plugin and confirm the it is working

Copy link
Copy Markdown
Author

Copilot AI commented Apr 17, 2026

@copilot update the site project in the sample folder to use the plugin and confirm the it is working

Done in commit ecce0af. The sample project now explicitly registers both plugins in Program.cs:

return await Bootstrapper
  .Factory
  .CreateWeb(args)
  .AddConfigurator(new ReadingTimeConfigurator())
  .AddConfigurator(new ReadingProgressBarConfigurator())
  .RunAsync();

ProgressBarColor was also added to appsettings.json. Several sample Razor issues were fixed along the way (_ViewStart.cshtml casing, _ViewImports.cshtml for @using Statiq.Common, @model IDocument in the layout). The site generates cleanly with the progress bar injected at the top of every post:

Reading Progress Bar

The teal bar is visible at the top of the page and grows from 0% → 100% as the reader scrolls through the post.

@AlexHedley
Copy link
Copy Markdown
Owner

@copilot extract the style into a css file and the JavaScript into a script file

Copy link
Copy Markdown
Author

Copilot AI commented Apr 18, 2026

@copilot extract the style into a css file and the JavaScript into a script file

Done in commit eee4eba. The CSS and JS are now in separate embedded resource files:

  • reading-progress-bar.css — bar styles, with var(--rpb-color, #0085A1) for the configurable colour
  • reading-progress-bar.js — scroll handler using addEventListener (avoids overwriting other scroll handlers)

The module reads them at build time via Assembly.GetManifestResourceStream() and injects a small :root { --rpb-color: ... } block alongside the loaded CSS for the configurable colour. The generated HTML in a post now looks like:

<div id="reading-progress-bar"></div>
<style>:root { --rpb-color: #0085A1; }
#reading-progress-bar {
    position: fixed;
    ...
    background-color: var(--rpb-color, #0085A1);
}
</style>
<script>
window.addEventListener('scroll', function() {
    ...
});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading Progress Bar

2 participants