@marlinjai/clearify 1.6.4 → 1.6.5

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.
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-SCZZB7OE.js";
9
9
  import {
10
10
  clearifyPlugin
11
- } from "./chunk-7VYQMIW2.js";
11
+ } from "./chunk-WAWXVHUA.js";
12
12
  import {
13
13
  loadUserConfig,
14
14
  resolveConfig,
@@ -26,6 +26,16 @@ var VIRTUAL_MERMAID_SVGS = "virtual:clearify/mermaid-svgs";
26
26
  var RESOLVED_VIRTUAL_MERMAID_SVGS = "\0" + VIRTUAL_MERMAID_SVGS;
27
27
  var VIRTUAL_OPENAPI_SPEC = "virtual:clearify/openapi-spec";
28
28
  var RESOLVED_VIRTUAL_OPENAPI_SPEC = "\0" + VIRTUAL_OPENAPI_SPEC;
29
+ function findFirstNavPath(items) {
30
+ for (const item of items) {
31
+ if (item.path) return item.path;
32
+ if (item.children) {
33
+ const found = findFirstNavPath(item.children);
34
+ if (found) return found;
35
+ }
36
+ }
37
+ return void 0;
38
+ }
29
39
  function clearifyPlugin(options = {}) {
30
40
  let config;
31
41
  let userRoot;
@@ -102,20 +112,44 @@ function clearifyPlugin(options = {}) {
102
112
  }
103
113
  }
104
114
  }
115
+ for (const sectionNav of allSectionNavigations) {
116
+ const bp = sectionNav.basePath;
117
+ const hasRoute = allRoutes.some(
118
+ (r) => r.path === bp || r.path === `${bp}/*`
119
+ );
120
+ if (!hasRoute) {
121
+ const firstPath = findFirstNavPath(sectionNav.navigation);
122
+ if (firstPath) {
123
+ allRoutes.push({
124
+ path: bp,
125
+ filePath: "",
126
+ frontmatter: { title: sectionNav.label },
127
+ sectionId: sectionNav.id,
128
+ redirectTo: firstPath
129
+ });
130
+ }
131
+ }
132
+ }
105
133
  }
106
134
  function generateRoutesCode() {
107
135
  const imports = [];
108
136
  const routeEntries = [];
109
137
  allRoutes.forEach((route, i) => {
110
- const varName = `Route${i}`;
111
- if (route.componentPath) {
112
- imports.push(`const ${varName} = () => import('${route.componentPath}');`);
138
+ if (route.redirectTo) {
139
+ routeEntries.push(
140
+ ` { path: ${JSON.stringify(route.path)}, redirectTo: ${JSON.stringify(route.redirectTo)} }`
141
+ );
113
142
  } else {
114
- imports.push(`const ${varName} = () => import(/* @vite-ignore */ '${route.filePath}');`);
143
+ const varName = `Route${i}`;
144
+ if (route.componentPath) {
145
+ imports.push(`const ${varName} = () => import('${route.componentPath}');`);
146
+ } else {
147
+ imports.push(`const ${varName} = () => import(/* @vite-ignore */ '${route.filePath}');`);
148
+ }
149
+ routeEntries.push(
150
+ ` { path: ${JSON.stringify(route.path)}, component: ${varName}, frontmatter: ${JSON.stringify(route.frontmatter)} }`
151
+ );
115
152
  }
116
- routeEntries.push(
117
- ` { path: ${JSON.stringify(route.path)}, component: ${varName}, frontmatter: ${JSON.stringify(route.frontmatter)} }`
118
- );
119
153
  });
120
154
  return `${imports.join("\n")}
121
155
  export default [
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  buildSite
3
- } from "../chunk-7IXPTIHW.js";
3
+ } from "../chunk-E3KDK3VB.js";
4
4
  import "../chunk-PRTER35L.js";
5
5
  import "../chunk-SCZZB7OE.js";
6
- import "../chunk-7VYQMIW2.js";
6
+ import "../chunk-WAWXVHUA.js";
7
7
  import "../chunk-B2Q23JW3.js";
8
8
  import "../chunk-IBK35HZR.js";
9
9
  import "../chunk-V7LLYIRO.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  buildSite
3
- } from "../chunk-7IXPTIHW.js";
3
+ } from "../chunk-E3KDK3VB.js";
4
4
  import {
5
5
  remarkMermaidToComponent
6
6
  } from "../chunk-PRTER35L.js";
7
7
  import "../chunk-SCZZB7OE.js";
8
8
  import {
9
9
  clearifyPlugin
10
- } from "../chunk-7VYQMIW2.js";
10
+ } from "../chunk-WAWXVHUA.js";
11
11
  import "../chunk-B2Q23JW3.js";
12
12
  import {
13
13
  init
@@ -73,6 +73,7 @@ interface RouteEntry {
73
73
  frontmatter: PageFrontmatter;
74
74
  sectionId?: string;
75
75
  componentPath?: string;
76
+ redirectTo?: string;
76
77
  }
77
78
  declare function defineConfig(config: Partial<ClearifyConfig>): Partial<ClearifyConfig>;
78
79
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  clearifyPlugin
3
- } from "../chunk-7VYQMIW2.js";
3
+ } from "../chunk-WAWXVHUA.js";
4
4
  import "../chunk-B2Q23JW3.js";
5
5
  import "../chunk-IBK35HZR.js";
6
6
  import "../chunk-V7LLYIRO.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marlinjai/clearify",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "An open-source documentation site generator. Turn markdown into beautiful docs.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState, useRef } from 'react';
2
- import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom';
2
+ import { BrowserRouter, Routes, Route, Navigate, useLocation } from 'react-router-dom';
3
3
  import { MDXProvider } from '@mdx-js/react';
4
4
  // @ts-expect-error virtual module
5
5
  import routes from 'virtual:clearify/routes';
@@ -15,8 +15,9 @@ import '../theme/styles/globals.css';
15
15
 
16
16
  interface RouteEntry {
17
17
  path: string;
18
- component: () => Promise<any>;
19
- frontmatter: { title?: string; description?: string };
18
+ component?: () => Promise<any>;
19
+ frontmatter?: { title?: string; description?: string };
20
+ redirectTo?: string;
20
21
  }
21
22
 
22
23
  function PageWrapper({ loader, fallbackFrontmatter }: { loader: () => Promise<any>; fallbackFrontmatter: any }) {
@@ -77,13 +78,17 @@ function AppRoutes() {
77
78
  return (
78
79
  <Layout config={config} sections={sections}>
79
80
  <Routes>
80
- {(routes as RouteEntry[]).map((route) => (
81
- <Route
82
- key={route.path}
83
- path={route.path}
84
- element={<PageWrapper loader={route.component} fallbackFrontmatter={route.frontmatter} />}
85
- />
86
- ))}
81
+ {(routes as RouteEntry[]).map((route) =>
82
+ route.redirectTo ? (
83
+ <Route key={route.path} path={route.path} element={<Navigate to={route.redirectTo} replace />} />
84
+ ) : (
85
+ <Route
86
+ key={route.path}
87
+ path={route.path}
88
+ element={<PageWrapper loader={route.component!} fallbackFrontmatter={route.frontmatter} />}
89
+ />
90
+ )
91
+ )}
87
92
  <Route path="*" element={<NotFound />} />
88
93
  </Routes>
89
94
  </Layout>