blume 0.1.3 → 0.1.4

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.
@@ -46,7 +46,11 @@ const paneStyle = `height:${paneHeight}px`;
46
46
  // CodeGroup, switching one Component must not switch the others.
47
47
  <Tabs hash={false} sync={false}>
48
48
  <Tab
49
- class="flex items-center justify-center overflow-auto"
49
+ // `not-prose`: the preview lives inside the page's `.prose` wrapper, so
50
+ // without this the typography styles bleed into the live component
51
+ // (headings, links, lists, spacing). The Code pane below keeps prose on
52
+ // purpose — that's what styles the highlighted source.
53
+ class="not-prose flex items-center justify-center overflow-auto"
50
54
  style={paneStyle}
51
55
  title="Preview"
52
56
  >
@@ -16,7 +16,12 @@ import Favicon from "./Favicon.astro";
16
16
  import Fonts from "./Fonts.astro";
17
17
  import { bannerInitScript, themeInitScript } from "./head-scripts.ts";
18
18
  import Header from "./Header.astro";
19
- import { findBreadcrumbs, flattenPages, getPagination } from "./nav-utils.ts";
19
+ import {
20
+ findBreadcrumbs,
21
+ flattenPages,
22
+ getPagination,
23
+ sidebarForRoute,
24
+ } from "./nav-utils.ts";
20
25
  import NavTree from "./NavTree.astro";
21
26
  import { resolveSlot } from "./overrides.ts";
22
27
  import PageActions from "./PageActions.astro";
@@ -179,11 +184,12 @@ const formattedLastModified =
179
184
  // Needs a configured site to be useful, so the menu is hidden without one.
180
185
  const mcpUrl = mcp && siteUrl ? new URL(mcp.route, siteUrl).href : null;
181
186
 
182
- const crumbs = findBreadcrumbs(navigation.sidebar, page.route);
183
- const { prev, next } = getPagination(
184
- flattenPages(navigation.sidebar),
185
- page.route
186
- );
187
+ // Scope the sidebar (and the breadcrumbs/pagination derived from it) to the
188
+ // active tab's section, so a multi-section site drills each tab into its own
189
+ // pages. Without tabs — or on a route under none — this is the full sidebar.
190
+ const sidebar = sidebarForRoute(navigation.sidebar, navigation.tabs, page.route);
191
+ const crumbs = findBreadcrumbs(sidebar, page.route);
192
+ const { prev, next } = getPagination(flattenPages(sidebar), page.route);
187
193
 
188
194
  // Structured data is skipped when disabled or for pages we ask crawlers not to
189
195
  // index. Escape `<` so a title/description containing `</script>` can't break
@@ -294,7 +300,7 @@ const bannerScript = banner?.dismissible
294
300
  class="fixed top-16 start-0 z-[35] h-[calc(100dvh-4rem)] w-64 max-w-[80vw] -translate-x-[105%] overflow-y-auto border-border border-e bg-background px-5 pt-4 pb-6 transition-transform rtl:translate-x-[105%] [:where([data-blume-nav-open])_&]:translate-x-0! lg:sticky lg:z-auto lg:w-auto lg:max-w-none lg:translate-x-0! lg:border-e-0 lg:bg-transparent lg:px-4"
295
301
  >
296
302
  <nav>
297
- <SidebarSlot currentRoute={page.route} items={navigation.sidebar} />
303
+ <SidebarSlot currentRoute={page.route} items={sidebar} />
298
304
  </nav>
299
305
  </aside>
300
306
  <main class="min-w-0 px-6 pt-6 pb-10 lg:px-8 xl:px-10" id="blume-content">
@@ -1,4 +1,4 @@
1
- import type { NavNode } from "../../core/types.ts";
1
+ import type { NavNode, NavTab } from "../../core/types.ts";
2
2
 
3
3
  /** A flat, ordered page reference used for previous/next pagination. */
