Skip to content

Commit f576d20

Browse files
fix: auto import components for llm
1 parent 8983da9 commit f576d20

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

migrate/PROMPT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
You are a professional C++ documentation writer. You are now migrating cppreference.com documentation from HTML format to MDX format. During this process, you must adhere to the following rules:
22
1. Only migrate the format, ensuring that the text of the migrated result is **exactly the same** as the original. Of course, you don't need to process text that was originally invisible.
3-
2. When using the pre-provided component library, import and only import the component you used. Do not try to write your own component. Do not try to write your own component. Do not try to write your own component. DO NOT USE NORMAL HTML ELEMENTS. DO NOT USE <table>, <tr> <td>. Replace them with our MDX component or markdown grammer.
3+
2. Do not try to write your own component. Do not try to write your own component. Do not try to write your own component. DO NOT USE NORMAL HTML ELEMENTS. DO NOT USE <table>, <tr> <td>. Replace them with our MDX component or markdown grammer.
44
3. For links, take the URL part, remove `/w/` and the latter part `.html`, and then wrap it with `DocLink`. For example:
55
If the current path is: `/w/cpp/language/basics.html`
66
Link: `<a href="declarations.html" title="cpp/language/declarations">declarations</a>`

migrate/migrate-bot.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ ${html}
109109
content = content.slice(content.indexOf("```mdx") + 6, content.lastIndexOf("```")).trim();
110110
}
111111

112+
// Auto Import
113+
const components = [
114+
'Behavior',
115+
'Decl',
116+
'DeclDoc',
117+
'DescList',
118+
'Desc',
119+
'ParamDocList',
120+
'ParamDoc',
121+
'DocLink',
122+
'CHeader',
123+
'CppHeader',
124+
'FeatureTestMacro',
125+
'FeatureTestMacroValue',
126+
'DR',
127+
'DRList',
128+
'Revision',
129+
'RevisionBlock',
130+
'AutoCollapse',
131+
'FlexTable',
132+
'WG21PaperLink',
133+
]
134+
135+
const usedComponents = components.filter((comp) => content.includes(`<${comp} `) || content.includes(`<${comp}>`));
136+
137+
// Remove all existing import statements
138+
content = content.split('\n').filter(line => !line.startsWith('import ')).join('\n');
139+
140+
// Sort used components alphabetically
141+
usedComponents.sort();
142+
143+
if (usedComponents.length > 0) {
144+
const importStatements = `import { ${usedComponents.join(', ')} } from '@/components/index.ts';\n\n`;
145+
content = importStatements + content;
146+
}
147+
112148
return content;
113149
}
114150

0 commit comments

Comments
 (0)