Skip to content

Commit 1639667

Browse files
committed
Add SEO checker to tasks workflow
1 parent ad7b07e commit 1639667

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

.vscode/tasks.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@
172172
"panel": "shared"
173173
},
174174
"problemMatcher": []
175-
}
175+
},
176+
{
177+
"label": "SEO Check (current article)",
178+
"type": "shell",
179+
"command": "node scripts/seo-check/seo-check.js \"${file}\"",
180+
"options": {
181+
"cwd": "${workspaceFolder}"
182+
},
183+
"windows": {
184+
"command": "node .\\scripts\\seo-check\\seo-check.js \"${file}\""
185+
},
186+
"group": "none",
187+
"presentation": {
188+
"reveal": "always",
189+
"panel": "shared"
190+
},
191+
"problemMatcher": []
192+
}
176193
]
177194
}

package-lock.json

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"homepage": "https://github.com/arduino/docs-content#readme",
2020
"dependencies": {
2121
"@arduino/docs-arduino-cc": "^2.0.29",
22+
"dotenv": "^16.4.7",
2223
"gatsby": "^5.11.0",
2324
"gatsby-background-image": "^1.6.0",
2425
"gatsby-image": "^3.11.0",

scripts/seo-check/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules

scripts/seo-check/seo-check.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require('dotenv').config({ path: __dirname + '/.env' });
2+
const fs = require('fs');
3+
const path = require('path');
4+
const OpenAI = require('openai');
5+
6+
// 1. Get file path from arguments
7+
const filePath = process.argv[2];
8+
if (!filePath) {
9+
console.error('❌ No file path provided.');
10+
process.exit(1);
11+
}
12+
13+
// 2. Read file content
14+
const content = fs.readFileSync(filePath, 'utf8');
15+
16+
// 3. Set up OpenAI client (v4 style)
17+
const openai = new OpenAI({
18+
apiKey: process.env.OPENAI_API_KEY,
19+
});
20+
21+
// 4. Send to OpenAI
22+
(async () => {
23+
try {
24+
const chatCompletion = await openai.chat.completions.create({
25+
model: 'gpt-4',
26+
messages: [
27+
{ role: 'system', content: 'You are a helpful SEO and content writing assistant.' },
28+
{ role: 'user', content: `Please review and improve this Markdown article for SEO:\n\n${content}` }
29+
],
30+
});
31+
32+
const result = chatCompletion.choices[0].message.content;
33+
console.log('\n💬 Response from OpenAI:\n');
34+
console.log(result);
35+
36+
// Optional: write to file
37+
const outputPath = filePath.replace(/\.md$/, '.openai.md');
38+
fs.writeFileSync(outputPath, result, 'utf8');
39+
console.log(`\n✅ Response saved to: ${outputPath}`);
40+
} catch (err) {
41+
console.error('⚠️ Error communicating with OpenAI:', err);
42+
}
43+
})();

0 commit comments

Comments
 (0)