@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.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.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
6
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
7
|
-
var _excluded = ["titleMarkdown", "children"],
|
|
8
|
-
_excluded2 = ["descriptionMarkdown", "sections"];
|
|
9
1
|
import fs from 'node:fs/promises';
|
|
10
2
|
import path from 'node:path';
|
|
11
3
|
import { fileURLToPath } from 'node:url';
|
|
@@ -24,29 +16,27 @@ import { markdownToMetadata } from "../syncPageIndex/metadataToMarkdown.js";
|
|
|
24
16
|
* e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
|
|
25
17
|
*/
|
|
26
18
|
export function pathSegmentToTitle(segment) {
|
|
27
|
-
return segment.split('-').map(
|
|
28
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
29
|
-
}).join(' ');
|
|
19
|
+
return segment.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
|
30
20
|
}
|
|
31
21
|
|
|
32
22
|
/**
|
|
33
23
|
* Recursively removes titleMarkdown fields from a heading hierarchy
|
|
34
24
|
*/
|
|
35
25
|
export function stripTitleMarkdown(hierarchy) {
|
|
36
|
-
|
|
37
|
-
for (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const [key, value] of Object.entries(hierarchy)) {
|
|
28
|
+
if (typeof value === 'object' && value !== null) {
|
|
29
|
+
const {
|
|
30
|
+
titleMarkdown,
|
|
31
|
+
children,
|
|
32
|
+
...rest
|
|
33
|
+
} = value;
|
|
34
|
+
const strippedChildren = children ? stripTitleMarkdown(children) : {};
|
|
35
|
+
result[key] = {
|
|
36
|
+
...rest,
|
|
47
37
|
// Only include children if it has keys, otherwise set to undefined
|
|
48
38
|
children: Object.keys(strippedChildren).length > 0 ? strippedChildren : undefined
|
|
49
|
-
}
|
|
39
|
+
};
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
42
|
return result;
|
|
@@ -58,19 +48,19 @@ export function stripTitleMarkdown(hierarchy) {
|
|
|
58
48
|
*/
|
|
59
49
|
export function extractPrefixAndTitle(absolutePath, rootContext) {
|
|
60
50
|
// Get the relative path from the root context
|
|
61
|
-
|
|
51
|
+
const relativePath = path.relative(rootContext, absolutePath);
|
|
62
52
|
|
|
63
53
|
// Extract the directory path (remove filename)
|
|
64
|
-
|
|
54
|
+
const dirPath = path.dirname(relativePath);
|
|
65
55
|
|
|
66
56
|
// Split into segments
|
|
67
|
-
|
|
57
|
+
const allSegments = dirPath.split(path.sep);
|
|
68
58
|
|
|
69
59
|
// Filter out segments:
|
|
70
60
|
// - Remove leading 'src' and 'app' directory markers (only if they're at the start)
|
|
71
61
|
// - Remove Next.js route groups (segments in parentheses like '(public)')
|
|
72
62
|
// - Remove current directory markers ('.' and empty strings)
|
|
73
|
-
|
|
63
|
+
const segments = allSegments.filter((seg, index) => {
|
|
74
64
|
// Remove 'src' only if it's the first segment
|
|
75
65
|
if (seg === 'src' && index === 0) {
|
|
76
66
|
return false;
|
|
@@ -91,13 +81,13 @@ export function extractPrefixAndTitle(absolutePath, rootContext) {
|
|
|
91
81
|
});
|
|
92
82
|
|
|
93
83
|
// Generate prefix with leading and trailing slashes
|
|
94
|
-
|
|
84
|
+
const prefix = segments.length > 0 ? `/${segments.join('/')}/` : '/';
|
|
95
85
|
|
|
96
86
|
// Generate title from path segments
|
|
97
|
-
|
|
87
|
+
const title = segments.map(pathSegmentToTitle).join(' ');
|
|
98
88
|
return {
|
|
99
|
-
prefix
|
|
100
|
-
title
|
|
89
|
+
prefix,
|
|
90
|
+
title
|
|
101
91
|
};
|
|
102
92
|
}
|
|
103
93
|
|
|
@@ -105,7 +95,7 @@ export function extractPrefixAndTitle(absolutePath, rootContext) {
|
|
|
105
95
|
* Default loadServerPageIndex function that loads page index data from a markdown file.
|
|
106
96
|
* This function uses process.cwd() as the root context for resolving relative paths.
|
|
107
97
|
*/
|
|
108
|
-
export
|
|
98
|
+
export const loadServerPageIndex = createLoadServerPageIndex();
|
|
109
99
|
|
|
110
100
|
/**
|
|
111
101
|
* Creates a loadServerPageIndex function with custom options.
|
|
@@ -119,58 +109,49 @@ export var loadServerPageIndex = createLoadServerPageIndex();
|
|
|
119
109
|
* @param options - Configuration options for the loader
|
|
120
110
|
* @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
|
|
121
111
|
*/
|
|
122
|
-
export function createLoadServerPageIndex() {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
case 2:
|
|
143
|
-
metadata = _context.v;
|
|
144
|
-
if (metadata) {
|
|
145
|
-
_context.n = 3;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
return _context.a(2, null);
|
|
149
|
-
case 3:
|
|
150
|
-
// Add prefix and override title with the generated one from the path
|
|
151
|
-
// Strip descriptionMarkdown and titleMarkdown to reduce bundle size
|
|
152
|
-
enrichedMetadata = _extends(_extends({}, metadata), {}, {
|
|
153
|
-
prefix: prefix,
|
|
154
|
-
// Use the generated title from the path (override markdown's H1)
|
|
155
|
-
title: generatedTitle,
|
|
156
|
-
// Strip markdown AST fields from each page to reduce size
|
|
157
|
-
pages: metadata.pages.map(function (page) {
|
|
158
|
-
var descriptionMarkdown = page.descriptionMarkdown,
|
|
159
|
-
sections = page.sections,
|
|
160
|
-
pageWithoutMarkdown = _objectWithoutPropertiesLoose(page, _excluded2);
|
|
161
|
-
return _extends(_extends({}, pageWithoutMarkdown), {}, {
|
|
162
|
-
// Strip titleMarkdown from sections hierarchy
|
|
163
|
-
sections: sections ? stripTitleMarkdown(sections) : undefined
|
|
164
|
-
});
|
|
165
|
-
})
|
|
166
|
-
});
|
|
167
|
-
return _context.a(2, enrichedMetadata);
|
|
168
|
-
}
|
|
169
|
-
}, _callee);
|
|
170
|
-
}));
|
|
171
|
-
function loadPageIndex(_x) {
|
|
172
|
-
return _loadPageIndex.apply(this, arguments);
|
|
112
|
+
export function createLoadServerPageIndex(options = {}) {
|
|
113
|
+
const rootContext = options.rootContext ?? process.cwd();
|
|
114
|
+
return async function loadPageIndex(filePath) {
|
|
115
|
+
// Convert file:// URLs to proper file system paths for reading the file
|
|
116
|
+
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
117
|
+
const absolutePath = filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath;
|
|
118
|
+
|
|
119
|
+
// Extract prefix and title from the import path
|
|
120
|
+
const {
|
|
121
|
+
prefix,
|
|
122
|
+
title: generatedTitle
|
|
123
|
+
} = extractPrefixAndTitle(absolutePath, rootContext);
|
|
124
|
+
|
|
125
|
+
// Read the markdown file
|
|
126
|
+
const markdownContent = await fs.readFile(absolutePath, 'utf-8');
|
|
127
|
+
|
|
128
|
+
// Parse the markdown to extract metadata
|
|
129
|
+
const metadata = await markdownToMetadata(markdownContent);
|
|
130
|
+
if (!metadata) {
|
|
131
|
+
return null;
|
|
173
132
|
}
|
|
174
|
-
|
|
175
|
-
|
|
133
|
+
|
|
134
|
+
// Add prefix and override title with the generated one from the path
|
|
135
|
+
// Strip descriptionMarkdown and titleMarkdown to reduce bundle size
|
|
136
|
+
const enrichedMetadata = {
|
|
137
|
+
...metadata,
|
|
138
|
+
prefix,
|
|
139
|
+
// Use the generated title from the path (override markdown's H1)
|
|
140
|
+
title: generatedTitle,
|
|
141
|
+
// Strip markdown AST fields from each page to reduce size
|
|
142
|
+
pages: metadata.pages.map(page => {
|
|
143
|
+
const {
|
|
144
|
+
descriptionMarkdown,
|
|
145
|
+
sections,
|
|
146
|
+
...pageWithoutMarkdown
|
|
147
|
+
} = page;
|
|
148
|
+
return {
|
|
149
|
+
...pageWithoutMarkdown,
|
|
150
|
+
// Strip titleMarkdown from sections hierarchy
|
|
151
|
+
sections: sections ? stripTitleMarkdown(sections) : undefined
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
return enrichedMetadata;
|
|
156
|
+
};
|
|
176
157
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
1
|
import { readFile } from 'node:fs/promises';
|
|
6
2
|
import path from 'node:path';
|
|
7
3
|
import { fileURLToPath } from 'node:url';
|
|
@@ -37,7 +33,7 @@ export function createSitemapSchema() {
|
|
|
37
33
|
* This function parses the sitemap index file to find createSitemap calls and resolves
|
|
38
34
|
* the page index paths from the imports.
|
|
39
35
|
*/
|
|
40
|
-
export
|
|
36
|
+
export const loadServerSitemap = createLoadServerSitemap();
|
|
41
37
|
|
|
42
38
|
/**
|
|
43
39
|
* Creates a loadServerSitemap function with custom options.
|
|
@@ -51,120 +47,77 @@ export var loadServerSitemap = createLoadServerSitemap();
|
|
|
51
47
|
* @param options - Configuration options for the loader
|
|
52
48
|
* @returns LoadServerSitemap function that takes a file URL and returns Promise<Sitemap>
|
|
53
49
|
*/
|
|
54
|
-
export function createLoadServerSitemap() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var filePath, rootContext, loadPageIndex, source, sitemapCall, entries, results, sitemapData, errors, _iterator, _step, result, errorMessages;
|
|
60
|
-
return _regenerator().w(function (_context2) {
|
|
61
|
-
while (1) switch (_context2.n) {
|
|
62
|
-
case 0:
|
|
63
|
-
// Convert file:// URL to proper file system path for reading the file
|
|
64
|
-
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
65
|
-
filePath = url.startsWith('file://') ? fileURLToPath(url) : url; // Determine root context from file path if not provided
|
|
66
|
-
rootContext = (_options$rootContext = options.rootContext) != null ? _options$rootContext : path.dirname(filePath); // Create page index loader with root context
|
|
67
|
-
loadPageIndex = createLoadServerPageIndex({
|
|
68
|
-
rootContext: rootContext
|
|
69
|
-
}); // Read the source file to find createSitemap calls
|
|
70
|
-
_context2.n = 1;
|
|
71
|
-
return readFile(filePath, 'utf-8');
|
|
72
|
-
case 1:
|
|
73
|
-
source = _context2.v;
|
|
74
|
-
_context2.n = 2;
|
|
75
|
-
return parseCreateFactoryCall(source, filePath);
|
|
76
|
-
case 2:
|
|
77
|
-
sitemapCall = _context2.v;
|
|
78
|
-
if (!(!sitemapCall || !sitemapCall.variants)) {
|
|
79
|
-
_context2.n = 3;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
return _context2.a(2, {
|
|
83
|
-
schema: createSitemapSchema(),
|
|
84
|
-
data: {}
|
|
85
|
-
});
|
|
86
|
-
case 3:
|
|
87
|
-
// Process all page index files in parallel
|
|
88
|
-
entries = Object.entries(sitemapCall.variants);
|
|
89
|
-
_context2.n = 4;
|
|
90
|
-
return Promise.all(entries.map(/*#__PURE__*/function () {
|
|
91
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
92
|
-
var _ref3, key, importPath, metadata, _t;
|
|
93
|
-
return _regenerator().w(function (_context) {
|
|
94
|
-
while (1) switch (_context.p = _context.n) {
|
|
95
|
-
case 0:
|
|
96
|
-
_ref3 = _slicedToArray(_ref, 2), key = _ref3[0], importPath = _ref3[1];
|
|
97
|
-
_context.p = 1;
|
|
98
|
-
_context.n = 2;
|
|
99
|
-
return loadPageIndex(importPath);
|
|
100
|
-
case 2:
|
|
101
|
-
metadata = _context.v;
|
|
102
|
-
return _context.a(2, {
|
|
103
|
-
key: key,
|
|
104
|
-
metadata: metadata,
|
|
105
|
-
error: null
|
|
106
|
-
});
|
|
107
|
-
case 3:
|
|
108
|
-
_context.p = 3;
|
|
109
|
-
_t = _context.v;
|
|
110
|
-
return _context.a(2, {
|
|
111
|
-
key: key,
|
|
112
|
-
metadata: null,
|
|
113
|
-
error: _t instanceof Error ? _t : new Error(String(_t))
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}, _callee, null, [[1, 3]]);
|
|
117
|
-
}));
|
|
118
|
-
return function (_x2) {
|
|
119
|
-
return _ref2.apply(this, arguments);
|
|
120
|
-
};
|
|
121
|
-
}()));
|
|
122
|
-
case 4:
|
|
123
|
-
results = _context2.v;
|
|
124
|
-
// Collect results and errors
|
|
125
|
-
sitemapData = {};
|
|
126
|
-
errors = [];
|
|
127
|
-
_iterator = _createForOfIteratorHelper(results);
|
|
128
|
-
try {
|
|
129
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
130
|
-
result = _step.value;
|
|
131
|
-
if (result.error) {
|
|
132
|
-
errors.push({
|
|
133
|
-
key: result.key,
|
|
134
|
-
error: result.error
|
|
135
|
-
});
|
|
136
|
-
} else if (result.metadata) {
|
|
137
|
-
sitemapData[result.key] = result.metadata;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
50
|
+
export function createLoadServerSitemap(options = {}) {
|
|
51
|
+
return async function loadSitemap(url) {
|
|
52
|
+
// Convert file:// URL to proper file system path for reading the file
|
|
53
|
+
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
54
|
+
const filePath = url.startsWith('file://') ? fileURLToPath(url) : url;
|
|
140
55
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
56
|
+
// Determine root context from file path if not provided
|
|
57
|
+
const rootContext = options.rootContext ?? path.dirname(filePath);
|
|
58
|
+
|
|
59
|
+
// Create page index loader with root context
|
|
60
|
+
const loadPageIndex = createLoadServerPageIndex({
|
|
61
|
+
rootContext
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Read the source file to find createSitemap calls
|
|
65
|
+
const source = await readFile(filePath, 'utf-8');
|
|
66
|
+
|
|
67
|
+
// Parse the source to find createSitemap call with page imports
|
|
68
|
+
const sitemapCall = await parseCreateFactoryCall(source, filePath);
|
|
69
|
+
if (!sitemapCall || !sitemapCall.variants) {
|
|
70
|
+
// Return empty sitemap if no createSitemap call found
|
|
71
|
+
return {
|
|
72
|
+
schema: createSitemapSchema(),
|
|
73
|
+
data: {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Process all page index files in parallel
|
|
78
|
+
const entries = Object.entries(sitemapCall.variants);
|
|
79
|
+
const results = await Promise.all(entries.map(async ([key, importPath]) => {
|
|
80
|
+
try {
|
|
81
|
+
const metadata = await loadPageIndex(importPath);
|
|
82
|
+
return {
|
|
83
|
+
key,
|
|
84
|
+
metadata,
|
|
85
|
+
error: null
|
|
86
|
+
};
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return {
|
|
89
|
+
key,
|
|
90
|
+
metadata: null,
|
|
91
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
92
|
+
};
|
|
93
|
+
}
|
|
164
94
|
}));
|
|
165
|
-
|
|
166
|
-
|
|
95
|
+
|
|
96
|
+
// Collect results and errors
|
|
97
|
+
const sitemapData = {};
|
|
98
|
+
const errors = [];
|
|
99
|
+
for (const result of results) {
|
|
100
|
+
if (result.error) {
|
|
101
|
+
errors.push({
|
|
102
|
+
key: result.key,
|
|
103
|
+
error: result.error
|
|
104
|
+
});
|
|
105
|
+
} else if (result.metadata) {
|
|
106
|
+
sitemapData[result.key] = result.metadata;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Throw if any pages failed to load
|
|
111
|
+
if (errors.length > 0) {
|
|
112
|
+
const errorMessages = errors.map(({
|
|
113
|
+
key,
|
|
114
|
+
error
|
|
115
|
+
}) => ` ${key}: ${error.message}`).join('\n');
|
|
116
|
+
throw new Error(`Failed to load ${errors.length} page index(es):\n${errorMessages}`);
|
|
167
117
|
}
|
|
168
|
-
return
|
|
169
|
-
|
|
118
|
+
return {
|
|
119
|
+
schema: createSitemapSchema(),
|
|
120
|
+
data: sitemapData
|
|
121
|
+
};
|
|
122
|
+
};
|
|
170
123
|
}
|