@@ -55,33 +55,43 @@ async function fetchPageContent(url) {
5555}
5656
5757async 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
105122async 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() {
235254main ( ) . catch ( ( err ) => {
236255 console . error ( err ) ;
237256 process . exit ( 1 ) ;
238- } ) ;
257+ } ) ;
0 commit comments