4
4
  export interface FlatPage {
@@ -71,6 +71,69 @@ export const findBreadcrumbs = (nodes: NavNode[], route: string): Crumb[] => {
71
71
  return search(nodes, []) ?? [];
72
72
  };
73
73
 
74
+ /** Whether `route` is the section root `base` or nested beneath it. */
75
+ const isUnderPath = (route: string, base: string): boolean =>
76
+ route === base || route.startsWith(`${base}/`);
77
+
78
+ /**
79
+ * The tab whose `path` is the longest prefix of `route`, mirroring the header's
80
+ * active-tab highlight. The root tab (`/`) is skipped — it spans everything and
81
+ * so never scopes the sidebar.
82
+ */
83
+ const activeTab = (tabs: NavTab[], route: string): NavTab | null => {
84
+ let match: NavTab | null = null;
85
+ for (const tab of tabs) {
86
+ if (tab.path === "/" || !isUnderPath(route, tab.path)) {
87
+ continue;
88
+ }
89
+ if (!match || tab.path.length > match.path.length) {
90
+ match = tab;
91
+ }
92
+ }
93
+ return match;
94
+ };
95
+
96
+ /**
97
+ * The children of the group whose path is `base`, searched at any depth — so a
98
+ * content tree wrapped in a top-level container group still resolves to the
99
+ * right section. Returns null when no group sits exactly at `base`.
100
+ */
101
+ const sectionChildren = (nodes: NavNode[], base: string): NavNode[] | null => {
102
+ for (const node of nodes) {
103
+ if (node.kind !== "group") {
104
+ continue;
105
+ }
106
+ if (node.path === base || node.route === base) {
107
+ return node.children;
108
+ }
109
+ const deeper = sectionChildren(node.children, base);
110
+ if (deeper) {
111
+ return deeper;
112
+ }
113
+ }
114
+ return null;
115
+ };
116
+
117
+ /**
118
+ * Scope the sidebar to the active tab's section. With tabs configured, a route
119
+ * under one tab shows only that tab's group — so a multi-section site (e.g.
120
+ * Adapters / API / AI tabs) drills each tab into its own pages instead of one
121
+ * global tree, the way Fumadocs' root folders do. Falls back to the full
122
+ * sidebar when no tab matches (or the tab maps to no group), so a route is
123
+ * never left with a blank sidebar.
124
+ */
125
+ export const sidebarForRoute = (
126
+ sidebar: NavNode[],
127
+ tabs: NavTab[],
128
+ route: string
129
+ ): NavNode[] => {
130
+ const tab = activeTab(tabs, route);
131
+ if (!tab) {
132
+ return sidebar;
133
+ }
134
+ return sectionChildren(sidebar, tab.path) ?? sidebar;
135
+ };
136
+
74
137
  /** Resolve previous/next pages around the current route. */
75
138
  export const getPagination = (
76
139
  flat: FlatPage[],
@@ -50,6 +50,15 @@ const uiStringsObject = z.object({
50
50
  untranslated: z.string().default("Not translated"),
51
51
  })
52
52
  .default({}),
53
+ notFound: z
54
+ .object({
55
+ description: z
56
+ .string()
57
+ .default("We couldn't find the page you're looking for."),
58
+ home: z.string().default("Back to home"),
59
+ title: z.string().default("Page not found"),
60
+ })
61
+ .default({}),
53
62
  page: z
54
63
  .object({
55
64
  lastUpdated: z.string().default("Last updated on"),
@@ -55,6 +55,8 @@ interface MutableGroup {
55
55
  kind: "group";
56
56
  key: string;
57
57
  path: string;
58
+ /** The group's URL path (folder route prefix); set as pages are inserted. */
59
+ routePath?: string;
58
60
  label: string;
59
61
  icon?: string;
60
62
  collapsed?: boolean;
@@ -194,6 +196,7 @@ const toNavNode = (node: MutableNode): NavNode => {
194
196
  icon: node.icon,
195
197
  kind: "group",
196
198
  label: node.label,
199
+ path: node.routePath,
197
200
  };
198
201
  };
199
202
 
@@ -215,9 +218,18 @@ const buildFileSystemSidebar = (
215
218
  const filename = parts.at(-1) ?? page.navPath;
216
219
  const dirs = parts.slice(0, -1);
217
220
 
221
+ // Each group's URL path is the matching prefix of the page's route. navPath
222
+ // is locale-stripped while the route may carry a locale/base prefix, so
223
+ // align the folder segments from the right (the extra leading segments are
224
+ // that prefix). Under such a prefix the path won't match a logical tab path,
225
+ // so tab-scoping simply no-ops — same as the header's active-tab logic.
226
+ const folderParts = page.route.split("/").filter(Boolean).slice(0, -1);
227
+ const offset = Math.max(0, folderParts.length - dirs.length);
228
+
218
229
  let parent = root;
219
- for (const dir of dirs) {
230
+ for (const [index, dir] of dirs.entries()) {
220
231
  parent = ensureGroup(parent, dir);
232
+ parent.routePath ??= `/${folderParts.slice(0, offset + index + 1).join("/")}`;
221
233
  }
222
234
 
223
235
  parent.children.push({
package/src/core/types.ts CHANGED
@@ -137,6 +137,12 @@ export type NavNode =
137
137
  display?: SidebarDisplay;
138
138
  icon?: string;
139
139
  route?: string;
140
+ /**
141
+ * The group's URL path (its folder route prefix), even when the folder
142
+ * has no index page to link. Used to scope the sidebar to a tab's section;
143
+ * not a clickable link (that's `route`).
144
+ */
145
+ path?: string;
140
146
  collapsed?: boolean;
141
147
  children: NavNode[];
142
148
  };
@@ -12,7 +12,7 @@ import {
12
12
  detectNeedsReact,
13
13
  } from "../astro/generate.ts";
14
14
  import { discoverIslands } from "../astro/islands.ts";
15
- import { customOgRoutes, discoverPages } from "../astro/pages.ts";
15
+ import { customOgRoutes, discoverPages, routeIsTaken } from "../astro/pages.ts";
16
16
  import {
17
17
  askEndpointTemplate,
18
18
  astroConfigTemplate,
@@ -25,6 +25,7 @@ import {
25
25
  islandMapTemplate,
26
26
  islandWrapperTemplate,
27
27
  mixedbreadSearchEndpointTemplate,
28
+ notFoundPageTemplate,
28
29
  ogEndpointTemplate,
29
30
  rawMarkdownEndpointTemplate,
30
31
  rssEndpointTemplate,
@@ -206,6 +207,16 @@ export const eject = async (root: string): Promise<string[]> => {
206
207
  });
207
208
  }
208
209
 
210
+ // Default 404 page, unless the project already owns `/404` (a custom
211
+ // `pages/404.astro` or a `404.md` content page). The ejected project owns the
212
+ // file afterwards and can edit or remove it.
213
+ if (!routeIsTaken(pages, project.graph.pages, "/404")) {
214
+ files.push({
215
+ content: notFoundPageTemplate(),
216
+ path: join(srcDir, "pages", "404.astro"),
217
+ });
218
+ }
219
+
209
220
  // The provider-specific client loader behind the `blume:search-client` alias.
210
221
  files.push({
211
222
  content: searchClientTemplate(config),