@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,9 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
6
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
7
1
|
import { visit } from 'unist-util-visit';
|
|
8
2
|
import { dirname, relative } from 'node:path';
|
|
9
3
|
import { syncPageIndex } from "../syncPageIndex/index.js";
|
|
@@ -12,28 +6,19 @@ import { markdownToMetadata } from "../syncPageIndex/metadataToMarkdown.js";
|
|
|
12
6
|
* Extracts text content from paragraph nodes
|
|
13
7
|
*/
|
|
14
8
|
function extractParagraphText(node) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
text += "`".concat(child.value, "`");
|
|
26
|
-
} else if ('children' in child) {
|
|
27
|
-
// Handle nested elements like strong, emphasis, etc.
|
|
28
|
-
text += extractTextFromChildren(child.children);
|
|
29
|
-
}
|
|
9
|
+
let text = '';
|
|
10
|
+
for (const child of node.children) {
|
|
11
|
+
if (child.type === 'text') {
|
|
12
|
+
text += child.value;
|
|
13
|
+
} else if (child.type === 'inlineCode') {
|
|
14
|
+
// Preserve backticks for inline code
|
|
15
|
+
text += `\`${child.value}\``;
|
|
16
|
+
} else if ('children' in child) {
|
|
17
|
+
// Handle nested elements like strong, emphasis, etc.
|
|
18
|
+
text += extractTextFromChildren(child.children);
|
|
30
19
|
}
|
|
31
|
-
// Replace newlines with spaces and normalize whitespace, preserving non-breaking spaces
|
|
32
|
-
} catch (err) {
|
|
33
|
-
_iterator.e(err);
|
|
34
|
-
} finally {
|
|
35
|
-
_iterator.f();
|
|
36
20
|
}
|
|
21
|
+
// Replace newlines with spaces and normalize whitespace, preserving non-breaking spaces
|
|
37
22
|
return text.replace(/[ \t\n\r]+/g, ' ').trim();
|
|
38
23
|
}
|
|
39
24
|
|
|
@@ -41,26 +26,17 @@ function extractParagraphText(node) {
|
|
|
41
26
|
* Recursively extracts text from children nodes
|
|
42
27
|
*/
|
|
43
28
|
function extractTextFromChildren(children) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
text += "`".concat(child.value, "`");
|
|
55
|
-
} else if ('children' in child) {
|
|
56
|
-
// Recursively extract from nested elements (strong, emphasis, etc.)
|
|
57
|
-
text += extractTextFromChildren(child.children);
|
|
58
|
-
}
|
|
29
|
+
let text = '';
|
|
30
|
+
for (const child of children) {
|
|
31
|
+
if (child.type === 'text') {
|
|
32
|
+
text += child.value;
|
|
33
|
+
} else if (child.type === 'inlineCode') {
|
|
34
|
+
// Preserve backticks for inline code
|
|
35
|
+
text += `\`${child.value}\``;
|
|
36
|
+
} else if ('children' in child) {
|
|
37
|
+
// Recursively extract from nested elements (strong, emphasis, etc.)
|
|
38
|
+
text += extractTextFromChildren(child.children);
|
|
59
39
|
}
|
|
60
|
-
} catch (err) {
|
|
61
|
-
_iterator2.e(err);
|
|
62
|
-
} finally {
|
|
63
|
-
_iterator2.f();
|
|
64
40
|
}
|
|
65
41
|
return text;
|
|
66
42
|
}
|
|
@@ -69,26 +45,17 @@ function extractTextFromChildren(children) {
|
|
|
69
45
|
* Extracts plain text from children nodes (without formatting markers)
|
|
70
46
|
*/
|
|
71
47
|
function extractPlainTextFromChildren(children) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
text += child.value;
|
|
83
|
-
} else if ('children' in child) {
|
|
84
|
-
// Recursively extract from nested elements
|
|
85
|
-
text += extractPlainTextFromChildren(child.children);
|
|
86
|
-
}
|
|
48
|
+
let text = '';
|
|
49
|
+
for (const child of children) {
|
|
50
|
+
if (child.type === 'text') {
|
|
51
|
+
text += child.value;
|
|
52
|
+
} else if (child.type === 'inlineCode') {
|
|
53
|
+
// Include inline code without backticks
|
|
54
|
+
text += child.value;
|
|
55
|
+
} else if ('children' in child) {
|
|
56
|
+
// Recursively extract from nested elements
|
|
57
|
+
text += extractPlainTextFromChildren(child.children);
|
|
87
58
|
}
|
|
88
|
-
} catch (err) {
|
|
89
|
-
_iterator3.e(err);
|
|
90
|
-
} finally {
|
|
91
|
-
_iterator3.f();
|
|
92
59
|
}
|
|
93
60
|
return text;
|
|
94
61
|
}
|
|
@@ -107,51 +74,42 @@ function slugify(text) {
|
|
|
107
74
|
*/
|
|
108
75
|
function buildHeadingHierarchy(headings) {
|
|
109
76
|
// Skip the first heading (H1 - page title)
|
|
110
|
-
|
|
77
|
+
const contentHeadings = headings.slice(1);
|
|
111
78
|
if (contentHeadings.length === 0) {
|
|
112
79
|
return {};
|
|
113
80
|
}
|
|
114
|
-
|
|
115
|
-
|
|
81
|
+
const root = {};
|
|
82
|
+
const stack = [{
|
|
116
83
|
depth: 0,
|
|
117
84
|
node: root
|
|
118
85
|
}];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// Pop from stack until we find the parent level
|
|
125
|
-
while (stack.length > 0 && stack[stack.length - 1].depth >= heading.depth) {
|
|
126
|
-
stack.pop();
|
|
127
|
-
}
|
|
86
|
+
for (const heading of contentHeadings) {
|
|
87
|
+
// Pop from stack until we find the parent level
|
|
88
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= heading.depth) {
|
|
89
|
+
stack.pop();
|
|
90
|
+
}
|
|
128
91
|
|
|
129
|
-
|
|
130
|
-
|
|
92
|
+
// Get the current parent node
|
|
93
|
+
const parent = stack[stack.length - 1].node;
|
|
131
94
|
|
|
132
|
-
|
|
133
|
-
|
|
95
|
+
// Create slug from heading text using the provided slugify function
|
|
96
|
+
const slug = slugify(heading.text);
|
|
134
97
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
98
|
+
// Create new node for this heading
|
|
99
|
+
const newNode = {
|
|
100
|
+
title: heading.text,
|
|
101
|
+
// Plain text for display
|
|
102
|
+
titleMarkdown: heading.children,
|
|
103
|
+
// AST nodes preserving formatting
|
|
104
|
+
children: {}
|
|
105
|
+
};
|
|
106
|
+
parent[slug] = newNode;
|
|
144
107
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
} catch (err) {
|
|
152
|
-
_iterator4.e(err);
|
|
153
|
-
} finally {
|
|
154
|
-
_iterator4.f();
|
|
108
|
+
// Push this heading onto the stack
|
|
109
|
+
stack.push({
|
|
110
|
+
depth: heading.depth,
|
|
111
|
+
node: newNode.children
|
|
112
|
+
});
|
|
155
113
|
}
|
|
156
114
|
return root;
|
|
157
115
|
}
|
|
@@ -161,37 +119,17 @@ function buildHeadingHierarchy(headings) {
|
|
|
161
119
|
*/
|
|
162
120
|
function parseMetadataFromEstree(estree) {
|
|
163
121
|
try {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var declarations = node.declaration.declarations || [];
|
|
173
|
-
var _iterator6 = _createForOfIteratorHelper(declarations),
|
|
174
|
-
_step6;
|
|
175
|
-
try {
|
|
176
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
177
|
-
var _decl$id, _decl$init;
|
|
178
|
-
var decl = _step6.value;
|
|
179
|
-
if (((_decl$id = decl.id) == null ? void 0 : _decl$id.type) === 'Identifier' && decl.id.name === 'metadata' && ((_decl$init = decl.init) == null ? void 0 : _decl$init.type) === 'ObjectExpression') {
|
|
180
|
-
// Convert ESTree ObjectExpression to plain object
|
|
181
|
-
return convertEstreeObjectToPlain(decl.init);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
} catch (err) {
|
|
185
|
-
_iterator6.e(err);
|
|
186
|
-
} finally {
|
|
187
|
-
_iterator6.f();
|
|
122
|
+
const body = estree?.body || [];
|
|
123
|
+
for (const node of body) {
|
|
124
|
+
if (node.type === 'ExportNamedDeclaration' && node.declaration?.type === 'VariableDeclaration') {
|
|
125
|
+
const declarations = node.declaration.declarations || [];
|
|
126
|
+
for (const decl of declarations) {
|
|
127
|
+
if (decl.id?.type === 'Identifier' && decl.id.name === 'metadata' && decl.init?.type === 'ObjectExpression') {
|
|
128
|
+
// Convert ESTree ObjectExpression to plain object
|
|
129
|
+
return convertEstreeObjectToPlain(decl.init);
|
|
188
130
|
}
|
|
189
131
|
}
|
|
190
132
|
}
|
|
191
|
-
} catch (err) {
|
|
192
|
-
_iterator5.e(err);
|
|
193
|
-
} finally {
|
|
194
|
-
_iterator5.f();
|
|
195
133
|
}
|
|
196
134
|
} catch (error) {
|
|
197
135
|
console.error('Error parsing metadata from estree:', error);
|
|
@@ -203,43 +141,32 @@ function parseMetadataFromEstree(estree) {
|
|
|
203
141
|
* Converts an ESTree ObjectExpression to a plain JavaScript object
|
|
204
142
|
*/
|
|
205
143
|
function convertEstreeObjectToPlain(node) {
|
|
206
|
-
if (
|
|
207
|
-
|
|
144
|
+
if (typeof node === 'object' && node !== null && 'type' in node && node.type === 'ObjectExpression') {
|
|
145
|
+
const obj = {};
|
|
208
146
|
if ('properties' in node && Array.isArray(node.properties)) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
key = String(prop.key.value);
|
|
220
|
-
}
|
|
221
|
-
if (key && 'value' in prop) {
|
|
222
|
-
obj[key] = convertEstreeObjectToPlain(prop.value);
|
|
223
|
-
}
|
|
147
|
+
for (const prop of node.properties) {
|
|
148
|
+
if (typeof prop === 'object' && prop !== null && 'type' in prop && prop.type === 'Property' && 'key' in prop && prop.key) {
|
|
149
|
+
let key = '';
|
|
150
|
+
if ('name' in prop.key && typeof prop.key.name === 'string') {
|
|
151
|
+
key = prop.key.name;
|
|
152
|
+
} else if ('value' in prop.key) {
|
|
153
|
+
key = String(prop.key.value);
|
|
154
|
+
}
|
|
155
|
+
if (key && 'value' in prop) {
|
|
156
|
+
obj[key] = convertEstreeObjectToPlain(prop.value);
|
|
224
157
|
}
|
|
225
158
|
}
|
|
226
|
-
} catch (err) {
|
|
227
|
-
_iterator7.e(err);
|
|
228
|
-
} finally {
|
|
229
|
-
_iterator7.f();
|
|
230
159
|
}
|
|
231
160
|
}
|
|
232
161
|
return obj;
|
|
233
162
|
}
|
|
234
|
-
if (
|
|
235
|
-
return node.elements.map(
|
|
236
|
-
return convertEstreeObjectToPlain(el);
|
|
237
|
-
});
|
|
163
|
+
if (typeof node === 'object' && node !== null && 'type' in node && node.type === 'ArrayExpression' && 'elements' in node && Array.isArray(node.elements)) {
|
|
164
|
+
return node.elements.map(el => convertEstreeObjectToPlain(el));
|
|
238
165
|
}
|
|
239
|
-
if (
|
|
166
|
+
if (typeof node === 'object' && node !== null && 'type' in node && node.type === 'Literal' && 'value' in node) {
|
|
240
167
|
return node.value;
|
|
241
168
|
}
|
|
242
|
-
if (
|
|
169
|
+
if (typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node) {
|
|
243
170
|
return node.name;
|
|
244
171
|
}
|
|
245
172
|
return undefined;
|
|
@@ -255,9 +182,8 @@ function isRouteGroup(dirName) {
|
|
|
255
182
|
/**
|
|
256
183
|
* Gets the parent directory, skipping over Next.js route groups if requested
|
|
257
184
|
*/
|
|
258
|
-
function getParentDir(path) {
|
|
259
|
-
|
|
260
|
-
var parent = dirname(path);
|
|
185
|
+
function getParentDir(path, skipRouteGroups = false) {
|
|
186
|
+
let parent = dirname(path);
|
|
261
187
|
if (skipRouteGroups) {
|
|
262
188
|
while (parent !== dirname(parent) && isRouteGroup(parent.split('/').pop() || '')) {
|
|
263
189
|
parent = dirname(parent);
|
|
@@ -268,19 +194,17 @@ function getParentDir(path) {
|
|
|
268
194
|
/**
|
|
269
195
|
* Converts extracted metadata to PageMetadata format for index updates
|
|
270
196
|
*/
|
|
271
|
-
function toPageMetadata(metadata, filePath) {
|
|
272
|
-
var _options$visibleDescr, _options$visibleDescr2;
|
|
273
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
197
|
+
function toPageMetadata(metadata, filePath, options = {}) {
|
|
274
198
|
// Extract the slug from the file path (directory name containing the page)
|
|
275
|
-
|
|
276
|
-
|
|
199
|
+
const parts = filePath.split('/');
|
|
200
|
+
const pageFileName = parts[parts.length - 1]; // e.g., 'page.mdx'
|
|
277
201
|
|
|
278
202
|
// Get the directory containing the page file
|
|
279
|
-
|
|
203
|
+
const pageDir = dirname(filePath);
|
|
280
204
|
|
|
281
205
|
// Find the directory name by looking backwards for the first non-route-group directory
|
|
282
|
-
|
|
283
|
-
for (
|
|
206
|
+
let dirName = '';
|
|
207
|
+
for (let i = parts.length - 2; i >= 0; i -= 1) {
|
|
284
208
|
if (!isRouteGroup(parts[i])) {
|
|
285
209
|
dirName = parts[i];
|
|
286
210
|
break;
|
|
@@ -289,20 +213,20 @@ function toPageMetadata(metadata, filePath) {
|
|
|
289
213
|
|
|
290
214
|
// Generate slug from title if available, otherwise from directory name
|
|
291
215
|
// This ensures consistency with section slug generation (kebab-case for multi-word, lowercase for camelCase)
|
|
292
|
-
|
|
216
|
+
const slug = metadata.title ? metadata.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') : dirName;
|
|
293
217
|
|
|
294
218
|
// Calculate parent directory (skipping route groups, matching syncPageIndex behavior)
|
|
295
|
-
|
|
219
|
+
const parentDir = getParentDir(pageDir, true);
|
|
296
220
|
|
|
297
221
|
// Create relative path from parent to page
|
|
298
|
-
|
|
299
|
-
|
|
222
|
+
const relativePath = relative(parentDir, pageDir);
|
|
223
|
+
const path = `./${relativePath}/${pageFileName}`;
|
|
300
224
|
return {
|
|
301
|
-
slug
|
|
302
|
-
path
|
|
225
|
+
slug,
|
|
226
|
+
path,
|
|
303
227
|
title: metadata.title,
|
|
304
|
-
description:
|
|
305
|
-
descriptionMarkdown:
|
|
228
|
+
description: options.visibleDescription ?? metadata.description,
|
|
229
|
+
descriptionMarkdown: options.visibleDescriptionMarkdown ?? metadata.descriptionMarkdown,
|
|
306
230
|
keywords: metadata.keywords,
|
|
307
231
|
sections: metadata.sections,
|
|
308
232
|
embeddings: metadata.embeddings,
|
|
@@ -323,30 +247,21 @@ function valueToEstree(value) {
|
|
|
323
247
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
324
248
|
return {
|
|
325
249
|
type: 'Literal',
|
|
326
|
-
value
|
|
250
|
+
value
|
|
327
251
|
};
|
|
328
252
|
}
|
|
329
253
|
if (Array.isArray(value)) {
|
|
330
254
|
return {
|
|
331
255
|
type: 'ArrayExpression',
|
|
332
|
-
elements: value.map(
|
|
333
|
-
return valueToEstree(item);
|
|
334
|
-
})
|
|
256
|
+
elements: value.map(item => valueToEstree(item))
|
|
335
257
|
};
|
|
336
258
|
}
|
|
337
|
-
if (
|
|
259
|
+
if (typeof value === 'object') {
|
|
338
260
|
return {
|
|
339
261
|
type: 'ObjectExpression',
|
|
340
|
-
properties: Object.entries(value).filter(
|
|
341
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
342
|
-
val = _ref2[1];
|
|
343
|
-
return val !== undefined;
|
|
344
|
-
}).map(function (_ref3) {
|
|
345
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
346
|
-
key = _ref4[0],
|
|
347
|
-
val = _ref4[1];
|
|
262
|
+
properties: Object.entries(value).filter(([, val]) => val !== undefined).map(([key, val]) => {
|
|
348
263
|
// Check if key is a valid JavaScript identifier
|
|
349
|
-
|
|
264
|
+
const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key);
|
|
350
265
|
return {
|
|
351
266
|
type: 'Property',
|
|
352
267
|
key: isValidIdentifier ? {
|
|
@@ -375,71 +290,40 @@ function valueToEstree(value) {
|
|
|
375
290
|
* Updates the metadata object in an existing ESTree
|
|
376
291
|
*/
|
|
377
292
|
function updateMetadataInEstree(estree, metadata) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
return '';
|
|
406
|
-
}));
|
|
407
|
-
|
|
408
|
-
// Add missing properties
|
|
409
|
-
var metadataObj = valueToEstree(metadata);
|
|
410
|
-
if (_typeof(metadataObj) === 'object' && metadataObj !== null && 'properties' in metadataObj && Array.isArray(metadataObj.properties)) {
|
|
411
|
-
var _iterator0 = _createForOfIteratorHelper(metadataObj.properties),
|
|
412
|
-
_step0;
|
|
413
|
-
try {
|
|
414
|
-
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
415
|
-
var prop = _step0.value;
|
|
416
|
-
if (_typeof(prop) === 'object' && prop !== null && 'key' in prop && _typeof(prop.key) === 'object' && prop.key !== null && 'name' in prop.key) {
|
|
417
|
-
var key = prop.key.name;
|
|
418
|
-
if (key && !existingKeys.has(String(key))) {
|
|
419
|
-
existingProps.push(prop);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
} catch (err) {
|
|
424
|
-
_iterator0.e(err);
|
|
425
|
-
} finally {
|
|
426
|
-
_iterator0.f();
|
|
293
|
+
const body = estree?.body || [];
|
|
294
|
+
for (const node of body) {
|
|
295
|
+
if (node.type === 'ExportNamedDeclaration' && node.declaration?.type === 'VariableDeclaration') {
|
|
296
|
+
const declarations = node.declaration.declarations || [];
|
|
297
|
+
for (const decl of declarations) {
|
|
298
|
+
if (decl.id?.type === 'Identifier' && decl.id.name === 'metadata' && decl.init?.type === 'ObjectExpression') {
|
|
299
|
+
// Merge new metadata into existing object
|
|
300
|
+
const existingProps = decl.init.properties || [];
|
|
301
|
+
const existingKeys = new Set(existingProps.filter(prop => prop.type === 'Property').map(prop => {
|
|
302
|
+
if ('name' in prop.key) {
|
|
303
|
+
return prop.key.name;
|
|
304
|
+
}
|
|
305
|
+
if ('value' in prop.key) {
|
|
306
|
+
return String(prop.key.value || '');
|
|
307
|
+
}
|
|
308
|
+
return '';
|
|
309
|
+
}));
|
|
310
|
+
|
|
311
|
+
// Add missing properties
|
|
312
|
+
const metadataObj = valueToEstree(metadata);
|
|
313
|
+
if (typeof metadataObj === 'object' && metadataObj !== null && 'properties' in metadataObj && Array.isArray(metadataObj.properties)) {
|
|
314
|
+
for (const prop of metadataObj.properties) {
|
|
315
|
+
if (typeof prop === 'object' && prop !== null && 'key' in prop && typeof prop.key === 'object' && prop.key !== null && 'name' in prop.key) {
|
|
316
|
+
const key = prop.key.name;
|
|
317
|
+
if (key && !existingKeys.has(String(key))) {
|
|
318
|
+
existingProps.push(prop);
|
|
427
319
|
}
|
|
428
320
|
}
|
|
429
|
-
return;
|
|
430
321
|
}
|
|
431
322
|
}
|
|
432
|
-
|
|
433
|
-
_iterator9.e(err);
|
|
434
|
-
} finally {
|
|
435
|
-
_iterator9.f();
|
|
323
|
+
return;
|
|
436
324
|
}
|
|
437
325
|
}
|
|
438
326
|
}
|
|
439
|
-
} catch (err) {
|
|
440
|
-
_iterator8.e(err);
|
|
441
|
-
} finally {
|
|
442
|
-
_iterator8.f();
|
|
443
327
|
}
|
|
444
328
|
}
|
|
445
329
|
|
|
@@ -447,7 +331,7 @@ function updateMetadataInEstree(estree, metadata) {
|
|
|
447
331
|
* Creates a new metadata export node
|
|
448
332
|
*/
|
|
449
333
|
function createMetadataExport(metadata) {
|
|
450
|
-
|
|
334
|
+
const metadataObj = valueToEstree(metadata);
|
|
451
335
|
return {
|
|
452
336
|
type: 'mdxjsEsm',
|
|
453
337
|
value: '',
|
|
@@ -477,510 +361,481 @@ function createMetadataExport(metadata) {
|
|
|
477
361
|
}
|
|
478
362
|
};
|
|
479
363
|
}
|
|
480
|
-
export
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
364
|
+
export const transformMarkdownMetadata = (options = {}) => {
|
|
365
|
+
return async (tree, file) => {
|
|
366
|
+
const root = tree;
|
|
367
|
+
const headings = [];
|
|
368
|
+
let metadata = null;
|
|
369
|
+
let firstH1 = null;
|
|
370
|
+
let firstParagraphAfterH1 = null;
|
|
371
|
+
let metadataNode = null; // Track the ESM node containing metadata
|
|
372
|
+
let metaDescription = null; // Track meta tag description
|
|
373
|
+
let metaKeywords = null; // Track meta tag keywords
|
|
374
|
+
let foundFirstH1 = false;
|
|
375
|
+
let nextNodeAfterH1 = null;
|
|
376
|
+
let firstParagraphMarkdown;
|
|
377
|
+
const fullTextParts = []; // Collect text parts for fullText - headings and content alternating
|
|
378
|
+
|
|
379
|
+
// Single pass: extract metadata export, meta tags, headings, first paragraph, and full text
|
|
380
|
+
visit(root, (node, index, parent) => {
|
|
381
|
+
// Extract metadata export if it exists
|
|
382
|
+
if (node.type === 'mdxjsEsm' && 'data' in node && node.data && typeof node.data === 'object' && 'estree' in node.data && node.data.estree) {
|
|
383
|
+
const extracted = parseMetadataFromEstree(node.data.estree);
|
|
384
|
+
if (extracted) {
|
|
385
|
+
metadata = extracted;
|
|
386
|
+
metadataNode = node;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Look for meta tags (can appear anywhere in the document)
|
|
391
|
+
if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') && 'name' in node && (node.name === 'meta' || node.name === 'Meta')) {
|
|
392
|
+
// Check attributes to find the meta tag type
|
|
393
|
+
const attributes = 'attributes' in node && Array.isArray(node.attributes) ? node.attributes : [];
|
|
394
|
+
let metaName = null;
|
|
395
|
+
let contentValue = null;
|
|
396
|
+
for (const attr of attributes) {
|
|
397
|
+
if (typeof attr === 'object' && attr !== null && 'type' in attr && attr.type === 'mdxJsxAttribute' && 'name' in attr) {
|
|
398
|
+
if (attr.name === 'name' && 'value' in attr) {
|
|
399
|
+
metaName = typeof attr.value === 'string' ? attr.value : null;
|
|
400
|
+
}
|
|
401
|
+
if (attr.name === 'content' && 'value' in attr) {
|
|
402
|
+
// Extract the content value
|
|
403
|
+
if (typeof attr.value === 'string') {
|
|
404
|
+
contentValue = attr.value;
|
|
405
|
+
} else if (typeof attr.value === 'object' && attr.value !== null && 'type' in attr.value && attr.value.type === 'mdxJsxAttributeValueExpression' && 'value' in attr.value && typeof attr.value.value === 'string') {
|
|
406
|
+
// Handle expression values if needed
|
|
407
|
+
contentValue = attr.value.value;
|
|
508
408
|
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
509
412
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
try {
|
|
519
|
-
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
520
|
-
var attr = _step1.value;
|
|
521
|
-
if (_typeof(attr) === 'object' && attr !== null && 'type' in attr && attr.type === 'mdxJsxAttribute' && 'name' in attr) {
|
|
522
|
-
if (attr.name === 'name' && 'value' in attr) {
|
|
523
|
-
metaName = typeof attr.value === 'string' ? attr.value : null;
|
|
524
|
-
}
|
|
525
|
-
if (attr.name === 'content' && 'value' in attr) {
|
|
526
|
-
// Extract the content value
|
|
527
|
-
if (typeof attr.value === 'string') {
|
|
528
|
-
contentValue = attr.value;
|
|
529
|
-
} else if (_typeof(attr.value) === 'object' && attr.value !== null && 'type' in attr.value && attr.value.type === 'mdxJsxAttributeValueExpression' && 'value' in attr.value && typeof attr.value.value === 'string') {
|
|
530
|
-
// Handle expression values if needed
|
|
531
|
-
contentValue = attr.value.value;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
413
|
+
// Process based on meta tag name
|
|
414
|
+
if (metaName === 'description' && contentValue) {
|
|
415
|
+
metaDescription = contentValue;
|
|
416
|
+
} else if (metaName === 'keywords' && contentValue) {
|
|
417
|
+
// Parse keywords CSV into array
|
|
418
|
+
metaKeywords = contentValue.split(',').map(keyword => keyword.trim());
|
|
419
|
+
}
|
|
420
|
+
}
|
|
536
421
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
422
|
+
// Extract headings
|
|
423
|
+
if (node.type === 'heading') {
|
|
424
|
+
const heading = node;
|
|
425
|
+
const text = extractTextFromChildren(heading.children);
|
|
426
|
+
headings.push({
|
|
427
|
+
depth: heading.depth,
|
|
428
|
+
text,
|
|
429
|
+
children: heading.children // Preserve AST nodes for formatting
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Track first h1
|
|
433
|
+
if (heading.depth === 1 && !foundFirstH1) {
|
|
434
|
+
firstH1 = text;
|
|
435
|
+
foundFirstH1 = true;
|
|
436
|
+
|
|
437
|
+
// Mark that we need to check the next node
|
|
438
|
+
if (parent && index !== undefined && 'children' in parent && Array.isArray(parent.children)) {
|
|
439
|
+
if (index + 1 < parent.children.length) {
|
|
440
|
+
nextNodeAfterH1 = parent.children[index + 1];
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
552
445
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
if (parent && index !== undefined && 'children' in parent && Array.isArray(parent.children)) {
|
|
570
|
-
if (index + 1 < parent.children.length) {
|
|
571
|
-
nextNodeAfterH1 = parent.children[index + 1];
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
446
|
+
// Check if this is the paragraph right after the first h1
|
|
447
|
+
if (foundFirstH1 && !firstParagraphAfterH1 && nextNodeAfterH1 && node === nextNodeAfterH1 && node.type === 'paragraph') {
|
|
448
|
+
const paragraphNode = node;
|
|
449
|
+
firstParagraphAfterH1 = extractParagraphText(paragraphNode);
|
|
450
|
+
|
|
451
|
+
// If the paragraph contains a single JSX element wrapper, unwrap it
|
|
452
|
+
// This handles cases like <Description>text</Description>
|
|
453
|
+
if (paragraphNode.children.length === 1 && paragraphNode.children[0].type === 'mdxJsxTextElement' && 'children' in paragraphNode.children[0] && Array.isArray(paragraphNode.children[0].children)) {
|
|
454
|
+
// Use the children of the JSX element instead of the wrapper
|
|
455
|
+
firstParagraphMarkdown = paragraphNode.children[0].children;
|
|
456
|
+
} else {
|
|
457
|
+
// Preserve AST nodes for formatting
|
|
458
|
+
firstParagraphMarkdown = paragraphNode.children;
|
|
459
|
+
}
|
|
460
|
+
nextNodeAfterH1 = null; // Clear the marker
|
|
461
|
+
}
|
|
576
462
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
// Preserve AST nodes for formatting
|
|
589
|
-
firstParagraphMarkdown = paragraphNode.children;
|
|
590
|
-
}
|
|
591
|
-
nextNodeAfterH1 = null; // Clear the marker
|
|
592
|
-
}
|
|
463
|
+
// Check if this is a JSX flow element right after the first h1 (multi-line JSX like <Subtitle>...</Subtitle>)
|
|
464
|
+
// This handles cases where the JSX element spans multiple lines and becomes a block-level element
|
|
465
|
+
if (foundFirstH1 && !firstParagraphAfterH1 && nextNodeAfterH1 && node === nextNodeAfterH1 && node.type === 'mdxJsxFlowElement' && 'name' in node && node.name !== 'meta' && node.name !== 'Meta' && 'children' in node && Array.isArray(node.children)) {
|
|
466
|
+
// Extract text from the JSX element's children, preserving non-breaking spaces
|
|
467
|
+
const textContent = extractPlainTextFromChildren(node.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
468
|
+
if (textContent) {
|
|
469
|
+
firstParagraphAfterH1 = textContent;
|
|
470
|
+
firstParagraphMarkdown = node.children;
|
|
471
|
+
}
|
|
472
|
+
nextNodeAfterH1 = null; // Clear the marker
|
|
473
|
+
}
|
|
593
474
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
475
|
+
// Extract full text content (excluding code blocks and metadata)
|
|
476
|
+
// When we encounter a heading, push the heading text and then create a new empty slot for content
|
|
477
|
+
if (node.type === 'heading') {
|
|
478
|
+
const heading = node;
|
|
479
|
+
// Preserve non-breaking spaces in heading text
|
|
480
|
+
const text = extractPlainTextFromChildren(heading.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
481
|
+
if (text) {
|
|
482
|
+
fullTextParts.push(text); // Add heading
|
|
483
|
+
fullTextParts.push(''); // Create slot for content after this heading
|
|
484
|
+
}
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
605
487
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
// Preserve non-breaking spaces in heading text
|
|
611
|
-
var _text = extractPlainTextFromChildren(_heading.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
612
|
-
if (_text) {
|
|
613
|
-
fullTextParts.push(_text); // Add heading
|
|
614
|
-
fullTextParts.push(''); // Create slot for content after this heading
|
|
615
|
-
}
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
488
|
+
// Skip multiline code blocks
|
|
489
|
+
if (node.type === 'code') {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
618
492
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
493
|
+
// Skip metadata exports
|
|
494
|
+
if (node.type === 'mdxjsEsm') {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
623
497
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
498
|
+
// Skip meta tags (they don't contribute to page content)
|
|
499
|
+
if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') && 'name' in node && (node.name === 'meta' || node.name === 'Meta')) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
628
502
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
503
|
+
// Handle paragraphs for full text, preserving non-breaking spaces
|
|
504
|
+
if (node.type === 'paragraph') {
|
|
505
|
+
const text = extractPlainTextFromChildren(node.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
506
|
+
if (text) {
|
|
507
|
+
// Append to the last slot (current section's content)
|
|
508
|
+
if (fullTextParts.length === 0) {
|
|
509
|
+
fullTextParts.push(text);
|
|
510
|
+
} else {
|
|
511
|
+
const lastIndex = fullTextParts.length - 1;
|
|
512
|
+
fullTextParts[lastIndex] = fullTextParts[lastIndex] ? `${fullTextParts[lastIndex]} ${text}` : text;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
633
516
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
517
|
+
// Handle lists - condense into comma-separated items
|
|
518
|
+
if (node.type === 'list' && 'children' in node && Array.isArray(node.children)) {
|
|
519
|
+
const listItems = [];
|
|
520
|
+
for (const item of node.children) {
|
|
521
|
+
if (item.type === 'listItem' && 'children' in item && Array.isArray(item.children)) {
|
|
522
|
+
// Preserve non-breaking spaces in list item text
|
|
523
|
+
const itemText = extractPlainTextFromChildren(item.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
524
|
+
if (itemText) {
|
|
525
|
+
listItems.push(itemText);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (listItems.length > 0) {
|
|
530
|
+
const text = listItems.join(', ');
|
|
531
|
+
// Append to the last slot (current section's content)
|
|
532
|
+
if (fullTextParts.length === 0) {
|
|
533
|
+
fullTextParts.push(text);
|
|
534
|
+
} else {
|
|
535
|
+
const lastIndex = fullTextParts.length - 1;
|
|
536
|
+
fullTextParts[lastIndex] = fullTextParts[lastIndex] ? `${fullTextParts[lastIndex]} ${text}` : text;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
647
540
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
var listItems = [];
|
|
651
|
-
var _iterator10 = _createForOfIteratorHelper(node.children),
|
|
652
|
-
_step10;
|
|
653
|
-
try {
|
|
654
|
-
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
655
|
-
var item = _step10.value;
|
|
656
|
-
if (item.type === 'listItem' && 'children' in item && Array.isArray(item.children)) {
|
|
657
|
-
// Preserve non-breaking spaces in list item text
|
|
658
|
-
var itemText = extractPlainTextFromChildren(item.children).replace(/[ \t\n\r]+/g, ' ').trim();
|
|
659
|
-
if (itemText) {
|
|
660
|
-
listItems.push(itemText);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
} catch (err) {
|
|
665
|
-
_iterator10.e(err);
|
|
666
|
-
} finally {
|
|
667
|
-
_iterator10.f();
|
|
668
|
-
}
|
|
669
|
-
if (listItems.length > 0) {
|
|
670
|
-
var _text3 = listItems.join(', ');
|
|
671
|
-
// Append to the last slot (current section's content)
|
|
672
|
-
if (fullTextParts.length === 0) {
|
|
673
|
-
fullTextParts.push(_text3);
|
|
674
|
-
} else {
|
|
675
|
-
var _lastIndex = fullTextParts.length - 1;
|
|
676
|
-
fullTextParts[_lastIndex] = fullTextParts[_lastIndex] ? "".concat(fullTextParts[_lastIndex], " ").concat(_text3) : _text3;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
541
|
+
// Handle blockquotes - their paragraphs will be picked up by the paragraph handler above
|
|
542
|
+
});
|
|
680
543
|
|
|
681
|
-
|
|
682
|
-
|
|
544
|
+
// Fill in missing title and description if we have them from content
|
|
545
|
+
let shouldUpdateMetadata = false;
|
|
546
|
+
if (metadata) {
|
|
547
|
+
const mutableMetadata = metadata;
|
|
683
548
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
mutableMetadata.title = firstH1;
|
|
690
|
-
shouldUpdateMetadata = true;
|
|
691
|
-
}
|
|
549
|
+
// Add title if missing
|
|
550
|
+
if (firstH1 && !mutableMetadata.title) {
|
|
551
|
+
mutableMetadata.title = firstH1;
|
|
552
|
+
shouldUpdateMetadata = true;
|
|
553
|
+
}
|
|
692
554
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
555
|
+
// Add description - prioritize meta tag over paragraph
|
|
556
|
+
if (!mutableMetadata.description) {
|
|
557
|
+
if (metaDescription) {
|
|
558
|
+
mutableMetadata.description = metaDescription;
|
|
559
|
+
shouldUpdateMetadata = true;
|
|
560
|
+
} else if (firstParagraphAfterH1) {
|
|
561
|
+
mutableMetadata.description = firstParagraphAfterH1;
|
|
562
|
+
shouldUpdateMetadata = true;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
703
565
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
566
|
+
// Add descriptionMarkdown if missing
|
|
567
|
+
// If we used meta tag, set to empty array since meta has no children
|
|
568
|
+
// Otherwise use the paragraph markdown nodes
|
|
569
|
+
if (!mutableMetadata.descriptionMarkdown) {
|
|
570
|
+
if (metaDescription) {
|
|
571
|
+
mutableMetadata.descriptionMarkdown = [];
|
|
572
|
+
shouldUpdateMetadata = true;
|
|
573
|
+
} else if (firstParagraphMarkdown) {
|
|
574
|
+
mutableMetadata.descriptionMarkdown = firstParagraphMarkdown;
|
|
575
|
+
shouldUpdateMetadata = true;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
716
578
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
579
|
+
// Add keywords from meta tag if present
|
|
580
|
+
if (metaKeywords && !mutableMetadata.keywords) {
|
|
581
|
+
mutableMetadata.keywords = metaKeywords;
|
|
582
|
+
shouldUpdateMetadata = true;
|
|
583
|
+
}
|
|
722
584
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
585
|
+
// Add sections hierarchy if we have headings
|
|
586
|
+
const hasSections = mutableMetadata.sections && Object.keys(mutableMetadata.sections).length > 0;
|
|
587
|
+
if (headings.length > 1 && !hasSections) {
|
|
588
|
+
mutableMetadata.sections = buildHeadingHierarchy(headings);
|
|
589
|
+
shouldUpdateMetadata = true;
|
|
590
|
+
}
|
|
729
591
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
592
|
+
// Update the metadata in the ESTree if we added any fields
|
|
593
|
+
if (shouldUpdateMetadata && metadataNode) {
|
|
594
|
+
const esmNode = metadataNode;
|
|
595
|
+
if (esmNode.data?.estree) {
|
|
596
|
+
// Apply titleSuffix only to the exported metadata, not to the internal metadata
|
|
597
|
+
const exportMetadata = options.titleSuffix && mutableMetadata.title ? {
|
|
598
|
+
...mutableMetadata,
|
|
599
|
+
title: mutableMetadata.title + options.titleSuffix
|
|
600
|
+
} : mutableMetadata;
|
|
601
|
+
updateMetadataInEstree(esmNode.data.estree, exportMetadata);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
} else if (firstH1 || firstParagraphAfterH1 || metaDescription || metaKeywords) {
|
|
605
|
+
// Create metadata if we found h1, paragraph, or meta tags but no metadata export exists
|
|
606
|
+
// Prioritize meta tag description over paragraph
|
|
607
|
+
const descriptionValue = metaDescription || firstParagraphAfterH1 || undefined;
|
|
608
|
+
const descriptionMarkdownValue = metaDescription ? [] : firstParagraphMarkdown || undefined;
|
|
609
|
+
metadata = {
|
|
610
|
+
title: firstH1 || undefined,
|
|
611
|
+
description: descriptionValue,
|
|
612
|
+
descriptionMarkdown: descriptionMarkdownValue,
|
|
613
|
+
keywords: metaKeywords || undefined,
|
|
614
|
+
sections: headings.length > 1 ? buildHeadingHierarchy(headings) : undefined
|
|
615
|
+
};
|
|
753
616
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
617
|
+
// Create a new metadata export and add it to the tree
|
|
618
|
+
// Apply titleSuffix only to the exported metadata, not to the internal metadata
|
|
619
|
+
const exportMetadata = options.titleSuffix && metadata.title ? {
|
|
620
|
+
...metadata,
|
|
621
|
+
title: metadata.title + options.titleSuffix
|
|
622
|
+
} : metadata;
|
|
623
|
+
const metadataExport = createMetadataExport(exportMetadata);
|
|
624
|
+
root.children.unshift(metadataExport);
|
|
625
|
+
}
|
|
762
626
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
627
|
+
// Inject sitemap data into wrapper components in autogenerated index files
|
|
628
|
+
// This uses the indexWrapperComponent from extractToIndex options
|
|
629
|
+
const wrapperComponent = typeof options.extractToIndex === 'object' ? options.extractToIndex.indexWrapperComponent : undefined;
|
|
630
|
+
const extractBaseDir = typeof options.extractToIndex === 'object' ? options.extractToIndex.baseDir : undefined;
|
|
631
|
+
if (wrapperComponent && file.path) {
|
|
632
|
+
let fileContent = null;
|
|
633
|
+
if (typeof file.value === 'string') {
|
|
634
|
+
fileContent = file.value;
|
|
635
|
+
} else if (file.value instanceof Buffer) {
|
|
636
|
+
fileContent = file.value.toString('utf-8');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Check if this is an autogenerated index file
|
|
640
|
+
if (fileContent && fileContent.includes("[//]: # 'This file is autogenerated")) {
|
|
641
|
+
// Parse the page list metadata from the markdown
|
|
642
|
+
const pagesMetadata = await markdownToMetadata(fileContent);
|
|
643
|
+
if (pagesMetadata) {
|
|
644
|
+
// Compute prefix from file path
|
|
645
|
+
let prefix = '/';
|
|
646
|
+
let filePath = file.path;
|
|
647
|
+
// Strip baseDir if provided
|
|
648
|
+
if (extractBaseDir && filePath.startsWith(extractBaseDir)) {
|
|
649
|
+
filePath = filePath.substring(extractBaseDir.length);
|
|
650
|
+
if (filePath.startsWith('/')) {
|
|
651
|
+
filePath = filePath.substring(1);
|
|
770
652
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
653
|
+
}
|
|
654
|
+
// Get directory path and convert to URL prefix
|
|
655
|
+
const dirPath = dirname(filePath);
|
|
656
|
+
// Filter out src, app, and route groups from the path
|
|
657
|
+
// First, split and filter to find meaningful segments
|
|
658
|
+
const segments = dirPath.split('/').filter(seg => {
|
|
659
|
+
if (seg.startsWith('(') && seg.endsWith(')')) {
|
|
660
|
+
return false;
|
|
776
661
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
if (!(fileContent && fileContent.includes("[//]: # 'This file is autogenerated"))) {
|
|
780
|
-
_context.n = 2;
|
|
781
|
-
break;
|
|
662
|
+
if (seg === '.' || seg === '') {
|
|
663
|
+
return false;
|
|
782
664
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
tags: page.tags,
|
|
841
|
-
skipDetailSection: page.skipDetailSection,
|
|
842
|
-
image: page.image
|
|
843
|
-
};
|
|
844
|
-
})
|
|
845
|
-
}; // Find and update the wrapper component in the AST
|
|
846
|
-
visit(root, function (node) {
|
|
847
|
-
if (node.type === 'mdxJsxFlowElement' && 'name' in node && node.name === wrapperComponent) {
|
|
848
|
-
// Create the data attribute with expression value
|
|
849
|
-
var dataAttr = {
|
|
850
|
-
type: 'mdxJsxAttribute',
|
|
851
|
-
name: 'data',
|
|
852
|
-
value: {
|
|
853
|
-
type: 'mdxJsxAttributeValueExpression',
|
|
854
|
-
value: JSON.stringify(sitemapData),
|
|
855
|
-
data: {
|
|
856
|
-
estree: {
|
|
857
|
-
type: 'Program',
|
|
858
|
-
sourceType: 'module',
|
|
859
|
-
body: [{
|
|
860
|
-
type: 'ExpressionStatement',
|
|
861
|
-
expression: valueToEstree(sitemapData)
|
|
862
|
-
}]
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
// Add the attribute to the element
|
|
869
|
-
if ('attributes' in node && Array.isArray(node.attributes)) {
|
|
870
|
-
// Remove existing data attribute if present
|
|
871
|
-
var existingIndex = node.attributes.findIndex(function (attr) {
|
|
872
|
-
return attr && _typeof(attr) === 'object' && 'type' in attr && attr.type === 'mdxJsxAttribute' && 'name' in attr && attr.name === 'data';
|
|
873
|
-
});
|
|
874
|
-
if (existingIndex !== -1) {
|
|
875
|
-
node.attributes.splice(existingIndex, 1);
|
|
665
|
+
return true;
|
|
666
|
+
});
|
|
667
|
+
// Find and remove 'src' followed by 'app' pattern (common in Next.js projects)
|
|
668
|
+
const srcIndex = segments.indexOf('src');
|
|
669
|
+
if (srcIndex !== -1) {
|
|
670
|
+
// Remove 'src'
|
|
671
|
+
segments.splice(srcIndex, 1);
|
|
672
|
+
// Check if 'app' now follows where 'src' was
|
|
673
|
+
if (segments[srcIndex] === 'app') {
|
|
674
|
+
segments.splice(srcIndex, 1);
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
// No 'src', check for standalone 'app' at the same position pattern
|
|
678
|
+
const appIndex = segments.indexOf('app');
|
|
679
|
+
if (appIndex !== -1 && (appIndex === 0 || appIndex === srcIndex)) {
|
|
680
|
+
segments.splice(appIndex, 1);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
prefix = segments.length > 0 ? `/${segments.join('/')}/` : '/';
|
|
684
|
+
|
|
685
|
+
// Convert PagesMetadata to SitemapSectionData
|
|
686
|
+
const sitemapData = {
|
|
687
|
+
title: pagesMetadata.title,
|
|
688
|
+
prefix,
|
|
689
|
+
pages: pagesMetadata.pages.map(page => ({
|
|
690
|
+
title: page.title,
|
|
691
|
+
slug: page.slug,
|
|
692
|
+
path: page.path,
|
|
693
|
+
description: page.description,
|
|
694
|
+
keywords: page.keywords,
|
|
695
|
+
sections: page.sections,
|
|
696
|
+
parts: page.parts,
|
|
697
|
+
exports: page.exports,
|
|
698
|
+
tags: page.tags,
|
|
699
|
+
skipDetailSection: page.skipDetailSection,
|
|
700
|
+
image: page.image
|
|
701
|
+
}))
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// Find and update the wrapper component in the AST
|
|
705
|
+
visit(root, node => {
|
|
706
|
+
if (node.type === 'mdxJsxFlowElement' && 'name' in node && node.name === wrapperComponent) {
|
|
707
|
+
// Create the data attribute with expression value
|
|
708
|
+
const dataAttr = {
|
|
709
|
+
type: 'mdxJsxAttribute',
|
|
710
|
+
name: 'data',
|
|
711
|
+
value: {
|
|
712
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
713
|
+
value: JSON.stringify(sitemapData),
|
|
714
|
+
data: {
|
|
715
|
+
estree: {
|
|
716
|
+
type: 'Program',
|
|
717
|
+
sourceType: 'module',
|
|
718
|
+
body: [{
|
|
719
|
+
type: 'ExpressionStatement',
|
|
720
|
+
expression: valueToEstree(sitemapData)
|
|
721
|
+
}]
|
|
876
722
|
}
|
|
877
|
-
node.attributes.push(dataAttr);
|
|
878
723
|
}
|
|
879
724
|
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
shouldExtract = false;
|
|
889
|
-
if (typeof options.extractToIndex === 'boolean') {
|
|
890
|
-
shouldExtract = options.extractToIndex;
|
|
891
|
-
} else {
|
|
892
|
-
_options$extractToInd = options.extractToIndex, _options$extractToInd2 = _options$extractToInd.include, include = _options$extractToInd2 === void 0 ? [] : _options$extractToInd2, _options$extractToInd3 = _options$extractToInd.exclude, exclude = _options$extractToInd3 === void 0 ? [] : _options$extractToInd3, baseDir = _options$extractToInd.baseDir;
|
|
893
|
-
_filePath = file.path; // Strip base directory if provided
|
|
894
|
-
if (baseDir && _filePath.startsWith(baseDir)) {
|
|
895
|
-
_filePath = _filePath.substring(baseDir.length);
|
|
896
|
-
// Remove leading slash if present
|
|
897
|
-
if (_filePath.startsWith('/')) {
|
|
898
|
-
_filePath = _filePath.substring(1);
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
// Add the attribute to the element
|
|
728
|
+
if ('attributes' in node && Array.isArray(node.attributes)) {
|
|
729
|
+
// Remove existing data attribute if present
|
|
730
|
+
const existingIndex = node.attributes.findIndex(attr => attr && typeof attr === 'object' && 'type' in attr && attr.type === 'mdxJsxAttribute' && 'name' in attr && attr.name === 'data');
|
|
731
|
+
if (existingIndex !== -1) {
|
|
732
|
+
node.attributes.splice(existingIndex, 1);
|
|
899
733
|
}
|
|
734
|
+
node.attributes.push(dataAttr);
|
|
900
735
|
}
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
901
741
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
742
|
+
// Update parent index if requested and file path matches filters
|
|
743
|
+
if (options.extractToIndex && metadata && file.path) {
|
|
744
|
+
// Normalize extractToIndex options
|
|
745
|
+
let shouldExtract = false;
|
|
746
|
+
if (typeof options.extractToIndex === 'boolean') {
|
|
747
|
+
shouldExtract = options.extractToIndex;
|
|
748
|
+
} else {
|
|
749
|
+
const {
|
|
750
|
+
include = [],
|
|
751
|
+
exclude = [],
|
|
752
|
+
baseDir
|
|
753
|
+
} = options.extractToIndex;
|
|
754
|
+
let filePath = file.path;
|
|
755
|
+
|
|
756
|
+
// Strip base directory if provided
|
|
757
|
+
if (baseDir && filePath.startsWith(baseDir)) {
|
|
758
|
+
filePath = filePath.substring(baseDir.length);
|
|
759
|
+
// Remove leading slash if present
|
|
760
|
+
if (filePath.startsWith('/')) {
|
|
761
|
+
filePath = filePath.substring(1);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// Normalize path by removing Next.js route groups (parentheses)
|
|
766
|
+
// e.g., "app/(shared)/page.mdx" becomes "app/page.mdx"
|
|
767
|
+
const normalizedPath = filePath.replace(/\/\([^)]+\)/g, '');
|
|
768
|
+
|
|
769
|
+
// Skip if the file is an index file (pattern/page.mdx)
|
|
770
|
+
// This prevents index files from extracting metadata to their parent
|
|
771
|
+
const isIndexFile = include.some(pattern => {
|
|
772
|
+
return normalizedPath === `${pattern}/page.mdx`;
|
|
773
|
+
});
|
|
774
|
+
if (isIndexFile) {
|
|
775
|
+
shouldExtract = false;
|
|
776
|
+
} else {
|
|
777
|
+
// Check if file matches any include pattern (must be inside the directory and not the index itself)
|
|
778
|
+
// The file must start with "pattern/" to ensure it's a child, not a sibling
|
|
779
|
+
// and must not be "pattern/page.mdx" to ensure it's not the index file itself
|
|
780
|
+
const matchedIncludePattern = include.find(pattern => {
|
|
781
|
+
return normalizedPath.startsWith(`${pattern}/`) && normalizedPath !== `${pattern}/page.mdx`;
|
|
782
|
+
});
|
|
783
|
+
const isIncluded = include.length === 0 || matchedIncludePattern !== undefined;
|
|
784
|
+
|
|
785
|
+
// Check if file matches any exclude pattern
|
|
786
|
+
const matchedExcludePattern = exclude.find(pattern => {
|
|
787
|
+
return normalizedPath.startsWith(`${pattern}/`);
|
|
788
|
+
});
|
|
789
|
+
const isExcluded = matchedExcludePattern !== undefined;
|
|
790
|
+
shouldExtract = isIncluded && !isExcluded;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (shouldExtract) {
|
|
794
|
+
try {
|
|
795
|
+
// Determine if we should use visible description instead of meta tag
|
|
796
|
+
const useVisibleDescription = typeof options.extractToIndex !== 'boolean' && options.extractToIndex.useVisibleDescription;
|
|
797
|
+
const pageMetadataOptions = {};
|
|
798
|
+
if (useVisibleDescription && firstParagraphAfterH1) {
|
|
799
|
+
pageMetadataOptions.visibleDescription = firstParagraphAfterH1;
|
|
800
|
+
pageMetadataOptions.visibleDescriptionMarkdown = firstParagraphMarkdown;
|
|
801
|
+
}
|
|
802
|
+
const pageMetadata = toPageMetadata(metadata, file.path, pageMetadataOptions);
|
|
803
|
+
const updateOptions = {
|
|
804
|
+
pagePath: file.path,
|
|
805
|
+
metadata: pageMetadata,
|
|
806
|
+
updateParents: true
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
// Pass through baseDir, include, exclude, onlyUpdateIndexes, and markerDir if they were configured
|
|
810
|
+
if (typeof options.extractToIndex !== 'boolean') {
|
|
811
|
+
if (options.extractToIndex.baseDir) {
|
|
812
|
+
updateOptions.baseDir = options.extractToIndex.baseDir;
|
|
925
813
|
}
|
|
926
|
-
if (
|
|
927
|
-
|
|
928
|
-
break;
|
|
814
|
+
if (options.extractToIndex.include) {
|
|
815
|
+
updateOptions.include = options.extractToIndex.include;
|
|
929
816
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
useVisibleDescription = typeof options.extractToIndex !== 'boolean' && options.extractToIndex.useVisibleDescription;
|
|
933
|
-
pageMetadataOptions = {};
|
|
934
|
-
if (useVisibleDescription && firstParagraphAfterH1) {
|
|
935
|
-
pageMetadataOptions.visibleDescription = firstParagraphAfterH1;
|
|
936
|
-
pageMetadataOptions.visibleDescriptionMarkdown = firstParagraphMarkdown;
|
|
817
|
+
if (options.extractToIndex.exclude) {
|
|
818
|
+
updateOptions.exclude = options.extractToIndex.exclude;
|
|
937
819
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
944
|
-
if (
|
|
945
|
-
|
|
946
|
-
updateOptions.baseDir = options.extractToIndex.baseDir;
|
|
947
|
-
}
|
|
948
|
-
if (options.extractToIndex.include) {
|
|
949
|
-
updateOptions.include = options.extractToIndex.include;
|
|
950
|
-
}
|
|
951
|
-
if (options.extractToIndex.exclude) {
|
|
952
|
-
updateOptions.exclude = options.extractToIndex.exclude;
|
|
953
|
-
}
|
|
954
|
-
if (options.extractToIndex.onlyUpdateIndexes !== undefined) {
|
|
955
|
-
updateOptions.onlyUpdateIndexes = options.extractToIndex.onlyUpdateIndexes;
|
|
956
|
-
}
|
|
957
|
-
if (options.extractToIndex.markerDir !== undefined) {
|
|
958
|
-
updateOptions.markerDir = options.extractToIndex.markerDir;
|
|
959
|
-
}
|
|
960
|
-
if (options.extractToIndex.errorIfOutOfDate !== undefined) {
|
|
961
|
-
updateOptions.errorIfOutOfDate = options.extractToIndex.errorIfOutOfDate;
|
|
962
|
-
}
|
|
963
|
-
if (options.extractToIndex.indexWrapperComponent) {
|
|
964
|
-
updateOptions.indexWrapperComponent = options.extractToIndex.indexWrapperComponent;
|
|
965
|
-
}
|
|
820
|
+
if (options.extractToIndex.onlyUpdateIndexes !== undefined) {
|
|
821
|
+
updateOptions.onlyUpdateIndexes = options.extractToIndex.onlyUpdateIndexes;
|
|
822
|
+
}
|
|
823
|
+
if (options.extractToIndex.markerDir !== undefined) {
|
|
824
|
+
updateOptions.markerDir = options.extractToIndex.markerDir;
|
|
825
|
+
}
|
|
826
|
+
if (options.extractToIndex.errorIfOutOfDate !== undefined) {
|
|
827
|
+
updateOptions.errorIfOutOfDate = options.extractToIndex.errorIfOutOfDate;
|
|
966
828
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
// Don't fail the build if index update fails
|
|
976
|
-
console.error('Failed to update page index for', file.path, _t);
|
|
977
|
-
case 6:
|
|
978
|
-
return _context.a(2);
|
|
829
|
+
if (options.extractToIndex.indexWrapperComponent) {
|
|
830
|
+
updateOptions.indexWrapperComponent = options.extractToIndex.indexWrapperComponent;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
await syncPageIndex(updateOptions);
|
|
834
|
+
} catch (error) {
|
|
835
|
+
// Don't fail the build if index update fails
|
|
836
|
+
console.error('Failed to update page index for', file.path, error);
|
|
979
837
|
}
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
return _ref5.apply(this, arguments);
|
|
984
|
-
};
|
|
985
|
-
}();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
};
|
|
986
841
|
};
|