@luhtech/site-template 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -144,6 +144,35 @@ venture's own marketing site instead of only dash.luh.tech's bare preview:
144
144
  heading-level chunk, so there is nothing real to link to below
145
145
  section-level today.
146
146
 
147
+ ## Sticky side-nav and back-navigation (0.5.0)
148
+
149
+ Real long-form/multi-section pages (Platform, Open, About-style pages -- not
150
+ splash/hero landing pages, which have nothing worth jumping to) get the same
151
+ sticky-TOC-plus-scrollspy treatment the rest of the industry has converged on
152
+ (Docusaurus, Mintlify, Nextra, VitePress, Astro Starlight all ship a variant
153
+ of this exact pattern; Stripe's own docs use the sibling breadcrumb
154
+ convention for the same reason -- orient the reader inside a long page):
155
+
156
+ - `TableOfContents.astro` gained real scrollspy: an `IntersectionObserver`
157
+ (the same convention `SiteLayout`'s own `[data-reveal]` reveal-on-scroll
158
+ script already uses, not a second one) tracks which linked section is
159
+ current and stamps `aria-current` on its link. The active link gets a
160
+ persistent left accent-bar + ink color + medium weight -- not just a hover
161
+ state. A consumer wires it exactly as before (`<TableOfContents
162
+ sections={page.sections} />` inside a `sticky` aside); the scrollspy is
163
+ automatic, and degrades to a plain static jump-list if JS never runs.
164
+ - `BackLink.astro` (new): the canonical "back to X" pattern -- a real
165
+ chevron icon (inline SVG, not the `&larr;` glyph) with a hover
166
+ micro-interaction, replacing the bare `<a>&larr; X</a>` markup that had
167
+ been hand-duplicated per consumer. `<BackLink href="/insights/"
168
+ label="Insights" />`.
169
+ - Consumer guidance: only wrap a page's sections in the two-column
170
+ `grid-cols-[1fr_200px]` + sticky-aside layout when it actually has more
171
+ than one headinged section (`page.sections.filter(s => s.heading).length
172
+ > 1` -- the same condition `TableOfContents` itself gates on). Reserving
173
+ an empty 200px rail next to a single-section page is dead space, not
174
+ navigation.
175
+
147
176
  ## Migrating a venture site
148
177
 
149
178
  A migration is: author `content/site.<venture>.json` + `content/pages/*.json`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luhtech/site-template",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Shared Astro component library + content-instance contract for LuhTech venture marketing sites -- one template renders every site from content/page.schema.json + content/site.schema.json instances.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,32 @@
1
+ ---
2
+ // Canonical "back" navigation link -- replaces the bare `&larr; X` text
3
+ // anchor pattern that was hand-duplicated per-consumer (e.g. Ectropy's
4
+ // insights/[slug].astro had it inline, twice, once per content branch).
5
+ // A real chevron (inline SVG, not the &larr; glyph -- consistent stroke
6
+ // weight against the rest of the icon set, and it can carry its own hover
7
+ // motion) plus a label, matching the back-nav language convention used
8
+ // across doc/article surfaces industry-wide (a short, specific "Back to
9
+ // X", not a bare arrow with no destination named).
10
+ export interface Props {
11
+ href: string;
12
+ label: string;
13
+ class?: string;
14
+ }
15
+ const { href, label, class: className = '' } = Astro.props;
16
+ ---
17
+ <a
18
+ href={href}
19
+ class={`group inline-flex items-center gap-1.5 text-sm font-medium text-accent-primary transition-colors hover:text-ink ${className}`}
20
+ >
21
+ <svg
22
+ width="16"
23
+ height="16"
24
+ viewBox="0 0 16 16"
25
+ fill="none"
26
+ aria-hidden="true"
27
+ class="shrink-0 transition-transform duration-200 group-hover:-translate-x-0.5"
28
+ >
29
+ <path d="M10 12.5 5.5 8l4.5-4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
30
+ </svg>
31
+ <span>{label}</span>
32
+ </a>
@@ -14,6 +14,14 @@
14
14
  // multi-section content (e.g. an article split into several `article`
15
15
  // sections, each with its own heading) gets a real, useful jump-list for
16
16
  // free; a single-section page simply renders nothing here.
17
+ //
18
+ // Scrollspy (industry-standard sticky-TOC pattern, the same shape
19
+ // Docusaurus/Mintlify/Nextra/VitePress/Astro Starlight all converge on): an
20
+ // IntersectionObserver watches each linked section and marks the current
21
+ // one with aria-current, matching the site's own [data-reveal] observer
22
+ // convention in SiteLayout rather than inventing a second one. Degrades to
23
+ // a plain static jump-list with no active-state if JS never runs -- every
24
+ // link is still a real, working anchor.
17
25
  export interface Props {
18
26
  sections: Array<{ sectionId: string; heading?: string }>;
19
27
  class?: string;
@@ -22,12 +30,15 @@ const { sections, class: className = '' } = Astro.props;
22
30
  const entries = (sections ?? []).filter((s) => s.heading);
23
31
  ---
24
32
  {entries.length > 1 && (
25
- <nav class={`text-sm ${className}`} aria-label="Table of contents">
33
+ <nav class={`text-sm ${className}`} aria-label="Table of contents" data-toc>
26
34
  <p class="font-display font-semibold uppercase tracking-wide text-xs text-ink/50 mb-2">On this page</p>
27
35
  <ul class="space-y-1.5 border-l border-ink/10">
28
36
  {entries.map((s) => (
29
37
  <li>
30
- <a href={`#${s.sectionId}`} class="block pl-3 -ml-px border-l-2 border-transparent text-ink/70 hover:text-ink hover:border-accent-primary transition-colors">
38
+ <a
39
+ href={`#${s.sectionId}`}
40
+ class="block pl-3 -ml-px border-l-2 border-transparent text-ink/70 transition-colors hover:text-ink hover:border-accent-primary [&[aria-current]]:border-accent-primary [&[aria-current]]:text-ink [&[aria-current]]:font-medium"
41
+ >
31
42
  {s.heading}
32
43
  </a>
33
44
  </li>
@@ -35,3 +46,30 @@ const entries = (sections ?? []).filter((s) => s.heading);
35
46
  </ul>
36
47
  </nav>
37
48
  )}
49
+ <script>
50
+ function initScrollSpies() {
51
+ document.querySelectorAll<HTMLElement>('nav[data-toc]').forEach((nav) => {
52
+ const links = Array.from(nav.querySelectorAll<HTMLAnchorElement>('a[href^="#"]'));
53
+ const targets = links
54
+ .map((link) => ({ link, el: document.getElementById(link.getAttribute('href')!.slice(1)) }))
55
+ .filter((t): t is { link: HTMLAnchorElement; el: HTMLElement } => !!t.el);
56
+ if (!targets.length) return;
57
+
58
+ const setActive = (id: string) => {
59
+ for (const { link, el } of targets) {
60
+ link.toggleAttribute('aria-current', el.id === id);
61
+ }
62
+ };
63
+
64
+ const observer = new IntersectionObserver(
65
+ (observerEntries) => {
66
+ const visible = observerEntries.filter((e) => e.isIntersecting);
67
+ if (visible.length) setActive(visible[0].target.id);
68
+ },
69
+ { rootMargin: '-20% 0px -70% 0px', threshold: 0 }
70
+ );
71
+ targets.forEach(({ el }) => observer.observe(el));
72
+ });
73
+ }
74
+ initScrollSpies();
75
+ </script>