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