diff --git a/CHANGELOG.md b/CHANGELOG.md index b4fd7b0..9060ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- The sidebar footer is now its own component, `BridgetownStoa::SidebarFooter`, rendered by `bridgetown-stoa/layout` in place of the inline markup. A host site can replace it by adding `src/_components/bridgetown_stoa/sidebar_footer.serb`, without copying the whole layout. +- `BridgetownStoa::Shadowable`, a mixin that makes a gem component look for its template in the host site's components directory before falling back to the gem's copy. Bridgetown normally resolves a component's template next to its Ruby class, which for a gem component is inside the gem; this mixin is what lets a site override just the `.serb`. Both `Sidebar` and `SidebarFooter` use it, so `src/_components/bridgetown_stoa/sidebar.serb` now shadows the navigation template too. + +### Changed - `script/release` accepts `--otp CODE` and forwards it to `gem push` via `GEM_HOST_OTP_CODE`, so a TOTP code can stand in for the WebAuthn browser handoff. ## [0.4.0] - 2026-09-24 diff --git a/README.md b/README.md index 4ec5917..f372f33 100644 --- a/README.md +++ b/README.md @@ -60,15 +60,40 @@ The layout is self-contained: it renders a full HTML document (doctype, `
` The document title is `{page title} | {site metadata title}` when a page sets `title:` in front matter, and just the site title otherwise. The layout also injects `asset_path :css` / `:js` so your site's esbuild bundle loads automatically. -### Overriding the layout +### Overriding parts of the layout + +The sidebar chrome is built from components that a host site can shadow one at a time, without copying the whole layout. Drop a template with the matching path into your site's `src/_components` directory and Stoa renders yours instead of its own: + +| Component | Shadow at | Renders | +| --- | --- | --- | +| `BridgetownStoa::SidebarFooter` | `src/_components/bridgetown_stoa/sidebar_footer.serb` | The attribution footer at the bottom of the sidebar | +| `BridgetownStoa::Sidebar` | `src/_components/bridgetown_stoa/sidebar.serb` | The navigation tree (the template has access to `tree` and `section_open?`) | + +For example, to add a line to the footer: + +```html + + +``` + +Only the template is replaced; the component's Ruby class still comes from the gem, so you keep any behavior it gains in later releases. Any template extension Bridgetown's components support (`.serb`, `.erb`, `.slim`, `.haml`) works. + +### Overriding the whole layout -To customize the chrome, shadow the layout in your own site: +To replace the chrome entirely, shadow the layout itself: ``` src/_layouts/bridgetown-stoa/layout.serb ``` -Bridgetown's layout resolution picks the host site's file over the gem's, so you can replace the entire layout or copy ours and edit it. (More granular override points — head, nav, footer partials — will land as the theme grows.) +Bridgetown's layout resolution picks the host site's file over the gem's, so you can replace the entire layout or copy ours and edit it. Prefer shadowing a component when you only need to change one region, since a copied layout won't pick up later changes to the gem's chrome. ## Development diff --git a/components/bridgetown_stoa/shadowable.rb b/components/bridgetown_stoa/shadowable.rb new file mode 100644 index 0000000..3f60c88 --- /dev/null +++ b/components/bridgetown_stoa/shadowable.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Lets a host site override a Stoa component's template without redefining +# its Ruby class. Bridgetown normally looks for a component's template next +# to the file that defines the class, which for a gem-provided component is +# inside the gem. Extending a component with this module makes it look in the +# site's own components directory first (for example +# src/_components/bridgetown_stoa/sidebar_footer.serb) and only then fall back +# to the template shipped with the gem. +module BridgetownStoa::Shadowable + using Bridgetown::Refinements + + def component_template_path + @_tmpl_path ||= site_template_path || super + end + + private + + def site_template_path + site = Bridgetown::Current.site + return unless site + + relative_name = name.underscore + site.config.components_load_paths.reverse_each do |load_path| + supported_template_extensions.each do |ext| + candidate = File.join(load_path, "#{relative_name}.#{ext}") + return candidate if File.exist?(candidate) + end + end + + nil + end +end diff --git a/components/bridgetown_stoa/sidebar.rb b/components/bridgetown_stoa/sidebar.rb index 97b4d3e..cb8a3e2 100644 --- a/components/bridgetown_stoa/sidebar.rb +++ b/components/bridgetown_stoa/sidebar.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class BridgetownStoa::Sidebar < Bridgetown::Component + extend BridgetownStoa::Shadowable + Node = Struct.new(:title, :url, :order, :parent_title, :current, :children, keyword_init: true) def initialize(site:, current_resource:) diff --git a/components/bridgetown_stoa/sidebar_footer.rb b/components/bridgetown_stoa/sidebar_footer.rb new file mode 100644 index 0000000..41ca14f --- /dev/null +++ b/components/bridgetown_stoa/sidebar_footer.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# The attribution footer at the bottom of the sidebar. Rendered by the +# bridgetown-stoa/layout template. Shadow it in a host site at +# src/_components/bridgetown_stoa/sidebar_footer.serb to change the footer +# without copying the whole layout. +class BridgetownStoa::SidebarFooter < Bridgetown::Component + extend BridgetownStoa::Shadowable +end diff --git a/components/bridgetown_stoa/sidebar_footer.serb b/components/bridgetown_stoa/sidebar_footer.serb new file mode 100644 index 0000000..da3c173 --- /dev/null +++ b/components/bridgetown_stoa/sidebar_footer.serb @@ -0,0 +1,7 @@ + diff --git a/layouts/bridgetown-stoa/layout.serb b/layouts/bridgetown-stoa/layout.serb index 4295218..a586df8 100644 --- a/layouts/bridgetown-stoa/layout.serb +++ b/layouts/bridgetown-stoa/layout.serb @@ -20,13 +20,7 @@ {{ site.metadata.title }} {%= render BridgetownStoa::Sidebar.new(site: site, current_resource: resource) %} - + {%= render BridgetownStoa::SidebarFooter.new %}