seomd-cli 2.0.0 → 2.0.1
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/bin/seomd.js +1 -0
- package/package.json +1 -1
- package/src/commands/generate.js +22 -9
- package/src/commands/init.js +73 -30
- package/src/generators/directory.js +4 -5
- package/src/generators/seomd.js +38 -9
- package/src/utils/migrate.js +99 -0
- package/src/utils/placeholders.js +31 -0
- package/src/validators/seomd.js +8 -0
package/bin/seomd.js
CHANGED
|
@@ -77,6 +77,7 @@ program
|
|
|
77
77
|
.command('generate <target>')
|
|
78
78
|
.description('Generate robots.txt, llms.txt, or JSON-LD schema from SEO.md (offline)')
|
|
79
79
|
.option('--out <file>', 'write output to file instead of stdout')
|
|
80
|
+
.option('--strict', 'fail instead of warning when SEO.md still has template text')
|
|
80
81
|
.addHelpText('after', `
|
|
81
82
|
|
|
82
83
|
Targets:
|
package/package.json
CHANGED
package/src/commands/generate.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { parseSeoMd, getBrand, getPages } from '../utils/parser.js';
|
|
5
5
|
import { AI_BOTS, SCHEMA_TYPES } from '../utils/constants.js';
|
|
6
|
+
import { getFact, findPlaceholders } from '../utils/placeholders.js';
|
|
6
7
|
|
|
7
8
|
const VALID_TARGETS = ['robots', 'llms', 'schema'];
|
|
8
9
|
|
|
@@ -45,11 +46,9 @@ export function buildLlmsTxt(data, body = '') {
|
|
|
45
46
|
const primaryKeyword = data.keywords?.primary || '';
|
|
46
47
|
const pages = getPages(data);
|
|
47
48
|
|
|
48
|
-
//
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
? oneLinerMatch[1].trim()
|
|
52
|
-
: `${brand} (${domain}) — ${primaryKeyword || 'official documentation and product pages'}.`;
|
|
49
|
+
// Use the founder's one-liner from the Markdown body, unless it is still init's template text
|
|
50
|
+
const summary = getFact(body, 'One-liner')
|
|
51
|
+
|| `${brand} (${domain}) — ${primaryKeyword || 'official documentation and product pages'}.`;
|
|
53
52
|
|
|
54
53
|
const lines = [
|
|
55
54
|
`# ${brand}`,
|
|
@@ -86,7 +85,7 @@ export function buildLlmsTxt(data, body = '') {
|
|
|
86
85
|
return lines.join('\n');
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
export function buildSchemaJsonLd(data) {
|
|
88
|
+
export function buildSchemaJsonLd(data, body = '') {
|
|
90
89
|
const brand = getBrand(data);
|
|
91
90
|
const domain = data.site?.domain || 'example.com';
|
|
92
91
|
const canonical = (data.site?.canonical || `https://${domain}`).replace(/\/$/, '');
|
|
@@ -130,7 +129,9 @@ export function buildSchemaJsonLd(data) {
|
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
|
|
132
|
+
// Only emit an FAQ answer the founder actually wrote; never publish template text as a fact
|
|
133
|
+
const oneLiner = getFact(body, 'One-liner');
|
|
134
|
+
if (types.includes('FAQPage') && oneLiner) {
|
|
134
135
|
graph.push({
|
|
135
136
|
'@type': 'FAQPage',
|
|
136
137
|
mainEntity: [
|
|
@@ -139,7 +140,7 @@ export function buildSchemaJsonLd(data) {
|
|
|
139
140
|
name: `What is ${brand}?`,
|
|
140
141
|
acceptedAnswer: {
|
|
141
142
|
'@type': 'Answer',
|
|
142
|
-
text:
|
|
143
|
+
text: oneLiner,
|
|
143
144
|
},
|
|
144
145
|
},
|
|
145
146
|
],
|
|
@@ -177,13 +178,25 @@ export async function generateCommand(target, options = {}) {
|
|
|
177
178
|
const cwd = process.cwd();
|
|
178
179
|
const { data, body } = await parseSeoMd(cwd);
|
|
179
180
|
|
|
181
|
+
// llms.txt and JSON-LD draw on the Canonical Product Facts; flag any still left as template text
|
|
182
|
+
const placeholders = normalizedTarget === 'robots' ? [] : findPlaceholders(body);
|
|
183
|
+
if (placeholders.length > 0) {
|
|
184
|
+
const list = placeholders.join(', ');
|
|
185
|
+
if (options.strict) {
|
|
186
|
+
console.error(chalk.red(`✗ SEO.md still has template text in: ${list}. Fill in Canonical Product Facts, then re-run.`));
|
|
187
|
+
process.exitCode = 1;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
console.error(chalk.yellow(`⚠ SEO.md still has template text in: ${list}. Those facts were left out of the ${normalizedTarget} output.`));
|
|
191
|
+
}
|
|
192
|
+
|
|
180
193
|
let output = '';
|
|
181
194
|
if (normalizedTarget === 'robots') {
|
|
182
195
|
output = buildRobotsTxt(data);
|
|
183
196
|
} else if (normalizedTarget === 'llms') {
|
|
184
197
|
output = buildLlmsTxt(data, body);
|
|
185
198
|
} else if (normalizedTarget === 'schema') {
|
|
186
|
-
output = buildSchemaJsonLd(data);
|
|
199
|
+
output = buildSchemaJsonLd(data, body);
|
|
187
200
|
}
|
|
188
201
|
|
|
189
202
|
if (options.out) {
|
package/src/commands/init.js
CHANGED
|
@@ -10,6 +10,8 @@ import { generateReverseMd } from '../generators/reverse.js';
|
|
|
10
10
|
import { createSeomdDir } from '../generators/directory.js';
|
|
11
11
|
import { scanRepo } from '../utils/repo-scanner.js';
|
|
12
12
|
import { wireAgentFiles } from '../utils/agent-wiring.js';
|
|
13
|
+
import { parseSeoMd } from '../utils/parser.js';
|
|
14
|
+
import { seedFromExisting, backupSeoMd } from '../utils/migrate.js';
|
|
13
15
|
import { SITE_TYPES, VALID_SITE_TYPES, SITE_TYPE_PROFILES } from '../utils/constants.js';
|
|
14
16
|
|
|
15
17
|
const { prompt } = enquirer;
|
|
@@ -53,23 +55,50 @@ export async function initCommand(options = {}) {
|
|
|
53
55
|
options.competitors !== undefined;
|
|
54
56
|
const isNonInteractive = Boolean(options.yes || hasConfigFlags);
|
|
55
57
|
|
|
58
|
+
// An existing SEO.md is never replaced silently:
|
|
59
|
+
// - v1 (legacy) files are upgraded in place, keeping their values
|
|
60
|
+
// - v2 / unreadable files need --force (or an interactive yes)
|
|
61
|
+
// and the previous file is always backed up first.
|
|
56
62
|
const seomdPath = path.join(workingDir, 'SEO.md');
|
|
63
|
+
let existing = null;
|
|
57
64
|
if (await fs.pathExists(seomdPath)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
let parsed = null;
|
|
66
|
+
try {
|
|
67
|
+
parsed = await parseSeoMd(workingDir);
|
|
68
|
+
} catch {
|
|
69
|
+
parsed = null;
|
|
70
|
+
}
|
|
71
|
+
const isLegacy = parsed?.format === 'v1';
|
|
72
|
+
|
|
73
|
+
if (!options.force) {
|
|
74
|
+
if (isNonInteractive && !isLegacy) {
|
|
75
|
+
console.log(chalk.red('✗ SEO.md already exists in this directory. Nothing was changed.'));
|
|
76
|
+
console.log(chalk.dim(' Re-run with --force to regenerate it (the current file is backed up to SEO.md.bak).'));
|
|
77
|
+
process.exitCode = 1;
|
|
69
78
|
return;
|
|
70
79
|
}
|
|
80
|
+
if (!isNonInteractive) {
|
|
81
|
+
console.log(chalk.yellow(isLegacy
|
|
82
|
+
? '⚠ Found a v1 SEO.md. init can upgrade it to v2, keeping your brand, keywords, intent queries, and pages.'
|
|
83
|
+
: '⚠ SEO.md already exists in this directory.'));
|
|
84
|
+
const { overwrite } = await prompt({
|
|
85
|
+
type: 'confirm',
|
|
86
|
+
name: 'overwrite',
|
|
87
|
+
message: isLegacy
|
|
88
|
+
? 'Upgrade SEO.md to v2? (current file is backed up to SEO.md.bak)'
|
|
89
|
+
: 'Overwrite existing SEO.md? (current file is backed up to SEO.md.bak)',
|
|
90
|
+
initial: isLegacy,
|
|
91
|
+
});
|
|
92
|
+
if (!overwrite) {
|
|
93
|
+
console.log(chalk.dim('Aborted.'));
|
|
94
|
+
process.exitCode = 0;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
71
98
|
}
|
|
99
|
+
existing = { parsed, isLegacy };
|
|
72
100
|
}
|
|
101
|
+
const seed = seedFromExisting(existing?.parsed?.data);
|
|
73
102
|
|
|
74
103
|
// Inspect repository for framework, existing routes, and crawl files
|
|
75
104
|
const repoInfo = await scanRepo(workingDir);
|
|
@@ -83,34 +112,35 @@ export async function initCommand(options = {}) {
|
|
|
83
112
|
console.log('');
|
|
84
113
|
}
|
|
85
114
|
|
|
86
|
-
const inferredBrand = repoInfo.packageName
|
|
115
|
+
const inferredBrand = seed.answers.brand || (repoInfo.packageName
|
|
87
116
|
? repoInfo.packageName.replace(/^@[^/]+\//, '').replace(/[-_]+/g, ' ')
|
|
88
|
-
: 'My Brand';
|
|
89
|
-
const inferredDomain = repoInfo.homepage
|
|
117
|
+
: 'My Brand');
|
|
118
|
+
const inferredDomain = seed.answers.domain || (repoInfo.homepage
|
|
90
119
|
? normalizeDomain(repoInfo.homepage)
|
|
91
|
-
: 'example.com';
|
|
120
|
+
: 'example.com');
|
|
92
121
|
|
|
93
122
|
let answers;
|
|
94
123
|
if (isNonInteractive) {
|
|
95
|
-
const siteType = options.type || 'saas';
|
|
124
|
+
const siteType = options.type || seed.answers.site_type || 'saas';
|
|
96
125
|
const profile = SITE_TYPE_PROFILES[siteType];
|
|
97
126
|
answers = {
|
|
98
127
|
site_type: siteType,
|
|
99
128
|
domain: normalizeDomain(options.domain || inferredDomain),
|
|
100
129
|
brand: (options.brand || inferredBrand).trim(),
|
|
101
|
-
primary_keyword: (options.primaryKeyword || profile.defaultKeyword).trim(),
|
|
130
|
+
primary_keyword: (options.primaryKeyword || seed.answers.primary_keyword || profile.defaultKeyword).trim(),
|
|
102
131
|
competitors: options.competitors
|
|
103
132
|
? options.competitors
|
|
104
133
|
.split(',')
|
|
105
134
|
.map((c) => normalizeDomain(c))
|
|
106
135
|
.filter(Boolean)
|
|
107
136
|
.slice(0, 5)
|
|
108
|
-
: [],
|
|
109
|
-
provider: options.provider || null,
|
|
137
|
+
: (seed.answers.competitors || []).map((c) => normalizeDomain(c)).filter(Boolean),
|
|
138
|
+
provider: options.provider || seed.answers.provider || null,
|
|
110
139
|
};
|
|
111
140
|
} else {
|
|
112
|
-
const
|
|
113
|
-
|
|
141
|
+
const typeForPrompt = options.type || seed.answers.site_type;
|
|
142
|
+
const initialTypeIdx = typeForPrompt
|
|
143
|
+
? Math.max(0, SITE_TYPES.findIndex((t) => t.value === typeForPrompt))
|
|
114
144
|
: 0;
|
|
115
145
|
|
|
116
146
|
answers = await prompt([
|
|
@@ -150,6 +180,7 @@ export async function initCommand(options = {}) {
|
|
|
150
180
|
type: 'input',
|
|
151
181
|
name: 'primary_keyword',
|
|
152
182
|
message: 'Primary keyword:',
|
|
183
|
+
initial: seed.answers.primary_keyword,
|
|
153
184
|
hint: 'e.g. project management software',
|
|
154
185
|
validate(value) {
|
|
155
186
|
if (!value || !value.trim()) return 'Primary keyword is required';
|
|
@@ -160,6 +191,7 @@ export async function initCommand(options = {}) {
|
|
|
160
191
|
type: 'input',
|
|
161
192
|
name: 'competitors',
|
|
162
193
|
message: 'Top competitors (comma separated, optional):',
|
|
194
|
+
initial: seed.answers.competitors ? seed.answers.competitors.join(', ') : undefined,
|
|
163
195
|
hint: 'e.g. asana.com, monday.com, notion.so',
|
|
164
196
|
result(value) {
|
|
165
197
|
return String(value || '')
|
|
@@ -170,26 +202,37 @@ export async function initCommand(options = {}) {
|
|
|
170
202
|
},
|
|
171
203
|
},
|
|
172
204
|
]);
|
|
173
|
-
answers.provider = options.provider || null;
|
|
205
|
+
answers.provider = options.provider || seed.answers.provider || null;
|
|
174
206
|
}
|
|
207
|
+
answers.carry = seed.carry;
|
|
175
208
|
|
|
176
209
|
console.log('');
|
|
177
210
|
const spinner = ora('Scaffolding your SEO.md workspace...').start();
|
|
178
211
|
|
|
179
212
|
try {
|
|
180
|
-
// 1. Generate v2 SEO.md (YAML frontmatter + Markdown body)
|
|
213
|
+
// 1. Generate v2 SEO.md (YAML frontmatter + Markdown body), backing up any existing file
|
|
181
214
|
const seomdContent = generateSeoMd(answers, repoInfo);
|
|
215
|
+
if (existing) {
|
|
216
|
+
const backupName = await backupSeoMd(workingDir);
|
|
217
|
+
spinner.succeed(chalk.green(`Previous SEO.md backed up to ${backupName}`));
|
|
218
|
+
}
|
|
182
219
|
await fs.writeFile(path.join(workingDir, 'SEO.md'), seomdContent, 'utf8');
|
|
183
|
-
spinner.succeed(chalk.green(
|
|
220
|
+
spinner.succeed(chalk.green(existing?.isLegacy
|
|
221
|
+
? 'SEO.md upgraded from v1 to spec v2.0.0 (values carried over)'
|
|
222
|
+
: 'SEO.md created (spec v2.0.0)'));
|
|
184
223
|
|
|
185
|
-
// 2. Create .seo/ workspace directory
|
|
224
|
+
// 2. Create .seo/ workspace directory (keeps an existing .seo/README.md)
|
|
186
225
|
await createSeomdDir(workingDir, answers);
|
|
187
|
-
spinner.succeed(chalk.green('.seo/ workspace
|
|
226
|
+
spinner.succeed(chalk.green('.seo/ workspace ready'));
|
|
188
227
|
|
|
189
|
-
// 3. Initialize .seo/REVERSE.md
|
|
190
|
-
const
|
|
191
|
-
await fs.
|
|
192
|
-
|
|
228
|
+
// 3. Initialize .seo/REVERSE.md: provider-generated intelligence, never overwritten
|
|
229
|
+
const reversePath = path.join(workingDir, '.seo', 'REVERSE.md');
|
|
230
|
+
if (await fs.pathExists(reversePath)) {
|
|
231
|
+
spinner.succeed(chalk.green('.seo/REVERSE.md kept (existing provider intelligence)'));
|
|
232
|
+
} else {
|
|
233
|
+
await fs.writeFile(reversePath, generateReverseMd(answers), 'utf8');
|
|
234
|
+
spinner.succeed(chalk.green('.seo/REVERSE.md initialized'));
|
|
235
|
+
}
|
|
193
236
|
|
|
194
237
|
// 4. Wire AGENTS.md / CLAUDE.md unless opted out via --no-wire-agents
|
|
195
238
|
let agentResult = { updated: [], created: [] };
|
|
@@ -15,11 +15,10 @@ export async function createSeomdDir(cwd, answers) {
|
|
|
15
15
|
|
|
16
16
|
await fs.ensureDir(path.join(seomdDir, 'pages'));
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
generateSeomdReadme(brand, domain),
|
|
21
|
-
|
|
22
|
-
);
|
|
18
|
+
const readmePath = path.join(seomdDir, 'README.md');
|
|
19
|
+
if (!(await fs.pathExists(readmePath))) {
|
|
20
|
+
await fs.writeFile(readmePath, generateSeomdReadme(brand, domain), 'utf8');
|
|
21
|
+
}
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
function generateSeomdReadme(brand, domain) {
|
package/src/generators/seomd.js
CHANGED
|
@@ -22,6 +22,7 @@ function getBrandNameFromDomain(domain) {
|
|
|
22
22
|
export function normalizeDomain(domain) {
|
|
23
23
|
return String(domain || '')
|
|
24
24
|
.trim()
|
|
25
|
+
.replace(/^<|>$/g, '')
|
|
25
26
|
.replace(/^https?:\/\//i, '')
|
|
26
27
|
.replace(/\/+$/, '');
|
|
27
28
|
}
|
|
@@ -50,6 +51,8 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
50
51
|
? answers.competitors.map(normalizeDomain).filter(Boolean)
|
|
51
52
|
: [];
|
|
52
53
|
const year = new Date().getFullYear();
|
|
54
|
+
// Founder-curated values carried over from an existing SEO.md (v1 or v2) on re-init
|
|
55
|
+
const carry = answers.carry || {};
|
|
53
56
|
|
|
54
57
|
// Build intent queries tailored to site type
|
|
55
58
|
const comparisonQueries = competitorList.length > 0
|
|
@@ -90,6 +93,14 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
90
93
|
queries: profile.categoryQuery(primaryKeyword, year),
|
|
91
94
|
},
|
|
92
95
|
};
|
|
96
|
+
if (carry.intent) {
|
|
97
|
+
for (const [category, kept] of Object.entries(carry.intent)) {
|
|
98
|
+
intent[category] = {
|
|
99
|
+
priority: kept.priority || intent[category]?.priority || 'medium',
|
|
100
|
+
queries: kept.queries,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
93
104
|
|
|
94
105
|
// Merge discovered live routes with recommended site-type pages
|
|
95
106
|
const recommendedPages = REQUIRED_PAGES[siteType] || REQUIRED_PAGES.saas;
|
|
@@ -100,14 +111,32 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
100
111
|
const seenUrls = new Set();
|
|
101
112
|
const seenIds = new Set();
|
|
102
113
|
|
|
103
|
-
//
|
|
114
|
+
// Pages declared in an existing SEO.md come first, keeping their keywords
|
|
115
|
+
for (const kept of carry.pages || []) {
|
|
116
|
+
const urlKey = kept.url.toLowerCase();
|
|
117
|
+
if (seenUrls.has(urlKey)) continue;
|
|
118
|
+
let id = kept.id || routeToPageId(kept.url);
|
|
119
|
+
if (seenIds.has(id)) id = `${id}-${pages.length + 1}`;
|
|
120
|
+
pages.push({
|
|
121
|
+
id,
|
|
122
|
+
url: kept.url,
|
|
123
|
+
status: discoveredSet.has(urlKey) ? 'live' : kept.status,
|
|
124
|
+
priority: kept.priority ?? pages.length + 1,
|
|
125
|
+
keyword: kept.keyword,
|
|
126
|
+
});
|
|
127
|
+
seenUrls.add(urlKey);
|
|
128
|
+
seenIds.add(id);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Then add recommended pages (marking as 'live' if discovered in repo)
|
|
104
132
|
for (const rec of recommendedPages) {
|
|
133
|
+
if (seenUrls.has(rec.url.toLowerCase())) continue;
|
|
105
134
|
const isLive = discoveredSet.has(rec.url.toLowerCase());
|
|
106
135
|
pages.push({
|
|
107
136
|
id: rec.id,
|
|
108
137
|
url: rec.url,
|
|
109
138
|
status: isLive ? 'live' : 'planned',
|
|
110
|
-
priority: rec.priority,
|
|
139
|
+
priority: carry.pages ? pages.length + 1 : rec.priority,
|
|
111
140
|
keyword: rec.url === '/' ? primaryKeyword : null,
|
|
112
141
|
});
|
|
113
142
|
seenUrls.add(rec.url.toLowerCase());
|
|
@@ -115,7 +144,7 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
115
144
|
}
|
|
116
145
|
|
|
117
146
|
// Then append any additional discovered live routes (capped at 20 total to keep manifest concise)
|
|
118
|
-
let nextPriority = pages.
|
|
147
|
+
let nextPriority = Math.max(0, ...pages.map((p) => Number(p.priority) || 0)) + 1;
|
|
119
148
|
for (const route of discoveredRoutes) {
|
|
120
149
|
if (pages.length >= 20) break;
|
|
121
150
|
if (seenUrls.has(route.toLowerCase())) continue;
|
|
@@ -141,12 +170,12 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
141
170
|
domain,
|
|
142
171
|
canonical: `https://${domain}`,
|
|
143
172
|
type: siteType,
|
|
144
|
-
locale: 'en-US',
|
|
173
|
+
locale: carry.locale || 'en-US',
|
|
145
174
|
},
|
|
146
175
|
keywords: {
|
|
147
176
|
primary: primaryKeyword,
|
|
148
|
-
secondary: [],
|
|
149
|
-
negative: profile.negativeKeywords,
|
|
177
|
+
secondary: carry.secondary || [],
|
|
178
|
+
negative: carry.negative || profile.negativeKeywords,
|
|
150
179
|
},
|
|
151
180
|
competitors: competitorList.map((c) => ({ domain: c })),
|
|
152
181
|
intent,
|
|
@@ -163,14 +192,14 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
163
192
|
},
|
|
164
193
|
provider: {
|
|
165
194
|
name: answers.provider || null,
|
|
166
|
-
endpoint: null,
|
|
195
|
+
endpoint: carry.providerEndpoint || null,
|
|
167
196
|
},
|
|
168
197
|
};
|
|
169
198
|
|
|
170
199
|
const yamlBlock = YAML.stringify(frontmatter, { lineWidth: 100 }).trimEnd();
|
|
171
200
|
|
|
172
201
|
const rulesMarkdown = profile.agentRules.map((rule) => `- ${rule}`).join('\n');
|
|
173
|
-
const negativeMarkdown =
|
|
202
|
+
const negativeMarkdown = frontmatter.keywords.negative.map((kw) => `\`${kw}\``).join(', ');
|
|
174
203
|
const promptLines = [
|
|
175
204
|
`- **Category:** ${intent.category.queries.map((q) => `"${q}"`).join(', ')}`,
|
|
176
205
|
`- **Comparison:** ${intent.comparison.queries.map((q) => `"${q}"`).join(', ')}`,
|
|
@@ -183,7 +212,7 @@ export function generateSeoMd(answers, repoInfo = null) {
|
|
|
183
212
|
> Coding agents: read this file and matching playbooks in \`.seo/pages/\` before creating or editing public pages.
|
|
184
213
|
|
|
185
214
|
## Canonical Product Facts
|
|
186
|
-
- **One-liner:** ${brand} — replace with a clear, factual 1-sentence description of what you offer
|
|
215
|
+
- **One-liner:** ${carry.tagline ? `${brand} — ${carry.tagline}` : `${brand} — replace with a clear, factual 1-sentence description of what you offer.`}
|
|
187
216
|
- **Primary category:** ${primaryKeyword}
|
|
188
217
|
- **Pricing / offer:** Add real pricing or offer facts here so coding agents never invent vague copy.
|
|
189
218
|
- **Proof points:** Add concrete, verifiable metrics, certifications, or customer outcomes.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getBrand, getCompetitors, getIntentQueries, getPages, getProviderConfig } from './parser.js';
|
|
4
|
+
import { VALID_SITE_TYPES } from './constants.js';
|
|
5
|
+
|
|
6
|
+
function cleanList(value) {
|
|
7
|
+
if (!Array.isArray(value)) return [];
|
|
8
|
+
return value.map((v) => (typeof v === 'string' ? v.trim() : v)).filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function domainFrom(data) {
|
|
12
|
+
const raw = data?.site?.domain || data?.site?.canonical || '';
|
|
13
|
+
return String(raw)
|
|
14
|
+
.trim()
|
|
15
|
+
.replace(/^<|>$/g, '')
|
|
16
|
+
.replace(/^https?:\/\//i, '')
|
|
17
|
+
.replace(/\/+$/, '') || null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pulls the founder-declared values out of an existing SEO.md (v1 or v2) so that
|
|
22
|
+
* re-running `init` upgrades the file instead of replacing it with a blank template.
|
|
23
|
+
*
|
|
24
|
+
* Returns init answers (only the fields that were actually set) plus `carry`,
|
|
25
|
+
* the curated lists the generator should keep instead of regenerating.
|
|
26
|
+
*
|
|
27
|
+
* @param {object} data - Parsed SEO.md data (from parseSeoMd)
|
|
28
|
+
*/
|
|
29
|
+
export function seedFromExisting(data) {
|
|
30
|
+
if (!data || typeof data !== 'object') return { answers: {}, carry: {} };
|
|
31
|
+
|
|
32
|
+
const answers = {};
|
|
33
|
+
const siteType = data?.site?.type;
|
|
34
|
+
if (VALID_SITE_TYPES.includes(siteType)) answers.site_type = siteType;
|
|
35
|
+
|
|
36
|
+
const domain = domainFrom(data);
|
|
37
|
+
if (domain) answers.domain = domain;
|
|
38
|
+
|
|
39
|
+
const brand = getBrand(data);
|
|
40
|
+
if (brand && brand !== 'My Brand') answers.brand = String(brand).trim();
|
|
41
|
+
|
|
42
|
+
const primary = data?.keywords?.primary;
|
|
43
|
+
if (typeof primary === 'string' && primary.trim()) answers.primary_keyword = primary.trim();
|
|
44
|
+
|
|
45
|
+
const competitors = getCompetitors(data);
|
|
46
|
+
if (competitors.length > 0) answers.competitors = competitors;
|
|
47
|
+
|
|
48
|
+
const provider = getProviderConfig(data);
|
|
49
|
+
if (provider.name) answers.provider = provider.name;
|
|
50
|
+
|
|
51
|
+
const carry = {};
|
|
52
|
+
const secondary = cleanList(data?.keywords?.secondary);
|
|
53
|
+
if (secondary.length > 0) carry.secondary = secondary;
|
|
54
|
+
const negative = cleanList(data?.keywords?.negative);
|
|
55
|
+
if (negative.length > 0) carry.negative = negative;
|
|
56
|
+
if (data?.site?.locale) carry.locale = data.site.locale;
|
|
57
|
+
if (data?.provider?.endpoint || data?.platform?.endpoint) carry.providerEndpoint = getProviderConfig(data).endpoint;
|
|
58
|
+
const tagline = data?.identity?.tagline || data?.site?.tagline;
|
|
59
|
+
if (typeof tagline === 'string' && tagline.trim()) carry.tagline = tagline.trim();
|
|
60
|
+
|
|
61
|
+
// Intent: keep curated queries + priorities per category (drop provider `_analysis` blocks)
|
|
62
|
+
const queries = getIntentQueries(data);
|
|
63
|
+
const intent = {};
|
|
64
|
+
for (const [category, list] of Object.entries(queries)) {
|
|
65
|
+
const cleaned = cleanList(list).filter((q) => typeof q === 'string');
|
|
66
|
+
if (cleaned.length === 0) continue;
|
|
67
|
+
const priority = data.intent?.[category]?.priority;
|
|
68
|
+
intent[category] = { ...(priority ? { priority } : {}), queries: cleaned };
|
|
69
|
+
}
|
|
70
|
+
if (Object.keys(intent).length > 0) carry.intent = intent;
|
|
71
|
+
|
|
72
|
+
// Pages: keep declared pages with their keywords and status
|
|
73
|
+
const pages = getPages(data)
|
|
74
|
+
.filter((p) => p.url)
|
|
75
|
+
.map((p) => ({
|
|
76
|
+
id: p.id || null,
|
|
77
|
+
url: p.url,
|
|
78
|
+
status: p.status || 'planned',
|
|
79
|
+
priority: p.priority ?? null,
|
|
80
|
+
keyword: p.primary_keyword || null,
|
|
81
|
+
}));
|
|
82
|
+
if (pages.length > 0) carry.pages = pages;
|
|
83
|
+
|
|
84
|
+
return { answers, carry };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Copies SEO.md to SEO.md.bak (or SEO.md.bak.<timestamp> if a backup already exists).
|
|
89
|
+
* @returns {Promise<string>} the backup file name
|
|
90
|
+
*/
|
|
91
|
+
export async function backupSeoMd(workingDir) {
|
|
92
|
+
const src = path.join(workingDir, 'SEO.md');
|
|
93
|
+
let name = 'SEO.md.bak';
|
|
94
|
+
if (await fs.pathExists(path.join(workingDir, name))) {
|
|
95
|
+
name = `SEO.md.bak.${new Date().toISOString().replace(/[:.]/g, '-')}`;
|
|
96
|
+
}
|
|
97
|
+
await fs.copy(src, path.join(workingDir, name));
|
|
98
|
+
return name;
|
|
99
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Template text that `seomd init` writes into SEO.md for the founder to replace.
|
|
2
|
+
// Anything that matches must never be published into robots/llms/schema output.
|
|
3
|
+
const PLACEHOLDER_PATTERN = /\b(replace with|add real|add concrete)\b/i;
|
|
4
|
+
|
|
5
|
+
export function isPlaceholder(text) {
|
|
6
|
+
return typeof text === 'string' && PLACEHOLDER_PATTERN.test(text);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reads a `- **Label:** value` fact line from the SEO.md Markdown body.
|
|
11
|
+
* Returns null when the fact is missing or still holds template text.
|
|
12
|
+
*/
|
|
13
|
+
export function getFact(body, label) {
|
|
14
|
+
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
15
|
+
const match = String(body || '').match(new RegExp(`\\*\\*${escaped}:\\*\\*\\s*(.+)`, 'i'));
|
|
16
|
+
if (!match) return null;
|
|
17
|
+
const value = match[1].trim();
|
|
18
|
+
return value && !isPlaceholder(value) ? value : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Lists the `- **Label:**` fact lines in the body that still hold template text.
|
|
23
|
+
* @returns {string[]} labels, e.g. ['One-liner', 'Pricing / offer']
|
|
24
|
+
*/
|
|
25
|
+
export function findPlaceholders(body) {
|
|
26
|
+
const labels = [];
|
|
27
|
+
for (const match of String(body || '').matchAll(/\*\*([^*]+?):\*\*\s*(.+)/g)) {
|
|
28
|
+
if (isPlaceholder(match[2])) labels.push(match[1].trim());
|
|
29
|
+
}
|
|
30
|
+
return labels;
|
|
31
|
+
}
|
package/src/validators/seomd.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findPlaceholders } from '../utils/placeholders.js';
|
|
1
2
|
import {
|
|
2
3
|
VALID_SITE_TYPES,
|
|
3
4
|
INTENT_CATEGORIES,
|
|
@@ -215,6 +216,13 @@ function validateV2(data, body, errors, warnings) {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
// 8. Markdown body check
|
|
219
|
+
const placeholders = findPlaceholders(body);
|
|
220
|
+
if (placeholders.length > 0) {
|
|
221
|
+
warnings.push({
|
|
222
|
+
path: 'body',
|
|
223
|
+
message: `Canonical Product Facts still have template text: ${placeholders.join(', ')}. Coding agents and generated llms.txt/JSON-LD need real facts.`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
218
226
|
if (!body || body.trim().length < 20) {
|
|
219
227
|
warnings.push({
|
|
220
228
|
path: 'body',
|