@edtools/cli 0.4.1 → 0.6.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/dist/adapters/html/index.d.ts.map +1 -1
- package/dist/adapters/html/index.js +14 -3
- package/dist/adapters/html/index.js.map +1 -1
- package/dist/adapters/html/templates/blog-index.html.ejs +342 -0
- package/dist/adapters/html/templates/blog-post.html.ejs +48 -0
- package/dist/chunk-AJSCN4WK.js +663 -0
- package/dist/chunk-INVECVSW.js +45 -0
- package/dist/chunk-JCUQ7D56.js +688 -0
- package/dist/chunk-UMREI3K7.js +652 -0
- package/dist/chunk-ZDV7BJZ4.js +652 -0
- package/dist/chunk-ZG6JJCRI.js +539 -0
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +114 -38
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +9 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +196 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/index.js +535 -46
- package/dist/cli/index.js.map +1 -1
- package/dist/content-helpers-TXVEJMQK.js +16 -0
- package/dist/core/generator.d.ts +2 -0
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/generator.js +148 -10
- package/dist/core/generator.js.map +1 -1
- package/dist/index.d.ts +92 -1
- package/dist/index.js +2 -1
- package/dist/types/content.d.ts +89 -0
- package/dist/types/content.d.ts.map +1 -1
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +9 -1
- package/dist/ui/banner.js.map +1 -1
- package/dist/utils/content-helpers.d.ts +7 -0
- package/dist/utils/content-helpers.d.ts.map +1 -0
- package/dist/utils/content-helpers.js +48 -0
- package/dist/utils/content-helpers.js.map +1 -0
- package/dist/utils/seo-validator.d.ts +35 -0
- package/dist/utils/seo-validator.d.ts.map +1 -0
- package/dist/utils/seo-validator.js +244 -0
- package/dist/utils/seo-validator.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculateReadTime,
|
|
3
|
+
calculateWordCount,
|
|
4
|
+
extractShortDescription,
|
|
5
|
+
generateTimestamp,
|
|
6
|
+
generateUUID
|
|
7
|
+
} from "./chunk-INVECVSW.js";
|
|
8
|
+
|
|
9
|
+
// src/types/adapter.ts
|
|
10
|
+
var AdapterRegistry = class {
|
|
11
|
+
adapters;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.adapters = /* @__PURE__ */ new Map();
|
|
14
|
+
}
|
|
15
|
+
register(adapter) {
|
|
16
|
+
this.adapters.set(adapter.name, adapter);
|
|
17
|
+
}
|
|
18
|
+
get(name) {
|
|
19
|
+
return this.adapters.get(name);
|
|
20
|
+
}
|
|
21
|
+
async detectAdapter(projectPath) {
|
|
22
|
+
for (const adapter of this.adapters.values()) {
|
|
23
|
+
if (await adapter.detect(projectPath)) {
|
|
24
|
+
return adapter;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
list() {
|
|
30
|
+
return Array.from(this.adapters.keys());
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/adapters/html/index.ts
|
|
35
|
+
import fs from "fs-extra";
|
|
36
|
+
import path from "path";
|
|
37
|
+
import { fileURLToPath } from "url";
|
|
38
|
+
import ejs from "ejs";
|
|
39
|
+
import { marked } from "marked";
|
|
40
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
41
|
+
var __dirname = path.dirname(__filename);
|
|
42
|
+
var HTMLAdapter = class {
|
|
43
|
+
name = "html";
|
|
44
|
+
async detect(projectPath) {
|
|
45
|
+
try {
|
|
46
|
+
const files = await fs.readdir(projectPath);
|
|
47
|
+
const hasHtmlInRoot = files.some((f) => f.endsWith(".html"));
|
|
48
|
+
const hasIndexHtml = await fs.pathExists(path.join(projectPath, "index.html"));
|
|
49
|
+
const commonDirs = ["public", "dist", "build", "src"];
|
|
50
|
+
for (const dir of commonDirs) {
|
|
51
|
+
const dirPath = path.join(projectPath, dir);
|
|
52
|
+
if (await fs.pathExists(dirPath)) {
|
|
53
|
+
const dirFiles = await fs.readdir(dirPath);
|
|
54
|
+
const hasHtmlInDir = dirFiles.some((f) => f.endsWith(".html"));
|
|
55
|
+
if (hasHtmlInDir) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return hasHtmlInRoot || hasIndexHtml;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async render(content) {
|
|
66
|
+
const templatePath = path.join(__dirname, "templates", "blog-post.html.ejs");
|
|
67
|
+
if (!await fs.pathExists(templatePath)) {
|
|
68
|
+
throw new Error(`Template not found at: ${templatePath}`);
|
|
69
|
+
}
|
|
70
|
+
const template = await fs.readFile(templatePath, "utf-8");
|
|
71
|
+
const templateData = {
|
|
72
|
+
metadata: content.metadata,
|
|
73
|
+
schemaOrg: JSON.stringify(content.schemaOrg, null, 2),
|
|
74
|
+
intro: await this.markdownToHTML(content.content.intro),
|
|
75
|
+
sections: await Promise.all(
|
|
76
|
+
content.content.sections.map(async (section) => ({
|
|
77
|
+
...section,
|
|
78
|
+
content: await this.renderSectionContent(section)
|
|
79
|
+
}))
|
|
80
|
+
),
|
|
81
|
+
conclusion: await this.markdownToHTML(content.content.conclusion),
|
|
82
|
+
cta: content.content.cta,
|
|
83
|
+
relatedPosts: content.relatedPosts || [],
|
|
84
|
+
seoScore: content.seo.score
|
|
85
|
+
};
|
|
86
|
+
const html = ejs.render(template, templateData);
|
|
87
|
+
return html;
|
|
88
|
+
}
|
|
89
|
+
async write(output, outputPath) {
|
|
90
|
+
await fs.ensureDir(path.dirname(outputPath));
|
|
91
|
+
await fs.writeFile(outputPath, output, "utf-8");
|
|
92
|
+
}
|
|
93
|
+
getFileExtension() {
|
|
94
|
+
return ".html";
|
|
95
|
+
}
|
|
96
|
+
transformPath(basePath) {
|
|
97
|
+
if (!basePath.endsWith(".html")) {
|
|
98
|
+
return basePath + ".html";
|
|
99
|
+
}
|
|
100
|
+
return basePath;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Convert markdown to HTML
|
|
104
|
+
*/
|
|
105
|
+
async markdownToHTML(markdown) {
|
|
106
|
+
return marked(markdown);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Render section content based on type
|
|
110
|
+
*/
|
|
111
|
+
async renderSectionContent(section) {
|
|
112
|
+
switch (section.type) {
|
|
113
|
+
case "text":
|
|
114
|
+
return await this.markdownToHTML(section.content);
|
|
115
|
+
case "comparison":
|
|
116
|
+
return this.renderComparisonTable(section.data);
|
|
117
|
+
case "list":
|
|
118
|
+
return this.renderList(section.data);
|
|
119
|
+
case "code":
|
|
120
|
+
return this.renderCode(section.data);
|
|
121
|
+
default:
|
|
122
|
+
return await this.markdownToHTML(section.content);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Render comparison table
|
|
127
|
+
*/
|
|
128
|
+
renderComparisonTable(data) {
|
|
129
|
+
if (!data || !data.headers || !data.rows) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
let html = '<table class="comparison-table">\n';
|
|
133
|
+
html += " <thead>\n <tr>\n";
|
|
134
|
+
data.headers.forEach((header) => {
|
|
135
|
+
html += ` <th>${header}</th>
|
|
136
|
+
`;
|
|
137
|
+
});
|
|
138
|
+
html += " </tr>\n </thead>\n";
|
|
139
|
+
html += " <tbody>\n";
|
|
140
|
+
data.rows.forEach((row) => {
|
|
141
|
+
html += " <tr>\n";
|
|
142
|
+
row.forEach((cell) => {
|
|
143
|
+
html += ` <td>${cell}</td>
|
|
144
|
+
`;
|
|
145
|
+
});
|
|
146
|
+
html += " </tr>\n";
|
|
147
|
+
});
|
|
148
|
+
html += " </tbody>\n";
|
|
149
|
+
html += "</table>";
|
|
150
|
+
return html;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Render list
|
|
154
|
+
*/
|
|
155
|
+
renderList(data) {
|
|
156
|
+
if (!data || !data.items) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
const tag = data.ordered ? "ol" : "ul";
|
|
160
|
+
let html = `<${tag} class="content-list">
|
|
161
|
+
`;
|
|
162
|
+
data.items.forEach((item) => {
|
|
163
|
+
html += " <li>\n";
|
|
164
|
+
html += ` <strong>${item.title}</strong>
|
|
165
|
+
`;
|
|
166
|
+
if (item.description) {
|
|
167
|
+
html += ` <p>${item.description}</p>
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
html += " </li>\n";
|
|
171
|
+
});
|
|
172
|
+
html += `</${tag}>`;
|
|
173
|
+
return html;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Render code block
|
|
177
|
+
*/
|
|
178
|
+
renderCode(data) {
|
|
179
|
+
if (!data || !data.code) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
let html = '<div class="code-block">\n';
|
|
183
|
+
if (data.caption) {
|
|
184
|
+
html += ` <div class="code-caption">${data.caption}</div>
|
|
185
|
+
`;
|
|
186
|
+
}
|
|
187
|
+
html += ` <pre><code class="language-${data.language || "plaintext"}">${this.escapeHtml(data.code)}</code></pre>
|
|
188
|
+
`;
|
|
189
|
+
html += "</div>";
|
|
190
|
+
return html;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Escape HTML entities
|
|
194
|
+
*/
|
|
195
|
+
escapeHtml(text) {
|
|
196
|
+
const map = {
|
|
197
|
+
"&": "&",
|
|
198
|
+
"<": "<",
|
|
199
|
+
">": ">",
|
|
200
|
+
'"': """,
|
|
201
|
+
"'": "'"
|
|
202
|
+
};
|
|
203
|
+
return text.replace(/[&<>"']/g, (m) => map[m]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/core/generator.ts
|
|
208
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
209
|
+
import OpenAI from "openai";
|
|
210
|
+
import path2 from "path";
|
|
211
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
212
|
+
import fs2 from "fs-extra";
|
|
213
|
+
import slugify from "slugify";
|
|
214
|
+
var ContentGenerator = class {
|
|
215
|
+
anthropic = null;
|
|
216
|
+
openai = null;
|
|
217
|
+
provider;
|
|
218
|
+
adapters;
|
|
219
|
+
constructor(apiKey, provider = "anthropic") {
|
|
220
|
+
this.provider = provider;
|
|
221
|
+
if (provider === "anthropic") {
|
|
222
|
+
this.anthropic = new Anthropic({
|
|
223
|
+
apiKey: apiKey || process.env.ANTHROPIC_API_KEY || ""
|
|
224
|
+
});
|
|
225
|
+
} else if (provider === "openai") {
|
|
226
|
+
this.openai = new OpenAI({
|
|
227
|
+
apiKey: apiKey || process.env.OPENAI_API_KEY || ""
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
this.adapters = new AdapterRegistry();
|
|
231
|
+
this.adapters.register(new HTMLAdapter());
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Main generate method
|
|
235
|
+
*/
|
|
236
|
+
async generate(config) {
|
|
237
|
+
const results = {
|
|
238
|
+
success: true,
|
|
239
|
+
posts: [],
|
|
240
|
+
warnings: [],
|
|
241
|
+
errors: []
|
|
242
|
+
};
|
|
243
|
+
const allPostsContent = [];
|
|
244
|
+
try {
|
|
245
|
+
const adapter = await this.adapters.detectAdapter(config.projectPath);
|
|
246
|
+
if (!adapter) {
|
|
247
|
+
throw new Error("No suitable adapter found for this project");
|
|
248
|
+
}
|
|
249
|
+
console.log(`\u2713 Using adapter: ${adapter.name}`);
|
|
250
|
+
const topics = config.topics || await this.generateTopics(config.productInfo, config.count || 3);
|
|
251
|
+
for (const topic of topics.slice(0, config.count || 3)) {
|
|
252
|
+
try {
|
|
253
|
+
console.log(`
|
|
254
|
+
\u{1F4DD} Generating: ${topic}`);
|
|
255
|
+
const content = await this.generateContent(config.productInfo, topic);
|
|
256
|
+
const output = await adapter.render(content);
|
|
257
|
+
const slug = content.metadata.slug;
|
|
258
|
+
const fileName = adapter.transformPath?.(slug) || `${slug}/index${adapter.getFileExtension()}`;
|
|
259
|
+
const outputPath = path2.join(config.outputDir, fileName);
|
|
260
|
+
await adapter.write(output, outputPath);
|
|
261
|
+
allPostsContent.push(content);
|
|
262
|
+
results.posts.push({
|
|
263
|
+
id: content.metadata.id,
|
|
264
|
+
title: content.metadata.title,
|
|
265
|
+
slug,
|
|
266
|
+
path: outputPath,
|
|
267
|
+
url: content.metadata.url,
|
|
268
|
+
seoScore: content.seo.score,
|
|
269
|
+
readTime: content.metadata.readTime,
|
|
270
|
+
wordCount: content.metadata.wordCount
|
|
271
|
+
});
|
|
272
|
+
console.log(`\u2713 Generated: ${outputPath}`);
|
|
273
|
+
console.log(` SEO Score: ${content.seo.score}/100`);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
results.errors?.push(`Failed to generate "${topic}": ${error.message}`);
|
|
276
|
+
results.success = false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (results.posts.length > 0 && allPostsContent.length > 0) {
|
|
280
|
+
await this.generateManifest(config.outputDir, config.productInfo, allPostsContent);
|
|
281
|
+
await this.generateBlogIndex(config.outputDir, config.productInfo);
|
|
282
|
+
await this.updateSitemap(config.projectPath, config.outputDir, allPostsContent);
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
results.success = false;
|
|
286
|
+
results.errors?.push(error.message);
|
|
287
|
+
}
|
|
288
|
+
return results;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Generate blog post content using the selected AI provider
|
|
292
|
+
*/
|
|
293
|
+
async generateContent(productInfo, topic) {
|
|
294
|
+
const prompt = this.buildPrompt(productInfo, topic);
|
|
295
|
+
let contentData;
|
|
296
|
+
if (this.provider === "anthropic") {
|
|
297
|
+
contentData = await this.generateWithAnthropic(prompt);
|
|
298
|
+
} else if (this.provider === "openai") {
|
|
299
|
+
contentData = await this.generateWithOpenAI(prompt);
|
|
300
|
+
} else {
|
|
301
|
+
throw new Error(`Unsupported provider: ${this.provider}`);
|
|
302
|
+
}
|
|
303
|
+
const id = generateUUID();
|
|
304
|
+
const slug = slugify(contentData.metadata.title, { lower: true, strict: true });
|
|
305
|
+
const datePublished = generateTimestamp();
|
|
306
|
+
const url = `/blog/${slug}.html`;
|
|
307
|
+
const fullContent = [
|
|
308
|
+
contentData.content.intro,
|
|
309
|
+
...contentData.content.sections.map((s) => s.content),
|
|
310
|
+
contentData.content.conclusion
|
|
311
|
+
].join(" ");
|
|
312
|
+
const wordCount = calculateWordCount(fullContent);
|
|
313
|
+
const readTime = calculateReadTime(wordCount);
|
|
314
|
+
const shortDescription = extractShortDescription(contentData.content.intro);
|
|
315
|
+
const tags = contentData.metadata.keywords.slice(0, 5);
|
|
316
|
+
const content = {
|
|
317
|
+
metadata: {
|
|
318
|
+
id,
|
|
319
|
+
...contentData.metadata,
|
|
320
|
+
slug,
|
|
321
|
+
url,
|
|
322
|
+
datePublished,
|
|
323
|
+
author: productInfo.name,
|
|
324
|
+
readTime,
|
|
325
|
+
wordCount,
|
|
326
|
+
tags,
|
|
327
|
+
shortDescription,
|
|
328
|
+
fullDescription: contentData.content.intro
|
|
329
|
+
},
|
|
330
|
+
schemaOrg: this.generateSchemaOrg({
|
|
331
|
+
id,
|
|
332
|
+
...contentData.metadata,
|
|
333
|
+
slug,
|
|
334
|
+
url,
|
|
335
|
+
datePublished,
|
|
336
|
+
author: productInfo.name,
|
|
337
|
+
readTime,
|
|
338
|
+
wordCount,
|
|
339
|
+
tags
|
|
340
|
+
}, productInfo),
|
|
341
|
+
content: contentData.content,
|
|
342
|
+
relatedPosts: [],
|
|
343
|
+
seo: await this.calculateSEOScore(contentData)
|
|
344
|
+
};
|
|
345
|
+
return content;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Generate content using Anthropic's Claude API
|
|
349
|
+
*/
|
|
350
|
+
async generateWithAnthropic(prompt) {
|
|
351
|
+
if (!this.anthropic) {
|
|
352
|
+
throw new Error("Anthropic client not initialized");
|
|
353
|
+
}
|
|
354
|
+
const response = await this.anthropic.messages.create({
|
|
355
|
+
model: "claude-3-5-sonnet-20241022",
|
|
356
|
+
max_tokens: 4096,
|
|
357
|
+
temperature: 0.7,
|
|
358
|
+
messages: [
|
|
359
|
+
{
|
|
360
|
+
role: "user",
|
|
361
|
+
content: prompt
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
});
|
|
365
|
+
const textContent = response.content[0].type === "text" ? response.content[0].text : "";
|
|
366
|
+
const jsonMatch = textContent.match(/\{[\s\S]*\}/);
|
|
367
|
+
if (!jsonMatch) {
|
|
368
|
+
throw new Error("Failed to extract JSON from Claude response");
|
|
369
|
+
}
|
|
370
|
+
return JSON.parse(jsonMatch[0]);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Generate content using OpenAI's ChatGPT API
|
|
374
|
+
*/
|
|
375
|
+
async generateWithOpenAI(prompt) {
|
|
376
|
+
if (!this.openai) {
|
|
377
|
+
throw new Error("OpenAI client not initialized");
|
|
378
|
+
}
|
|
379
|
+
const response = await this.openai.chat.completions.create({
|
|
380
|
+
model: "gpt-4-turbo-preview",
|
|
381
|
+
max_tokens: 4096,
|
|
382
|
+
temperature: 0.7,
|
|
383
|
+
messages: [
|
|
384
|
+
{
|
|
385
|
+
role: "user",
|
|
386
|
+
content: prompt
|
|
387
|
+
}
|
|
388
|
+
],
|
|
389
|
+
response_format: { type: "json_object" }
|
|
390
|
+
});
|
|
391
|
+
const textContent = response.choices[0]?.message?.content || "";
|
|
392
|
+
if (!textContent) {
|
|
393
|
+
throw new Error("Failed to get response from OpenAI");
|
|
394
|
+
}
|
|
395
|
+
return JSON.parse(textContent);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Build prompt for Claude API
|
|
399
|
+
*/
|
|
400
|
+
buildPrompt(productInfo, topic) {
|
|
401
|
+
return `You are an expert SEO content writer. Generate a comprehensive blog post about: "${topic}"
|
|
402
|
+
|
|
403
|
+
Product context:
|
|
404
|
+
- Name: ${productInfo.name}
|
|
405
|
+
- Tagline: ${productInfo.tagline || ""}
|
|
406
|
+
- Category: ${productInfo.category}
|
|
407
|
+
- Features: ${productInfo.features.join(", ")}
|
|
408
|
+
- Pricing: ${productInfo.pricingModel || "Not specified"}
|
|
409
|
+
${productInfo.useCases ? `- Use cases: ${productInfo.useCases.join(", ")}` : ""}
|
|
410
|
+
|
|
411
|
+
IMPORTANT INSTRUCTIONS:
|
|
412
|
+
1. Write for users searching on Google and being recommended by AI assistants (Claude, ChatGPT)
|
|
413
|
+
2. Focus on being helpful, not promotional
|
|
414
|
+
3. Include comparisons with alternatives when relevant
|
|
415
|
+
4. Use natural language, avoid keyword stuffing
|
|
416
|
+
5. Make it comprehensive (1000-1500 words worth of content)
|
|
417
|
+
6. Structure with clear sections (intro, 3-5 main sections, conclusion)
|
|
418
|
+
7. Be factual - do NOT invent statistics or make false claims
|
|
419
|
+
|
|
420
|
+
Output ONLY valid JSON in this exact format (no markdown, no code blocks):
|
|
421
|
+
{
|
|
422
|
+
"metadata": {
|
|
423
|
+
"title": "SEO-optimized title (under 60 chars)",
|
|
424
|
+
"description": "Meta description (under 160 chars)",
|
|
425
|
+
"keywords": ["keyword1", "keyword2", "keyword3"],
|
|
426
|
+
"category": "${productInfo.category}"
|
|
427
|
+
},
|
|
428
|
+
"content": {
|
|
429
|
+
"intro": "Engaging introduction paragraph in markdown format",
|
|
430
|
+
"sections": [
|
|
431
|
+
{
|
|
432
|
+
"heading": "Section title",
|
|
433
|
+
"level": 2,
|
|
434
|
+
"content": "Section content in markdown format",
|
|
435
|
+
"type": "text"
|
|
436
|
+
}
|
|
437
|
+
],
|
|
438
|
+
"conclusion": "Conclusion paragraph in markdown",
|
|
439
|
+
"cta": {
|
|
440
|
+
"text": "Try ${productInfo.name}",
|
|
441
|
+
"url": "${productInfo.websiteUrl || "/signup"}"
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}`;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Generate Schema.org structured data
|
|
448
|
+
*/
|
|
449
|
+
generateSchemaOrg(metadata, productInfo) {
|
|
450
|
+
return {
|
|
451
|
+
"@context": "https://schema.org",
|
|
452
|
+
"@type": "BlogPosting",
|
|
453
|
+
headline: metadata.title,
|
|
454
|
+
description: metadata.description,
|
|
455
|
+
author: {
|
|
456
|
+
"@type": "Organization",
|
|
457
|
+
name: productInfo.name,
|
|
458
|
+
url: productInfo.websiteUrl
|
|
459
|
+
},
|
|
460
|
+
datePublished: metadata.datePublished,
|
|
461
|
+
publisher: {
|
|
462
|
+
"@type": "Organization",
|
|
463
|
+
name: productInfo.name
|
|
464
|
+
},
|
|
465
|
+
keywords: metadata.keywords.join(", "),
|
|
466
|
+
articleSection: metadata.category
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Calculate SEO score
|
|
471
|
+
*/
|
|
472
|
+
async calculateSEOScore(content) {
|
|
473
|
+
let score = 100;
|
|
474
|
+
const suggestions = [];
|
|
475
|
+
if (content.metadata.title.length > 60) {
|
|
476
|
+
score -= 10;
|
|
477
|
+
suggestions.push("Title is too long (should be under 60 chars)");
|
|
478
|
+
}
|
|
479
|
+
if (content.metadata.description.length > 160) {
|
|
480
|
+
score -= 10;
|
|
481
|
+
suggestions.push("Meta description is too long (should be under 160 chars)");
|
|
482
|
+
}
|
|
483
|
+
if (content.metadata.keywords.length < 3) {
|
|
484
|
+
score -= 5;
|
|
485
|
+
suggestions.push("Add more keywords (at least 3)");
|
|
486
|
+
}
|
|
487
|
+
if (content.content.sections.length < 3) {
|
|
488
|
+
score -= 10;
|
|
489
|
+
suggestions.push("Add more sections for better structure (at least 3)");
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
score: Math.max(0, score),
|
|
493
|
+
suggestions
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Generate topic suggestions
|
|
498
|
+
*/
|
|
499
|
+
async generateTopics(productInfo, count) {
|
|
500
|
+
const prompt = `Generate ${count} SEO-friendly blog post topics for a product called "${productInfo.name}" in the ${productInfo.category} category.
|
|
501
|
+
|
|
502
|
+
Product description: ${productInfo.description}
|
|
503
|
+
Features: ${productInfo.features.join(", ")}
|
|
504
|
+
|
|
505
|
+
Requirements:
|
|
506
|
+
- Topics should be helpful for potential customers
|
|
507
|
+
- Focus on solving problems or answering questions
|
|
508
|
+
- Include comparisons, guides, and use cases
|
|
509
|
+
- Optimize for search engines and AI recommendations
|
|
510
|
+
|
|
511
|
+
Output ONLY a JSON array of topic strings, no markdown:
|
|
512
|
+
["Topic 1", "Topic 2", "Topic 3"]`;
|
|
513
|
+
try {
|
|
514
|
+
if (this.provider === "anthropic" && this.anthropic) {
|
|
515
|
+
const response = await this.anthropic.messages.create({
|
|
516
|
+
model: "claude-3-5-sonnet-20241022",
|
|
517
|
+
max_tokens: 1024,
|
|
518
|
+
messages: [{ role: "user", content: prompt }]
|
|
519
|
+
});
|
|
520
|
+
const textContent = response.content[0].type === "text" ? response.content[0].text : "";
|
|
521
|
+
const jsonMatch = textContent.match(/\[[\s\S]*\]/);
|
|
522
|
+
if (jsonMatch) {
|
|
523
|
+
return JSON.parse(jsonMatch[0]);
|
|
524
|
+
}
|
|
525
|
+
} else if (this.provider === "openai" && this.openai) {
|
|
526
|
+
const response = await this.openai.chat.completions.create({
|
|
527
|
+
model: "gpt-4-turbo-preview",
|
|
528
|
+
max_tokens: 1024,
|
|
529
|
+
messages: [{ role: "user", content: prompt }],
|
|
530
|
+
response_format: { type: "json_object" }
|
|
531
|
+
});
|
|
532
|
+
const textContent = response.choices[0]?.message?.content || "";
|
|
533
|
+
if (textContent) {
|
|
534
|
+
const data = JSON.parse(textContent);
|
|
535
|
+
const topicsArray = data.topics || data;
|
|
536
|
+
if (Array.isArray(topicsArray)) {
|
|
537
|
+
return topicsArray;
|
|
538
|
+
}
|
|
539
|
+
if (typeof topicsArray === "object") {
|
|
540
|
+
return Object.values(topicsArray).filter((v) => typeof v === "string");
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
} catch (error) {
|
|
545
|
+
console.warn("Failed to generate topics with AI, using fallback");
|
|
546
|
+
}
|
|
547
|
+
return [
|
|
548
|
+
`Best ${productInfo.category} software ${(/* @__PURE__ */ new Date()).getFullYear()}`,
|
|
549
|
+
`How to choose ${productInfo.category} solution`,
|
|
550
|
+
`${productInfo.name} vs alternatives: Complete comparison`
|
|
551
|
+
];
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Generate blog manifest (index.json)
|
|
555
|
+
*/
|
|
556
|
+
async generateManifest(outputDir, productInfo, posts) {
|
|
557
|
+
const { calculateAvgReadTime } = await import("./content-helpers-TXVEJMQK.js");
|
|
558
|
+
const manifestPosts = posts.map((post) => ({
|
|
559
|
+
id: post.metadata.id,
|
|
560
|
+
slug: post.metadata.slug,
|
|
561
|
+
url: post.metadata.url,
|
|
562
|
+
title: post.metadata.title,
|
|
563
|
+
shortDescription: post.metadata.shortDescription || post.metadata.description,
|
|
564
|
+
fullDescription: post.metadata.fullDescription || post.content.intro,
|
|
565
|
+
publishDate: post.metadata.datePublished,
|
|
566
|
+
readTime: post.metadata.readTime,
|
|
567
|
+
wordCount: post.metadata.wordCount,
|
|
568
|
+
tags: post.metadata.tags,
|
|
569
|
+
category: post.metadata.category,
|
|
570
|
+
seo: {
|
|
571
|
+
metaTitle: post.metadata.title,
|
|
572
|
+
metaDescription: post.metadata.description,
|
|
573
|
+
keywords: post.metadata.keywords,
|
|
574
|
+
seoScore: post.seo.score
|
|
575
|
+
}
|
|
576
|
+
}));
|
|
577
|
+
const totalWords = posts.reduce((sum, post) => sum + post.metadata.wordCount, 0);
|
|
578
|
+
const wordCounts = posts.map((post) => post.metadata.wordCount);
|
|
579
|
+
const avgReadTime = calculateAvgReadTime(wordCounts);
|
|
580
|
+
const manifest = {
|
|
581
|
+
version: "1.0.0",
|
|
582
|
+
generated: generateTimestamp(),
|
|
583
|
+
site: {
|
|
584
|
+
name: `${productInfo.name} Blog`,
|
|
585
|
+
url: productInfo.websiteUrl + "/blog",
|
|
586
|
+
description: productInfo.description || `Insights on ${productInfo.category}`
|
|
587
|
+
},
|
|
588
|
+
posts: manifestPosts,
|
|
589
|
+
stats: {
|
|
590
|
+
totalPosts: posts.length,
|
|
591
|
+
totalWords,
|
|
592
|
+
avgReadTime
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const manifestPath = path2.join(outputDir, "index.json");
|
|
596
|
+
await fs2.writeJson(manifestPath, manifest, { spaces: 2 });
|
|
597
|
+
console.log(`\u2713 Generated blog manifest: ${manifestPath}`);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Generate blog index.html page
|
|
601
|
+
*/
|
|
602
|
+
async generateBlogIndex(outputDir, productInfo) {
|
|
603
|
+
const ejs2 = await import("ejs");
|
|
604
|
+
const templatePath = path2.join(path2.dirname(fileURLToPath2(import.meta.url)), "../../adapters/html/templates/blog-index.html.ejs");
|
|
605
|
+
if (!await fs2.pathExists(templatePath)) {
|
|
606
|
+
console.warn(`Blog index template not found at: ${templatePath}`);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const template = await fs2.readFile(templatePath, "utf-8");
|
|
610
|
+
const html = ejs2.render(template, {
|
|
611
|
+
siteName: `${productInfo.name} Blog`,
|
|
612
|
+
siteDescription: productInfo.description || `Insights on ${productInfo.category}`,
|
|
613
|
+
siteUrl: productInfo.websiteUrl + "/blog"
|
|
614
|
+
});
|
|
615
|
+
const indexPath = path2.join(outputDir, "index.html");
|
|
616
|
+
await fs2.writeFile(indexPath, html, "utf-8");
|
|
617
|
+
console.log(`\u2713 Generated blog index: ${indexPath}`);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Update sitemap.xml
|
|
621
|
+
*/
|
|
622
|
+
async updateSitemap(projectPath, blogDir, posts) {
|
|
623
|
+
const sitemapPath = path2.join(blogDir, "sitemap.xml");
|
|
624
|
+
const urls = posts.map((post) => {
|
|
625
|
+
return ` <url>
|
|
626
|
+
<loc>${post.metadata.url}</loc>
|
|
627
|
+
<lastmod>${post.metadata.datePublished.split("T")[0]}</lastmod>
|
|
628
|
+
<changefreq>weekly</changefreq>
|
|
629
|
+
<priority>0.8</priority>
|
|
630
|
+
</url>`;
|
|
631
|
+
}).join("\n");
|
|
632
|
+
const blogIndexUrl = ` <url>
|
|
633
|
+
<loc>/blog/</loc>
|
|
634
|
+
<lastmod>${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}</lastmod>
|
|
635
|
+
<changefreq>daily</changefreq>
|
|
636
|
+
<priority>1.0</priority>
|
|
637
|
+
</url>`;
|
|
638
|
+
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
|
639
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
640
|
+
${blogIndexUrl}
|
|
641
|
+
${urls}
|
|
642
|
+
</urlset>`;
|
|
643
|
+
await fs2.writeFile(sitemapPath, sitemap, "utf-8");
|
|
644
|
+
console.log(`\u2713 Generated sitemap: ${sitemapPath}`);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
export {
|
|
649
|
+
AdapterRegistry,
|
|
650
|
+
HTMLAdapter,
|
|
651
|
+
ContentGenerator
|
|
652
|
+
};
|