Skip to content

Commit 8d89011

Browse files
style: run prettier
1 parent 0f658e4 commit 8d89011

File tree

4 files changed

+74
-35
lines changed

4 files changed

+74
-35
lines changed

.github/workflows/migrate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch:
99
inputs:
1010
issue_number:
11-
description: 'Specific issue number to process (optional)'
11+
description: "Specific issue number to process (optional)"
1212
required: false
1313
type: string
1414

@@ -46,4 +46,4 @@ jobs:
4646
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
4747
GITHUB_REPOSITORY: ${{ github.repository }}
4848
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
49-
run: npm run migrate
49+
run: npm run migrate

migrate/migrate-bot.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,43 @@ async function fetchPageContent(url) {
5555
}
5656

5757
async function convertToMDX(html, title, url) {
58-
const prompt = await readFile(__dirname + "/PROMPT.md", "utf8")
59-
.replace("{{LLM_DOCS}}", await readFile(__dirname + "/../src/content/docs/development/guide/component-docs-for-llm.mdx", "utf8"));
60-
61-
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
62-
method: "POST",
63-
headers: {
64-
Authorization: `Bearer ${OPENROUTER_API_KEY}`,
65-
"Content-Type": "application/json",
66-
"HTTP-Referer": "https://github.com/cppdoc/cppdoc",
67-
"X-Title": "CppDoc Migration Bot",
68-
},
69-
body: JSON.stringify({
70-
model: "deepseek/deepseek-v3.2",
71-
messages: [
72-
{ role: "system", content: prompt },
73-
{ role: "user", content:
74-
`
58+
const prompt = await readFile(__dirname + "/PROMPT.md", "utf8").replace(
59+
"{{LLM_DOCS}}",
60+
await readFile(
61+
__dirname +
62+
"/../src/content/docs/development/guide/component-docs-for-llm.mdx",
63+
"utf8",
64+
),
65+
);
66+
67+
const response = await fetch(
68+
"https://openrouter.ai/api/v1/chat/completions",
69+
{
70+
method: "POST",
71+
headers: {
72+
Authorization: `Bearer ${OPENROUTER_API_KEY}`,
73+
"Content-Type": "application/json",
74+
"HTTP-Referer": "https://github.com/cppdoc/cppdoc",
75+
"X-Title": "CppDoc Migration Bot",
76+
},
77+
body: JSON.stringify({
78+
model: "deepseek/deepseek-v3.2",
79+
messages: [
80+
{ role: "system", content: prompt },
81+
{
82+
role: "user",
83+
content: `
7584
// Convert the following HTML content from cppreference.com into MDX format suitable for CppDoc.
7685
// Title: ${title}
7786
// URL: ${url}
7887
// HTML Content:
7988
${html}
80-
`
81-
}
82-
],
83-
}),
84-
});
89+
`,
90+
},
91+
],
92+
}),
93+
},
94+
);
8595

8696
if (!response.ok) {
8797
const error = await response.text();
@@ -99,7 +109,14 @@ function getLocalPath(url) {
99109
throw new Error(`无法从URL解析路径: ${url}`);
100110
}
101111
const relative = match[1]; // "cpp/comments"
102-
return path.join(__dirname, "..", "src", "content", "docs", `${relative}.mdx`);
112+
return path.join(
113+
__dirname,
114+
"..",
115+
"src",
116+
"content",
117+
"docs",
118+
`${relative}.mdx`,
119+
);
103120
}
104121

105122
async function writeMDXFile(filePath, content, title) {
@@ -122,7 +139,9 @@ async function createPullRequest(issue, filePath, url) {
122139
const { execSync } = await import("child_process");
123140
try {
124141
execSync(`git config user.name "github-actions[bot]"`);
125-
execSync(`git config user.email "github-actions[bot]@users.noreply.github.com"`);
142+
execSync(
143+
`git config user.email "github-actions[bot]@users.noreply.github.com"`,
144+
);
126145
execSync(`git checkout -b ${branchName}`);
127146
execSync(`git add "${filePath}"`);
128147
execSync(`git commit -m "${commitMessage}"`);
@@ -235,4 +254,4 @@ async function main() {
235254
main().catch((err) => {
236255
console.error(err);
237256
process.exit(1);
238-
});
257+
});

src/components/index.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@ import { DescList, Desc } from "@components/desc-list";
44
import { ParamDocList, ParamDoc } from "@components/param-doc";
55
import DocLink from "@components/DocLink.astro";
66
import { CHeader, CppHeader } from "@components/header";
7-
import { FeatureTestMacro, FeatureTestMacroValue } from "@components/feature-test-macro";
7+
import {
8+
FeatureTestMacro,
9+
FeatureTestMacroValue,
10+
} from "@components/feature-test-macro";
811
import { DR, DRList } from "@components/defect-report";
912
import { Revision, RevisionBlock } from "@components/revision";
1013
import AutoCollapse from "@components/AutoCollapse.astro";
1114
import FlexTable from "@components/FlexTable.astro";
1215
import WG21PaperLink from "@components/WG21PaperLink.astro";
1316

1417
export {
15-
Behavior, Decl, DeclDoc, DescList, Desc, ParamDocList, ParamDoc, DocLink,
16-
CHeader, CppHeader, FeatureTestMacro, FeatureTestMacroValue, DR, DRList,
17-
Revision, RevisionBlock, AutoCollapse, FlexTable, WG21PaperLink
18-
};
18+
Behavior,
19+
Decl,
20+
DeclDoc,
21+
DescList,
22+
Desc,
23+
ParamDocList,
24+
ParamDoc,
25+
DocLink,
26+
CHeader,
27+
CppHeader,
28+
FeatureTestMacro,
29+
FeatureTestMacroValue,
30+
DR,
31+
DRList,
32+
Revision,
33+
RevisionBlock,
34+
AutoCollapse,
35+
FlexTable,
36+
WG21PaperLink,
37+
};

src/lib/doc-index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ async function getOrBuildKeyIndex(): Promise<Map<string, string>> {
5858
export async function getLinkToKey(key: string): Promise<string | undefined> {
5959
const index = await getOrBuildKeyIndex();
6060
if (key?.startsWith("/")) {
61-
if (index.values().some(slug => `/${slug}/` === key || `/${slug}` === key))
61+
if (
62+
index.values().some((slug) => `/${slug}/` === key || `/${slug}` === key)
63+
)
6264
return key;
63-
else
64-
return undefined;
65+
else return undefined;
6566
}
6667
const slug = index.get(key);
6768
if (!slug) return undefined;

0 commit comments

Comments
 (0)