@wkgeo/cli 1.0.0 → 1.1.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/CHANGELOG.md +249 -203
- package/README.md +151 -19
- package/SKILL.md +108 -27
- package/lib/args.mjs +2 -2
- package/lib/asset-role.mjs +68 -0
- package/lib/cms.mjs +2 -2
- package/lib/commands/billing.mjs +56 -10
- package/lib/commands/cms.mjs +49 -13
- package/lib/commands/content.mjs +108 -0
- package/lib/commands/crawl.mjs +219 -0
- package/lib/commands/geo.mjs +1673 -0
- package/lib/commands/index.mjs +640 -528
- package/lib/commands/member.mjs +930 -0
- package/lib/commands/seo.mjs +1386 -0
- package/lib/commands/siteops.mjs +3 -3
- package/lib/commands/sites.mjs +21 -125
- package/lib/commands/template.mjs +1474 -0
- package/lib/config.mjs +16 -13
- package/lib/content-apply.mjs +664 -0
- package/lib/content-check.mjs +887 -0
- package/lib/content-contract.mjs +957 -0
- package/lib/errors.mjs +6 -0
- package/lib/format.mjs +5 -1
- package/lib/manifest-apply.mjs +1499 -0
- package/lib/manifest-schema.json +476 -0
- package/lib/manifest.mjs +1082 -0
- package/lib/oauth-urls.mjs +1 -1
- package/lib/runtime.mjs +5 -1
- package/lib/site-create.mjs +536 -0
- package/lib/tar.mjs +207 -0
- package/lib/template-anim.mjs +1338 -0
- package/lib/template-animation.mjs +232 -0
- package/lib/template-capture.mjs +700 -0
- package/lib/template-gen.mjs +1204 -0
- package/lib/template-pack.mjs +206 -0
- package/lib/template-package.mjs +522 -0
- package/lib/template-publish.mjs +733 -0
- package/lib/template-score.mjs +865 -0
- package/lib/template-validate.mjs +368 -0
- package/lib/template-verify.mjs +434 -0
- package/lib/templates-sync.mjs +616 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wkgeo seo` —— 本地站点产物的 SEO 工具(**只读本地文件,不联网、不写库**)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么放 CLI:A(agent)产出的静态站点 / 模板包 / 导出目录,在**上线前**就要能体检、
|
|
5
|
+
* 补齐 `llms.txt` / `sitemap.xml` / `robots.txt` / JSON-LD;这些活不依赖站点 ID,也不该
|
|
6
|
+
* 先登录、先建站。所以做成四条纯本地命令,跟 `template validate` 一样可离线跑。
|
|
7
|
+
*
|
|
8
|
+
* 四条命令:
|
|
9
|
+
* * `seo audit <dir>` —— 13 项加权评分(权重见 `AUDIT_RULES`,合计 100)+ issues[];
|
|
10
|
+
* * `seo llms <dir>` —— 生成 llms.txt(一级/二级页面 + 一句话摘要)+ llms-full.txt(正文摘录);
|
|
11
|
+
* * `seo schema <dir> --type <类型>` —— 生成 organization / website / article / faq / breadcrumb 的 JSON-LD;
|
|
12
|
+
* * `seo files <dir>` —— 校验 sitemap.xml(XML 良构 / `<loc>` 非空 / URL 去重)与
|
|
13
|
+
* robots.txt(语法 / `Sitemap:` 与 sitemap.xml 一致)。**不联网**(不校验 URL 可达性)。
|
|
14
|
+
*
|
|
15
|
+
* 约定(与其他命令一致):
|
|
16
|
+
* * 写文件的命令(`llms` / `schema`)**默认 dry-run**,只打印;`--confirm` 才落盘;
|
|
17
|
+
* * 全部支持 `--json`,`data` 形状稳定;
|
|
18
|
+
* * **零第三方依赖**:XML 用下面的 `parseXml()` 手写轻量校验(只做良构 + 取 `<loc>`,不做 XSD 校验);
|
|
19
|
+
* * `seo audit` 是**报告命令**:有问题也 exit 0,看 `data.score` / `data.summary`;
|
|
20
|
+
* * `seo files` 是**门禁命令**:有 error 就 exit 1,`--json` 时完整 issues 在 `error.details` 里。
|
|
21
|
+
*
|
|
22
|
+
* 与后台插件的关系(`docs/功能-插件-seo.md`):插件那条链是"按站点 ID 读库 + 生成 sitemap 文本",
|
|
23
|
+
* 本文件是"按目录读静态产物",口径(title 10~60、description 50~160、H1 恰好一个、图片 alt)
|
|
24
|
+
* 与插件 `seoCheck` 对齐,但**不共用代码**(插件运行在云函数里,CLI 拿不到它的运行时)。
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import fs from 'node:fs';
|
|
28
|
+
import path from 'node:path';
|
|
29
|
+
|
|
30
|
+
import { CliError, UsageError } from '../errors.mjs';
|
|
31
|
+
|
|
32
|
+
/* ------------------------------------------------------------------ 常量 */
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 13 项审计规则与权重(合计 100)。
|
|
36
|
+
*
|
|
37
|
+
* 改权重只改这里:`auditDirectory()` 的逐项得分、总分、等级都从这张表推,
|
|
38
|
+
* 不会出现"帮助里写了 13 项、代码里只算 11 项"这种漂移。
|
|
39
|
+
* `llms_txt` / `sitemap` / `robots` 是**站点级**(整目录一次),其余 10 项按页算。
|
|
40
|
+
*/
|
|
41
|
+
export const AUDIT_RULES = [
|
|
42
|
+
{ id: 'title', weight: 10, title: 'title 存在且 ≤60 字符' },
|
|
43
|
+
{ id: 'description', weight: 10, title: 'description 存在且 ≤160 字符' },
|
|
44
|
+
{ id: 'keywords', weight: 4, title: 'keywords 非空' },
|
|
45
|
+
{ id: 'canonical', weight: 7, title: 'canonical 存在' },
|
|
46
|
+
{ id: 'og', weight: 12, title: 'og:title / og:description / og:image 齐全' },
|
|
47
|
+
{ id: 'jsonld', weight: 10, title: 'JSON-LD 存在且能 JSON.parse' },
|
|
48
|
+
{ id: 'h1', weight: 9, title: '每页恰好 1 个 h1' },
|
|
49
|
+
{ id: 'heading_order', weight: 6, title: '标题层级不跳级' },
|
|
50
|
+
{ id: 'img_alt', weight: 9, title: '图片都有 alt 属性' },
|
|
51
|
+
{ id: 'dead_links', weight: 12, title: '内链都能落到本地文件' },
|
|
52
|
+
{ id: 'llms_txt', weight: 4, title: 'llms.txt 存在' },
|
|
53
|
+
{ id: 'sitemap', weight: 4, title: 'sitemap.xml 存在且 XML 合法' },
|
|
54
|
+
{ id: 'robots', weight: 3, title: 'robots.txt 存在且含 Sitemap: 行' },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/** 站点级规则(整目录只算一次,不按页累加) */
|
|
58
|
+
const SITE_RULES = new Set(['llms_txt', 'sitemap', 'robots']);
|
|
59
|
+
|
|
60
|
+
/** 一次最多报多少条 issue(大站全量会刷屏;`--json` 里会带 `truncated:true`) */
|
|
61
|
+
const MAX_ISSUES = 500;
|
|
62
|
+
/** 单页最多报多少条死链(其余汇总成一条 info) */
|
|
63
|
+
const MAX_DEAD_LINKS_PER_PAGE = 20;
|
|
64
|
+
/** llms.txt 里一句话摘要最多多少字符 */
|
|
65
|
+
const LLMS_SUMMARY_CHARS = 120;
|
|
66
|
+
/** llms-full.txt 里每页正文摘录最多多少字符 */
|
|
67
|
+
const LLMS_FULL_PAGE_CHARS = 3000;
|
|
68
|
+
/** 遍历产物目录时跳过的目录名(`seo/` 是我们自己写 schema 的地方,不算页面) */
|
|
69
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', '.svn', '.hg', 'seo']);
|
|
70
|
+
/** 站点清单候选文件名(有就用来填 name / url / logo,没有就走页面里的文字) */
|
|
71
|
+
const MANIFEST_NAMES = ['site-manifest.json', 'manifest.json', 'site.json'];
|
|
72
|
+
/** `seo schema --type` 允许的取值 */
|
|
73
|
+
export const SEO_SCHEMA_TYPES = ['organization', 'website', 'article', 'faq', 'breadcrumb'];
|
|
74
|
+
|
|
75
|
+
/* ------------------------------------------------------------------ HTML 解析(正则,够用且零依赖) */
|
|
76
|
+
|
|
77
|
+
/** HTML 实体解码(覆盖常见命名实体 + 数字实体;不认的保持原样,不猜) */
|
|
78
|
+
export function decodeEntities(text) {
|
|
79
|
+
const named = {
|
|
80
|
+
amp: '&',
|
|
81
|
+
lt: '<',
|
|
82
|
+
gt: '>',
|
|
83
|
+
quot: '"',
|
|
84
|
+
apos: "'",
|
|
85
|
+
nbsp: ' ',
|
|
86
|
+
mdash: '—',
|
|
87
|
+
ndash: '–',
|
|
88
|
+
hellip: '…',
|
|
89
|
+
middot: '·',
|
|
90
|
+
copy: '©',
|
|
91
|
+
reg: '®',
|
|
92
|
+
times: '×',
|
|
93
|
+
};
|
|
94
|
+
return String(text == null ? '' : text).replace(/&(#x?[0-9a-fA-F]+|[A-Za-z][A-Za-z0-9]*);/g, (all, body) => {
|
|
95
|
+
if (body.startsWith('#x') || body.startsWith('#X')) {
|
|
96
|
+
const code = Number.parseInt(body.slice(2), 16);
|
|
97
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : all;
|
|
98
|
+
}
|
|
99
|
+
if (body.startsWith('#')) {
|
|
100
|
+
const code = Number.parseInt(body.slice(1), 10);
|
|
101
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : all;
|
|
102
|
+
}
|
|
103
|
+
const value = named[body.toLowerCase()];
|
|
104
|
+
return value === undefined ? all : value;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 去标签 → 解实体 → 压空白(正文/标题文本统一走它) */
|
|
109
|
+
export function stripTags(html) {
|
|
110
|
+
const src = String(html == null ? '' : html)
|
|
111
|
+
.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
112
|
+
.replace(/<(script|style|noscript|template)\b[^>]*>[\s\S]*?<\/\1>/gi, ' ');
|
|
113
|
+
return collapse(decodeEntities(src.replace(/<[^>]*>/g, ' ')));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 空白压成一个空格并去掉首尾空白 */
|
|
117
|
+
export function collapse(text) {
|
|
118
|
+
return String(text == null ? '' : text)
|
|
119
|
+
.replace(/\s+/g, ' ')
|
|
120
|
+
.trim();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 字符数(按码点算,中文 1 个字算 1 —— 跟插件 `seoCheck` 的口径一致) */
|
|
124
|
+
export function charCount(text) {
|
|
125
|
+
return [...String(text == null ? '' : text)].length;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 截断到 n 个字符,超出补省略号 */
|
|
129
|
+
export function clip(text, n) {
|
|
130
|
+
const chars = [...String(text == null ? '' : text)];
|
|
131
|
+
if (chars.length <= n) return chars.join('');
|
|
132
|
+
return chars.slice(0, n).join('') + '…';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 读一个标签上的属性(`<meta name="description" content="x">` → `{name,description,content:x}`)。
|
|
137
|
+
* 属性名一律小写;没写值的属性(`<script defer>`)给空串。
|
|
138
|
+
*/
|
|
139
|
+
export function readAttrs(tagHtml) {
|
|
140
|
+
const attrs = {};
|
|
141
|
+
const src = String(tagHtml == null ? '' : tagHtml);
|
|
142
|
+
const body = src.replace(/^<\s*\/?\s*[A-Za-z][\w:.-]*/, '').replace(/\/?>\s*$/, '');
|
|
143
|
+
const re = /([A-Za-z_:][-A-Za-z0-9_:.]*)(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
144
|
+
let m;
|
|
145
|
+
while ((m = re.exec(body))) {
|
|
146
|
+
const name = m[1].toLowerCase();
|
|
147
|
+
if (name === '' || name === '/') continue;
|
|
148
|
+
const value = m[3] !== undefined ? m[3] : m[4] !== undefined ? m[4] : m[5] !== undefined ? m[5] : '';
|
|
149
|
+
if (!(name in attrs)) attrs[name] = decodeEntities(value);
|
|
150
|
+
}
|
|
151
|
+
return attrs;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 解析一页 HTML 里审计/生成要用的东西(不引 DOM 库:我们只用标题、meta、标题层级、图片、链接)。
|
|
156
|
+
*
|
|
157
|
+
* 说明:`alt` 用 `null` 表示**属性缺失**,空串表示"写了 alt=""(装饰图,合法)"——
|
|
158
|
+
* 两者必须区分,否则会把合规的装饰图算成缺 alt(插件 `seoCheck` 也是这个口径)。
|
|
159
|
+
*/
|
|
160
|
+
export function parsePageHtml(html) {
|
|
161
|
+
const src = String(html == null ? '' : html).replace(/<!--[\s\S]*?-->/g, '');
|
|
162
|
+
const page = {
|
|
163
|
+
title: '',
|
|
164
|
+
description: '',
|
|
165
|
+
keywords: '',
|
|
166
|
+
canonical: '',
|
|
167
|
+
lang: '',
|
|
168
|
+
author: '',
|
|
169
|
+
published: '',
|
|
170
|
+
modified: '',
|
|
171
|
+
og: {},
|
|
172
|
+
jsonld: [],
|
|
173
|
+
headings: [],
|
|
174
|
+
images: [],
|
|
175
|
+
links: [],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const titleMatch = src.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
179
|
+
if (titleMatch) page.title = collapse(stripTags(titleMatch[1]));
|
|
180
|
+
|
|
181
|
+
const htmlTag = src.match(/<html\b[^>]*>/i);
|
|
182
|
+
if (htmlTag) page.lang = String(readAttrs(htmlTag[0]).lang || '').trim();
|
|
183
|
+
|
|
184
|
+
for (const m of src.matchAll(/<meta\b[^>]*>/gi)) {
|
|
185
|
+
const a = readAttrs(m[0]);
|
|
186
|
+
const key = String(a.property || a.name || '').trim().toLowerCase();
|
|
187
|
+
const content = a.content === undefined ? '' : a.content;
|
|
188
|
+
if (!key) continue;
|
|
189
|
+
if (key === 'description' && !page.description) page.description = collapse(content);
|
|
190
|
+
else if (key === 'keywords' && !page.keywords) page.keywords = collapse(content);
|
|
191
|
+
else if (key === 'author' && !page.author) page.author = collapse(content);
|
|
192
|
+
else if ((key === 'article:published_time' || key === 'article:published') && !page.published) page.published = collapse(content);
|
|
193
|
+
else if ((key === 'article:modified_time' || key === 'article:modified') && !page.modified) page.modified = collapse(content);
|
|
194
|
+
else if (key.startsWith('og:') && !(key in page.og)) page.og[key] = collapse(content);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
for (const m of src.matchAll(/<link\b[^>]*>/gi)) {
|
|
198
|
+
const a = readAttrs(m[0]);
|
|
199
|
+
if (!page.canonical && /\bcanonical\b/i.test(String(a.rel || ''))) page.canonical = String(a.href || '').trim();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (const m of src.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)) {
|
|
203
|
+
const openTag = m[0].slice(0, m[0].indexOf('>') + 1);
|
|
204
|
+
const a = readAttrs(openTag);
|
|
205
|
+
if (!/application\/ld\+json/i.test(String(a.type || ''))) continue;
|
|
206
|
+
const raw = String(m[1] || '').trim();
|
|
207
|
+
const item = { raw, ok: false, value: null, error: '' };
|
|
208
|
+
try {
|
|
209
|
+
item.value = JSON.parse(raw);
|
|
210
|
+
item.ok = true;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
item.error = String((e && e.message) || e);
|
|
213
|
+
}
|
|
214
|
+
page.jsonld.push(item);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
for (const m of src.matchAll(/<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/gi)) {
|
|
218
|
+
page.headings.push({ level: Number(m[1]), text: collapse(stripTags(m[2])) });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const timeMatch = src.match(/<time\b[^>]*\bdatetime\s*=\s*("([^"]*)"|'([^']*)')/i);
|
|
222
|
+
if (timeMatch) {
|
|
223
|
+
const value = timeMatch[2] !== undefined ? timeMatch[2] : timeMatch[3];
|
|
224
|
+
page.published = page.published || collapse(value);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const m of src.matchAll(/<img\b[^>]*>/gi)) {
|
|
228
|
+
const a = readAttrs(m[0]);
|
|
229
|
+
page.images.push({ src: String(a.src || '').trim(), alt: a.alt === undefined ? null : a.alt });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (const m of src.matchAll(/<a\b[^>]*>/gi)) {
|
|
233
|
+
const a = readAttrs(m[0]);
|
|
234
|
+
const href = String(a.href || '').trim();
|
|
235
|
+
if (href) page.links.push(href);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return page;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** 正文纯文本(llms-full.txt 用):去掉 head / 脚本 / 样式 / 注释再压空白 */
|
|
242
|
+
export function pageText(html) {
|
|
243
|
+
const src = String(html == null ? '' : html)
|
|
244
|
+
.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
245
|
+
.replace(/<head\b[^>]*>[\s\S]*?<\/head>/gi, ' ')
|
|
246
|
+
.replace(/<(script|style|noscript|template)\b[^>]*>[\s\S]*?<\/\1>/gi, ' ');
|
|
247
|
+
return collapse(decodeEntities(src.replace(/<[^>]*>/g, ' ')));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/* ------------------------------------------------------------------ 目录遍历 */
|
|
251
|
+
|
|
252
|
+
function isHtmlFile(name) {
|
|
253
|
+
return /\.html?$/i.test(String(name || ''));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function pageRank(rel) {
|
|
257
|
+
if (rel === 'index.html') return 0;
|
|
258
|
+
if (!rel.includes('/')) return 1;
|
|
259
|
+
return 2;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 列出目录下所有 HTML(相对路径,`/` 分隔)。
|
|
264
|
+
* 跳过隐藏目录 / `node_modules` / `seo/`(schema 输出目录),深度上限 8 层。
|
|
265
|
+
*/
|
|
266
|
+
export function listHtmlFiles(dir) {
|
|
267
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
268
|
+
const out = [];
|
|
269
|
+
const walk = (abs, rel, depth) => {
|
|
270
|
+
if (depth > 8) return;
|
|
271
|
+
let entries;
|
|
272
|
+
try {
|
|
273
|
+
entries = fs.readdirSync(abs, { withFileTypes: true });
|
|
274
|
+
} catch {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (const entry of entries) {
|
|
278
|
+
const name = entry.name;
|
|
279
|
+
if (name.startsWith('.')) continue;
|
|
280
|
+
const childRel = rel ? `${rel}/${name}` : name;
|
|
281
|
+
if (entry.isDirectory()) {
|
|
282
|
+
if (SKIP_DIRS.has(name)) continue;
|
|
283
|
+
walk(path.join(abs, name), childRel, depth + 1);
|
|
284
|
+
} else if (isHtmlFile(name)) {
|
|
285
|
+
out.push(childRel);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
walk(absolute, '', 0);
|
|
290
|
+
out.sort((a, b) => pageRank(a) - pageRank(b) || a.localeCompare(b));
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** 相对路径 → 站内 URL(`index.html` → `/`,`blog/index.html` → `/blog/`) */
|
|
295
|
+
export function pageUrl(rel) {
|
|
296
|
+
const norm = String(rel || '').replace(/\\/g, '/').replace(/^\/+/, '');
|
|
297
|
+
if (norm === 'index.html') return '/';
|
|
298
|
+
if (norm.endsWith('/index.html')) return `/${norm.slice(0, -'index.html'.length)}`;
|
|
299
|
+
return `/${norm}`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/* ------------------------------------------------------------------ 链接解析 */
|
|
303
|
+
|
|
304
|
+
/** 外链 / 锚点 / 协议链接:不参与"本地文件是否存在"的判断 */
|
|
305
|
+
function isExternalHref(href) {
|
|
306
|
+
return /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(href);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 把页面里的 href 落到本地文件上(只解析,不判断存在)。
|
|
311
|
+
* 返回 `{ skip:true }`(空/锚点/外链)或 `{ skip:false, abs, outside, decoded, rel }`。
|
|
312
|
+
*/
|
|
313
|
+
export function resolveLocalLink(dir, pageRel, href) {
|
|
314
|
+
const raw = String(href || '').trim();
|
|
315
|
+
if (!raw || raw.startsWith('#')) return { skip: true };
|
|
316
|
+
if (isExternalHref(raw)) return { skip: true, external: true };
|
|
317
|
+
const cut = raw.split('#')[0].split('?')[0];
|
|
318
|
+
if (!cut) return { skip: true };
|
|
319
|
+
let decoded = cut;
|
|
320
|
+
try {
|
|
321
|
+
decoded = decodeURIComponent(cut);
|
|
322
|
+
} catch {
|
|
323
|
+
/* 非法百分号编码就按原样查文件 */
|
|
324
|
+
}
|
|
325
|
+
const baseDir = decoded.startsWith('/') ? path.resolve(dir) : path.dirname(path.resolve(dir, pageRel));
|
|
326
|
+
const abs = path.resolve(baseDir, decoded.replace(/^\/+/, ''));
|
|
327
|
+
const rel = path.relative(path.resolve(dir), abs);
|
|
328
|
+
return {
|
|
329
|
+
skip: false,
|
|
330
|
+
abs,
|
|
331
|
+
outside: rel.startsWith('..') || path.isAbsolute(rel),
|
|
332
|
+
decoded,
|
|
333
|
+
rel: rel.replace(/\\/g, '/'),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** 链接目标是否存在(`about` / `about/` 都试 `about.html`、`about/index.html`) */
|
|
338
|
+
function localTargetExists(abs) {
|
|
339
|
+
const candidates = [abs];
|
|
340
|
+
if (!path.extname(abs)) {
|
|
341
|
+
candidates.push(`${abs}.html`, path.join(abs, 'index.html'));
|
|
342
|
+
}
|
|
343
|
+
if (/[\\/]$/.test(abs)) candidates.push(path.join(abs, 'index.html'));
|
|
344
|
+
return candidates.some((one) => {
|
|
345
|
+
try {
|
|
346
|
+
return fs.statSync(one).isFile();
|
|
347
|
+
} catch {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* ------------------------------------------------------------------ XML / robots.txt(手写轻量校验) */
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 轻量 XML 良构校验(sitemap 够用:不引 sax、不建树,只保证"标签闭合 + 单根 + 实体合法")。
|
|
357
|
+
* 返回 `{ ok, errors[], root, elements[{name, attrs}] }`;`elements` 供 `sitemapLocs()` 之外的用途。
|
|
358
|
+
*/
|
|
359
|
+
export function parseXml(text) {
|
|
360
|
+
const src = String(text == null ? '' : text).replace(/^\uFEFF/, '');
|
|
361
|
+
const errors = [];
|
|
362
|
+
const elements = [];
|
|
363
|
+
const body = src
|
|
364
|
+
.replace(/<\?[\s\S]*?\?>/g, '')
|
|
365
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
366
|
+
.replace(/<!DOCTYPE[^>[]*(\[[\s\S]*?\])?[^>]*>/gi, '');
|
|
367
|
+
const re = /<(\/?)([A-Za-z_][A-Za-z0-9_.:-]*)((?:"[^"]*"|'[^']*'|[^"'<>])*?)(\/?)>/g;
|
|
368
|
+
const stack = [];
|
|
369
|
+
let root = null;
|
|
370
|
+
let last = 0;
|
|
371
|
+
let truncated = null;
|
|
372
|
+
let m;
|
|
373
|
+
const checkText = (chunk, where) => {
|
|
374
|
+
if (/[<>]/.test(chunk)) errors.push(`${where}出现非法字符「${chunk.trim().slice(0, 40)}」(未转义的 < 或 >)`);
|
|
375
|
+
if (/&(?!(?:#\d+|#x[0-9a-fA-F]+|[A-Za-z][A-Za-z0-9._-]*);)/.test(chunk)) {
|
|
376
|
+
errors.push(`${where}有未转义的 &(应写成 &)`);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
while ((m = re.exec(body))) {
|
|
380
|
+
checkText(body.slice(last, m.index), '标签之间');
|
|
381
|
+
last = re.lastIndex;
|
|
382
|
+
if (body.indexOf('<', last - 1) === last - 1 && m[0].length === 0) break;
|
|
383
|
+
const closing = m[1] === '/';
|
|
384
|
+
const name = m[2];
|
|
385
|
+
const selfClose = m[4] === '/';
|
|
386
|
+
if (closing) {
|
|
387
|
+
const open = stack.pop();
|
|
388
|
+
if (!open) errors.push(`多出来的结束标签 </${name}>`);
|
|
389
|
+
else if (open !== name) errors.push(`标签没有正确闭合:<${open}> … </${name}>`);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (!stack.length) {
|
|
393
|
+
if (root) errors.push(`有多个根元素:<${root}> / <${name}>`);
|
|
394
|
+
else root = name;
|
|
395
|
+
}
|
|
396
|
+
if (!selfClose) stack.push(name);
|
|
397
|
+
elements.push({ name, attrs: readAttrs(`<${name}${m[3] || ''}>`), selfClosing: selfClose });
|
|
398
|
+
}
|
|
399
|
+
checkText(body.slice(last), '末尾');
|
|
400
|
+
if (body.indexOf('<', last) >= 0 && body.indexOf('<', last) === body.indexOf('<', Math.max(0, last))) {
|
|
401
|
+
/** 上面 checkText 已经覆盖;这里只兜底"最后一个标签后还有 <" */
|
|
402
|
+
}
|
|
403
|
+
if (stack.length) errors.push(`有标签没有闭合:${stack.map((n) => `<${n}>`).join(' ')}`);
|
|
404
|
+
if (!root) errors.push('没有根元素(不是 XML 文档)');
|
|
405
|
+
if (truncated) errors.push(truncated);
|
|
406
|
+
return { ok: errors.length === 0, errors, root, elements };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** 取 `<loc>` 文本(已解实体;空 `<loc></loc>` 会得到空串,由调用方判 error) */
|
|
410
|
+
export function sitemapLocs(xml) {
|
|
411
|
+
const out = [];
|
|
412
|
+
for (const m of String(xml == null ? '' : xml).matchAll(/<loc\b[^>]*>([\s\S]*?)<\/loc>/gi)) {
|
|
413
|
+
out.push(collapse(decodeEntities(m[1])));
|
|
414
|
+
}
|
|
415
|
+
return out;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** robots.txt 里认识的指令(其余只 warn,不当错误 —— 各家长尾指令是允许的) */
|
|
419
|
+
const ROBOTS_DIRECTIVES = new Set([
|
|
420
|
+
'user-agent',
|
|
421
|
+
'allow',
|
|
422
|
+
'disallow',
|
|
423
|
+
'sitemap',
|
|
424
|
+
'crawl-delay',
|
|
425
|
+
'host',
|
|
426
|
+
'clean-param',
|
|
427
|
+
'request-rate',
|
|
428
|
+
'visit-time',
|
|
429
|
+
'noindex',
|
|
430
|
+
]);
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* robots.txt 语法解析:每行必须是 `指令: 值`(注释 `#` 与空行忽略)。
|
|
434
|
+
* 返回 `{ lines, directives[{line,name,value}], sitemapLines[{line,value}], issues[] }`。
|
|
435
|
+
*/
|
|
436
|
+
export function analyzeRobots(text) {
|
|
437
|
+
const rawLines = String(text == null ? '' : text).split(/\r?\n/);
|
|
438
|
+
const directives = [];
|
|
439
|
+
const sitemapLines = [];
|
|
440
|
+
const issues = [];
|
|
441
|
+
rawLines.forEach((raw, index) => {
|
|
442
|
+
const clean = String(raw || '').replace(/\r$/, '').trim();
|
|
443
|
+
if (!clean || clean.startsWith('#')) return;
|
|
444
|
+
const m = clean.match(/^([A-Za-z][A-Za-z-]*)\s*:\s*(.*)$/);
|
|
445
|
+
if (!m) {
|
|
446
|
+
issues.push({
|
|
447
|
+
severity: 'error',
|
|
448
|
+
rule: 'robots_syntax',
|
|
449
|
+
line: index + 1,
|
|
450
|
+
message: `第 ${index + 1} 行不是「指令: 值」形式:${clean.slice(0, 60)}`,
|
|
451
|
+
suggestion: '每行写成 `User-agent: *` / `Allow: /` / `Sitemap: https://<域名>/sitemap.xml`',
|
|
452
|
+
});
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const name = m[1].toLowerCase();
|
|
456
|
+
const value = m[2].trim();
|
|
457
|
+
directives.push({ line: index + 1, name, value });
|
|
458
|
+
if (name === 'sitemap') sitemapLines.push({ line: index + 1, value });
|
|
459
|
+
if (!ROBOTS_DIRECTIVES.has(name)) {
|
|
460
|
+
issues.push({
|
|
461
|
+
severity: 'warn',
|
|
462
|
+
rule: 'robots_syntax',
|
|
463
|
+
line: index + 1,
|
|
464
|
+
message: `第 ${index + 1} 行是不常见的指令 ${m[1]}(不认识但保留,不影响评定)`,
|
|
465
|
+
suggestion: '确认拼写;非标准指令各家爬虫行为不一致',
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
return { lines: rawLines.length, directives, sitemapLines, issues };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/* ------------------------------------------------------------------ 站点清单(manifest)
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 找站点清单:`site-manifest.json` / `manifest.json` / `site.json`(有就取,没有返回 null)。
|
|
476
|
+
* **绝不因为"没有清单"就编造站点信息**:调用方按空值处理并写 notes。
|
|
477
|
+
*/
|
|
478
|
+
export function findManifest(dir) {
|
|
479
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
480
|
+
for (const name of MANIFEST_NAMES) {
|
|
481
|
+
const file = path.join(absolute, name);
|
|
482
|
+
let stat = null;
|
|
483
|
+
try {
|
|
484
|
+
stat = fs.statSync(file);
|
|
485
|
+
} catch {
|
|
486
|
+
stat = null;
|
|
487
|
+
}
|
|
488
|
+
if (!stat || !stat.isFile()) continue;
|
|
489
|
+
try {
|
|
490
|
+
return { file: name, path: file, data: JSON.parse(fs.readFileSync(file, 'utf8')), error: null };
|
|
491
|
+
} catch (e) {
|
|
492
|
+
return { file: name, path: file, data: null, error: String((e && e.message) || e) };
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return { file: null, path: null, data: null, error: null };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function str(value) {
|
|
499
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* 从清单里取站点级字段(兼容 `site-manifest@1` 的 `site{}` 与松散的顶层写法)。
|
|
504
|
+
* 只认字符串、只做 trim —— 不做类型转换、不猜。
|
|
505
|
+
*/
|
|
506
|
+
export function manifestSiteFields(data) {
|
|
507
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return {};
|
|
508
|
+
const site = data.site && typeof data.site === 'object' && !Array.isArray(data.site) ? data.site : {};
|
|
509
|
+
return {
|
|
510
|
+
name: str(site.name) || str(data.name) || str(data.title),
|
|
511
|
+
description: str(site.description) || str(data.description),
|
|
512
|
+
url: str(site.url) || str(site.baseUrl) || str(site.base_url) || str(data.url),
|
|
513
|
+
logo: str(site.logo) || str(site.logoUrl) || str(site.logo_url) || str(data.logo),
|
|
514
|
+
lang: str(site.lang) || str(data.lang),
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function readFileSafe(file) {
|
|
519
|
+
try {
|
|
520
|
+
return fs.readFileSync(file, 'utf8');
|
|
521
|
+
} catch {
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* 站点级元信息:清单优先,缺的用首页的 title / description / lang 兜底。
|
|
528
|
+
* 返回 `{ name, description, url, logo, lang, manifest, notes[] }`。
|
|
529
|
+
*/
|
|
530
|
+
export function readSiteMeta(dir) {
|
|
531
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
532
|
+
const manifest = findManifest(absolute);
|
|
533
|
+
const fields = manifestSiteFields(manifest.data);
|
|
534
|
+
const notes = [];
|
|
535
|
+
if (manifest.error) notes.push(`清单 ${manifest.file} 不是合法 JSON(已忽略):${manifest.error}`);
|
|
536
|
+
if (!manifest.file) notes.push('没有找到 site-manifest.json / manifest.json / site.json(站点名与 URL 只能从页面里取)');
|
|
537
|
+
const indexHtml = readFileSafe(path.join(absolute, 'index.html'));
|
|
538
|
+
const home = indexHtml === null ? null : parsePageHtml(indexHtml);
|
|
539
|
+
const name = fields.name || (home && home.title) || '';
|
|
540
|
+
const description = fields.description || (home && home.description) || '';
|
|
541
|
+
const lang = fields.lang || (home && home.lang) || '';
|
|
542
|
+
if (!fields.name && name) notes.push('站点名取自首页 <title>(清单里没有 site.name)');
|
|
543
|
+
if (!fields.url) notes.push('站点 URL 缺失(清单与 og:url 都没有):JSON-LD 里 url 留空、页面地址用相对路径');
|
|
544
|
+
return { name, description, url: fields.url, logo: fields.logo, lang, manifest, notes };
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/* ------------------------------------------------------------------ 审计 */
|
|
548
|
+
|
|
549
|
+
function addIssue(list, rule, severity, file, message, suggestion) {
|
|
550
|
+
list.push({ severity, file, rule, message, suggestion });
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** 单页 10 项检查;返回 `{ failed:Set<string>, issues[] }` */
|
|
554
|
+
export function auditPage(dir, rel, html) {
|
|
555
|
+
const page = parsePageHtml(html);
|
|
556
|
+
const issues = [];
|
|
557
|
+
const failed = new Set();
|
|
558
|
+
const fail = (rule) => failed.add(rule);
|
|
559
|
+
|
|
560
|
+
const titleLen = charCount(page.title);
|
|
561
|
+
if (!page.title) {
|
|
562
|
+
fail('title');
|
|
563
|
+
addIssue(issues, 'title', 'error', rel, '缺 <title>', '补一个 10~60 字符的页面标题');
|
|
564
|
+
} else if (titleLen > 60) {
|
|
565
|
+
fail('title');
|
|
566
|
+
addIssue(issues, 'title', 'warn', rel, `title 过长(${titleLen} 字符 > 60)`, '压到 60 字符以内,长尾词放进 description');
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const descLen = charCount(page.description);
|
|
570
|
+
if (!page.description) {
|
|
571
|
+
fail('description');
|
|
572
|
+
addIssue(issues, 'description', 'error', rel, '缺 meta description', '补 50~160 字符的描述(列表页简介 + SEO 的 D 共用这一段)');
|
|
573
|
+
} else if (descLen > 160) {
|
|
574
|
+
fail('description');
|
|
575
|
+
addIssue(issues, 'description', 'warn', rel, `description 过长(${descLen} 字符 > 160)`, '压到 160 字符以内,剩下的写进正文');
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (!page.keywords) {
|
|
579
|
+
fail('keywords');
|
|
580
|
+
addIssue(issues, 'keywords', 'info', rel, 'keywords 为空', '补 3~20 个关键词(逗号分隔);现代搜索不重它,但 GEO / 站内检索要用');
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (!page.canonical) {
|
|
584
|
+
fail('canonical');
|
|
585
|
+
addIssue(issues, 'canonical', 'warn', rel, '缺 <link rel="canonical">', '每页加 canonical(多域名 / 带参访问时防重复收录)');
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
for (const [tag, suggestion] of [
|
|
589
|
+
['og:title', '补 `<meta property="og:title" content="…">`(可与 title 相同)'],
|
|
590
|
+
['og:description', '补 `<meta property="og:description" content="…">`(可与 description 相同)'],
|
|
591
|
+
['og:image', '补 `<meta property="og:image" content="https://…/封面.jpg">`(绝对地址,建议 1200×630)'],
|
|
592
|
+
]) {
|
|
593
|
+
if (!page.og[tag]) {
|
|
594
|
+
fail('og');
|
|
595
|
+
addIssue(issues, 'og', 'warn', rel, `缺 ${tag}`, suggestion);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (!page.jsonld.length) {
|
|
600
|
+
fail('jsonld');
|
|
601
|
+
addIssue(issues, 'jsonld', 'warn', rel, '缺 JSON-LD(<script type="application/ld+json">)', '用 `wkgeo seo schema <目录> --type article --confirm` 生成,或手写 schema.org 结构化数据');
|
|
602
|
+
} else {
|
|
603
|
+
const bad = page.jsonld.filter((one) => !one.ok);
|
|
604
|
+
if (bad.length) {
|
|
605
|
+
fail('jsonld');
|
|
606
|
+
addIssue(issues, 'jsonld', 'error', rel, `JSON-LD 解析失败(${bad.length}/${page.jsonld.length} 段):${bad[0].error || 'JSON.parse 报错'}`, '改成合法 JSON(不能有注释、不能有尾逗号),`--json` 里带原文');
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const h1s = page.headings.filter((one) => one.level === 1);
|
|
611
|
+
if (h1s.length !== 1) {
|
|
612
|
+
fail('h1');
|
|
613
|
+
addIssue(
|
|
614
|
+
issues,
|
|
615
|
+
'h1',
|
|
616
|
+
'warn',
|
|
617
|
+
rel,
|
|
618
|
+
h1s.length === 0 ? '页面没有 h1' : `h1 有 ${h1s.length} 个(应唯一)`,
|
|
619
|
+
'每页只留一个 h1 当主标题,其余降为 h2 / h3',
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
for (let i = 1; i < page.headings.length; i++) {
|
|
624
|
+
const prev = page.headings[i - 1];
|
|
625
|
+
const cur = page.headings[i];
|
|
626
|
+
if (cur.level > prev.level + 1) {
|
|
627
|
+
fail('heading_order');
|
|
628
|
+
addIssue(issues, 'heading_order', 'warn', rel, `标题层级跳级:h${prev.level} → h${cur.level}(「${clip(cur.text, 24) || '无文字'}」)`, `中间补一层 h${prev.level + 1},别从 h${prev.level} 直接跳到 h${cur.level}`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const noAlt = page.images.filter((one) => one.alt === null);
|
|
633
|
+
if (noAlt.length) {
|
|
634
|
+
fail('img_alt');
|
|
635
|
+
addIssue(
|
|
636
|
+
issues,
|
|
637
|
+
'img_alt',
|
|
638
|
+
'warn',
|
|
639
|
+
rel,
|
|
640
|
+
`${noAlt.length}/${page.images.length} 张图缺 alt 属性`,
|
|
641
|
+
'给内容图写一句 alt;纯装饰图显式写 alt=""(空 alt 是允许的,缺属性不是)',
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
let deadCount = 0;
|
|
646
|
+
const seen = new Set();
|
|
647
|
+
for (const href of page.links) {
|
|
648
|
+
if (seen.has(href)) continue;
|
|
649
|
+
seen.add(href);
|
|
650
|
+
const target = resolveLocalLink(dir, rel, href);
|
|
651
|
+
if (target.skip) continue;
|
|
652
|
+
if (deadCount >= MAX_DEAD_LINKS_PER_PAGE) {
|
|
653
|
+
addIssue(issues, 'dead_links', 'info', rel, `死链超过 ${MAX_DEAD_LINKS_PER_PAGE} 条,其余省略`, '先修前面这些,再跑一次看剩下的');
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
if (target.outside) {
|
|
657
|
+
fail('dead_links');
|
|
658
|
+
deadCount += 1;
|
|
659
|
+
addIssue(issues, 'dead_links', 'error', rel, `内链跑到站点目录之外:${href}`, '改成站内相对路径;产物目录不该引用目录外的文件');
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (!localTargetExists(target.abs)) {
|
|
663
|
+
fail('dead_links');
|
|
664
|
+
deadCount += 1;
|
|
665
|
+
addIssue(issues, 'dead_links', 'error', rel, `内链指向的文件不存在:${href}`, '补上目标文件,或把链接改成已存在的页面');
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return { page, failed, issues };
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** 站点级 3 项(llms.txt / sitemap.xml / robots.txt);返回各规则的 pass 与 issues */
|
|
673
|
+
export function auditSiteFiles(dir) {
|
|
674
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
675
|
+
const issues = [];
|
|
676
|
+
const results = {};
|
|
677
|
+
|
|
678
|
+
const llmsFile = path.join(absolute, 'llms.txt');
|
|
679
|
+
const llmsText = readFileSafe(llmsFile);
|
|
680
|
+
if (llmsText === null || !llmsText.trim()) {
|
|
681
|
+
addIssue(issues, 'llms_txt', 'info', 'llms.txt', '缺 llms.txt', '用 `wkgeo seo llms <目录> --confirm` 生成(给 AI 爬虫看的站点索引)');
|
|
682
|
+
results.llms_txt = { pass: false, exists: llmsText !== null };
|
|
683
|
+
} else {
|
|
684
|
+
results.llms_txt = { pass: true, exists: true };
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const sitemapFile = path.join(absolute, 'sitemap.xml');
|
|
688
|
+
const sitemapText = readFileSafe(sitemapFile);
|
|
689
|
+
if (sitemapText === null) {
|
|
690
|
+
addIssue(issues, 'sitemap', 'warn', 'sitemap.xml', '缺 sitemap.xml', '生成标准 urlset(每条至少 <loc>),并在 robots.txt 里用 Sitemap: 宣告');
|
|
691
|
+
results.sitemap = { pass: false, exists: false, urls: 0 };
|
|
692
|
+
} else {
|
|
693
|
+
const parsed = parseXml(sitemapText);
|
|
694
|
+
const locs = sitemapLocs(sitemapText).filter(Boolean);
|
|
695
|
+
if (!parsed.ok) {
|
|
696
|
+
addIssue(issues, 'sitemap', 'error', 'sitemap.xml', `XML 不合法:${parsed.errors[0]}`, '修闭合标签 / 转义 &(用 `wkgeo seo files <目录>` 看全部问题)');
|
|
697
|
+
results.sitemap = { pass: false, exists: true, urls: locs.length, xml_ok: false };
|
|
698
|
+
} else if (!locs.length) {
|
|
699
|
+
addIssue(issues, 'sitemap', 'warn', 'sitemap.xml', '<loc> 一条都没有', '至少收录首页 + 已发布页面');
|
|
700
|
+
results.sitemap = { pass: false, exists: true, urls: 0, xml_ok: true };
|
|
701
|
+
} else {
|
|
702
|
+
results.sitemap = { pass: true, exists: true, urls: locs.length, xml_ok: true };
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const robotsFile = path.join(absolute, 'robots.txt');
|
|
707
|
+
const robotsText = readFileSafe(robotsFile);
|
|
708
|
+
if (robotsText === null) {
|
|
709
|
+
addIssue(issues, 'robots', 'warn', 'robots.txt', '缺 robots.txt', '加 `User-agent: *` / `Allow: /` / `Sitemap: <站点>/sitemap.xml`');
|
|
710
|
+
results.robots = { pass: false, exists: false, sitemap_lines: 0 };
|
|
711
|
+
} else {
|
|
712
|
+
const robots = analyzeRobots(robotsText);
|
|
713
|
+
for (const one of robots.issues) {
|
|
714
|
+
if (one.severity === 'warn') {
|
|
715
|
+
addIssue(issues, 'robots', 'warn', 'robots.txt', one.message, one.suggestion);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (!robots.sitemapLines.length) {
|
|
719
|
+
addIssue(issues, 'robots', 'warn', 'robots.txt', 'robots.txt 里没有 Sitemap: 行', '加一行 `Sitemap: https://<域名>/sitemap.xml`');
|
|
720
|
+
results.robots = { pass: false, exists: true, sitemap_lines: 0 };
|
|
721
|
+
} else {
|
|
722
|
+
results.robots = { pass: true, exists: true, sitemap_lines: robots.sitemapLines.length };
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return { results, issues };
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** 等级(与插件 `seoScore` 同口径) */
|
|
730
|
+
export function gradeOf(score) {
|
|
731
|
+
if (score >= 85) return 'good';
|
|
732
|
+
if (score >= 60) return 'fair';
|
|
733
|
+
return 'poor';
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* 审计整个目录:**13 项加权评分** + 全量 issues。
|
|
738
|
+
* 返回 `{ dir, pages, score, grade, rules[], issues[], summary{error,warn,info,total}, truncated }`。
|
|
739
|
+
*/
|
|
740
|
+
export function auditDirectory(dir) {
|
|
741
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
742
|
+
const files = listHtmlFiles(absolute);
|
|
743
|
+
if (!files.length) {
|
|
744
|
+
throw new CliError(`目录里没有 .html 文件:${absolute}`, {
|
|
745
|
+
kind: 'empty',
|
|
746
|
+
code: 'ENOPAGES',
|
|
747
|
+
hint: '确认这是站点产物目录(里面有 index.html 等页面)',
|
|
748
|
+
exitCode: 1,
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const state = new Map(AUDIT_RULES.map((rule) => [rule.id, { ...rule, passed: 0, total: 0 }]));
|
|
753
|
+
const issues = [];
|
|
754
|
+
for (const rel of files) {
|
|
755
|
+
const html = readFileSafe(path.join(absolute, rel));
|
|
756
|
+
const result = auditPage(absolute, rel, html === null ? '' : html);
|
|
757
|
+
for (const rule of state.values()) {
|
|
758
|
+
if (SITE_RULES.has(rule.id)) continue;
|
|
759
|
+
rule.total += 1;
|
|
760
|
+
if (!result.failed.has(rule.id)) rule.passed += 1;
|
|
761
|
+
}
|
|
762
|
+
issues.push(...result.issues);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const site = auditSiteFiles(absolute);
|
|
766
|
+
for (const id of SITE_RULES) {
|
|
767
|
+
const rule = state.get(id);
|
|
768
|
+
rule.total = 1;
|
|
769
|
+
rule.passed = site.results[id] && site.results[id].pass ? 1 : 0;
|
|
770
|
+
}
|
|
771
|
+
issues.push(...site.issues);
|
|
772
|
+
|
|
773
|
+
const rules = [...state.values()].map((rule) => ({
|
|
774
|
+
id: rule.id,
|
|
775
|
+
title: rule.title,
|
|
776
|
+
weight: rule.weight,
|
|
777
|
+
total: rule.total,
|
|
778
|
+
passed: rule.passed,
|
|
779
|
+
score: rule.total ? Math.round((rule.weight * rule.passed) / rule.total) : 0,
|
|
780
|
+
}));
|
|
781
|
+
|
|
782
|
+
let score = Math.round(rules.reduce((sum, rule) => sum + (rule.total ? (rule.weight * rule.passed) / rule.total : 0), 0));
|
|
783
|
+
score = Math.max(0, Math.min(100, score));
|
|
784
|
+
|
|
785
|
+
const severityRank = { error: 0, warn: 1, info: 2 };
|
|
786
|
+
issues.sort(
|
|
787
|
+
(a, b) =>
|
|
788
|
+
(severityRank[a.severity] ?? 9) - (severityRank[b.severity] ?? 9) ||
|
|
789
|
+
String(a.file).localeCompare(String(b.file)) ||
|
|
790
|
+
String(a.rule).localeCompare(String(b.rule)),
|
|
791
|
+
);
|
|
792
|
+
const truncated = issues.length > MAX_ISSUES;
|
|
793
|
+
const shown = truncated ? issues.slice(0, MAX_ISSUES) : issues;
|
|
794
|
+
|
|
795
|
+
const summary = { error: 0, warn: 0, info: 0, total: issues.length };
|
|
796
|
+
for (const one of issues) summary[one.severity] = (summary[one.severity] || 0) + 1;
|
|
797
|
+
|
|
798
|
+
return {
|
|
799
|
+
dir: absolute,
|
|
800
|
+
pages: files.length,
|
|
801
|
+
score,
|
|
802
|
+
grade: gradeOf(score),
|
|
803
|
+
rules,
|
|
804
|
+
issues: shown,
|
|
805
|
+
summary,
|
|
806
|
+
truncated,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/* ------------------------------------------------------------------ llms.txt */
|
|
811
|
+
|
|
812
|
+
/** 正文第一段(description 缺的时候当摘要用) */
|
|
813
|
+
function firstParagraph(html) {
|
|
814
|
+
const src = String(html == null ? '' : html).replace(/<!--[\s\S]*?-->/g, ' ');
|
|
815
|
+
const m = src.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);
|
|
816
|
+
return m ? collapse(stripTags(m[1])) : '';
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* 生成 llms.txt / llms-full.txt 的**内容**(不写盘,写盘由命令层按 `--confirm` 决定)。
|
|
821
|
+
*
|
|
822
|
+
* llms.txt 形状(对齐 llmstxt.org 约定):
|
|
823
|
+
* `# 站点标题` / `> 站点描述` / `## 一级页面` / `## 二级页面`(每行 `- [标题](url):摘要`)。
|
|
824
|
+
* llms-full.txt:站点头 + 每页 `## 标题` / `URL: …` / 正文纯文本摘录(上限 3000 字符)。
|
|
825
|
+
*/
|
|
826
|
+
export function buildLlms(dir, { baseUrl = '' } = {}) {
|
|
827
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
828
|
+
const files = listHtmlFiles(absolute);
|
|
829
|
+
if (!files.length) {
|
|
830
|
+
throw new CliError(`目录里没有 .html 文件:${absolute}`, {
|
|
831
|
+
kind: 'empty',
|
|
832
|
+
code: 'ENOPAGES',
|
|
833
|
+
hint: '确认这是站点产物目录(里面有 index.html 等页面)',
|
|
834
|
+
exitCode: 1,
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
const meta = readSiteMeta(absolute);
|
|
838
|
+
const base = String(baseUrl || '').replace(/\/+$/, '');
|
|
839
|
+
const withBase = (url) => (base ? `${base}${url}` : url);
|
|
840
|
+
|
|
841
|
+
const pages = files.map((rel) => {
|
|
842
|
+
const html = readFileSafe(path.join(absolute, rel)) || '';
|
|
843
|
+
const parsed = parsePageHtml(html);
|
|
844
|
+
const depth = rel.split('/').length;
|
|
845
|
+
return {
|
|
846
|
+
file: rel,
|
|
847
|
+
url: pageUrl(rel),
|
|
848
|
+
title: parsed.title || path.basename(rel, path.extname(rel)),
|
|
849
|
+
summary: clip(parsed.description || firstParagraph(html) || '', LLMS_SUMMARY_CHARS),
|
|
850
|
+
text: clip(pageText(html), LLMS_FULL_PAGE_CHARS),
|
|
851
|
+
level: depth >= 2 ? 2 : 1,
|
|
852
|
+
lang: parsed.lang || meta.lang || '',
|
|
853
|
+
};
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
const title = meta.name || path.basename(absolute);
|
|
857
|
+
const lines = [`# ${title}`];
|
|
858
|
+
if (meta.description) lines.push('', `> ${meta.description}`);
|
|
859
|
+
lines.push('', '> 站点页面索引与一句话摘要;每页正文纯文本见 llms-full.txt。');
|
|
860
|
+
|
|
861
|
+
const section = (level, heading) => {
|
|
862
|
+
const subset = pages.filter((one) => one.level === level);
|
|
863
|
+
if (!subset.length) return;
|
|
864
|
+
lines.push('', `## ${heading}`);
|
|
865
|
+
for (const one of subset) {
|
|
866
|
+
const link = `[${one.title}](${withBase(one.url)})`;
|
|
867
|
+
lines.push(one.summary ? `- ${link}:${one.summary}` : `- ${link}`);
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
section(1, '一级页面');
|
|
871
|
+
section(2, '二级页面');
|
|
872
|
+
|
|
873
|
+
const full = [`# ${title}`];
|
|
874
|
+
if (meta.description) full.push('', `> ${meta.description}`);
|
|
875
|
+
for (const one of pages) {
|
|
876
|
+
full.push('', '---', '', `## ${one.title}`, '', `URL: ${withBase(one.url)}`);
|
|
877
|
+
if (one.text) full.push('', one.text);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
const llmsTxt = `${lines.join('\n').replace(/\n{3,}/g, '\n\n').trim()}\n`;
|
|
881
|
+
const llmsFull = `${full.join('\n').replace(/\n{3,}/g, '\n\n').trim()}\n`;
|
|
882
|
+
|
|
883
|
+
return {
|
|
884
|
+
dir: absolute,
|
|
885
|
+
base_url: base,
|
|
886
|
+
site: { name: title, description: meta.description, url: meta.url, lang: meta.lang, manifest: meta.manifest.file },
|
|
887
|
+
notes: meta.notes,
|
|
888
|
+
pages,
|
|
889
|
+
llms_txt: { path: path.join(absolute, 'llms.txt'), chars: charCount(llmsTxt), content: llmsTxt },
|
|
890
|
+
llms_full: { path: path.join(absolute, 'llms-full.txt'), chars: charCount(llmsFull), content: llmsFull },
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/* ------------------------------------------------------------------ JSON-LD */
|
|
895
|
+
|
|
896
|
+
function readPageFrom(dir, rel) {
|
|
897
|
+
const html = readFileSafe(path.join(dir, rel));
|
|
898
|
+
if (html === null) return null;
|
|
899
|
+
return { rel, html, page: parsePageHtml(html) };
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/** 把 `--page` 归一到目录内的相对路径(找不到直接 UsageError,不猜) */
|
|
903
|
+
function resolvePageRel(dir, page) {
|
|
904
|
+
const raw = String(page || '').trim();
|
|
905
|
+
if (!raw) return '';
|
|
906
|
+
const norm = raw.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
907
|
+
const abs = path.resolve(dir, norm);
|
|
908
|
+
const rel = path.relative(dir, abs).replace(/\\/g, '/');
|
|
909
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) throw new UsageError(`--page 必须在 <目录> 之内:${page}`);
|
|
910
|
+
if (!fs.existsSync(abs)) throw new UsageError(`--page 指向的文件不存在:${page}`);
|
|
911
|
+
if (!isHtmlFile(abs)) throw new UsageError(`--page 只收 .html 文件:${page}`);
|
|
912
|
+
return rel;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** 面包屑:从 `--page` 的祖先目录推(有 index.html 的那一层取它的 title),不编造层级 */
|
|
916
|
+
function breadcrumbItems(dir, targetRel) {
|
|
917
|
+
const items = [];
|
|
918
|
+
const home = readPageFrom(dir, 'index.html');
|
|
919
|
+
if (home) items.push({ name: home.page.title || '首页', url: pageUrl('index.html') });
|
|
920
|
+
if (!targetRel || targetRel === 'index.html') return items;
|
|
921
|
+
const parts = targetRel.split('/');
|
|
922
|
+
const targetIsIndex = parts[parts.length - 1] === 'index.html';
|
|
923
|
+
let acc = '';
|
|
924
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
925
|
+
acc = acc ? `${acc}/${parts[i]}` : parts[i];
|
|
926
|
+
const indexPath = `${acc}/index.html`;
|
|
927
|
+
const found = readPageFrom(dir, indexPath);
|
|
928
|
+
if (found) items.push({ name: found.page.title || parts[i], url: pageUrl(indexPath) });
|
|
929
|
+
}
|
|
930
|
+
/* 目标本身就是某层 index.html 时,上面那圈已经把它收进来了,别再追加一次 */
|
|
931
|
+
if (!targetIsIndex) {
|
|
932
|
+
const target = readPageFrom(dir, targetRel);
|
|
933
|
+
if (target) items.push({ name: target.page.title || path.basename(targetRel), url: pageUrl(targetRel) });
|
|
934
|
+
}
|
|
935
|
+
return items;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** `<details><summary>问</summary>答</details>` → FAQ 条目(页面里真有才取,没有就是空数组) */
|
|
939
|
+
function extractFaq(html) {
|
|
940
|
+
const out = [];
|
|
941
|
+
for (const m of String(html == null ? '' : html).matchAll(/<details\b[^>]*>([\s\S]*?)<\/details>/gi)) {
|
|
942
|
+
const body = m[1];
|
|
943
|
+
const q = body.match(/<summary\b[^>]*>([\s\S]*?)<\/summary>/i);
|
|
944
|
+
if (!q) continue;
|
|
945
|
+
const question = collapse(stripTags(q[1]));
|
|
946
|
+
const answer = collapse(stripTags(body.replace(/<summary\b[^>]*>[\s\S]*?<\/summary>/i, ' ')));
|
|
947
|
+
if (question) out.push({ q: question, a: answer });
|
|
948
|
+
}
|
|
949
|
+
return out;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* 生成某一类 JSON-LD。
|
|
954
|
+
*
|
|
955
|
+
* 数据来源(按优先级):`site-manifest.json` / `manifest.json` / `site.json` →
|
|
956
|
+
* 目标页面(`--page`,默认首页)的 title / description / og:image / author / 时间 → 目录名。
|
|
957
|
+
* **缺的字段留空串 / 空数组 / 空对象**(并写进 `missing[]` 与 `notes[]`),绝不编造。
|
|
958
|
+
*/
|
|
959
|
+
export function buildSchema(dir, type, { page = '' } = {}) {
|
|
960
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
961
|
+
const allowed = SEO_SCHEMA_TYPES;
|
|
962
|
+
if (!allowed.includes(type)) {
|
|
963
|
+
throw new UsageError(`--type 只支持 ${allowed.join(' / ')},收到:${type || '(空)'}`);
|
|
964
|
+
}
|
|
965
|
+
const meta = readSiteMeta(absolute);
|
|
966
|
+
const manifest = findManifest(absolute);
|
|
967
|
+
const targetRel = resolvePageRel(absolute, page) || (fs.existsSync(path.join(absolute, 'index.html')) ? 'index.html' : listHtmlFiles(absolute)[0] || '');
|
|
968
|
+
const target = targetRel ? readPageFrom(absolute, targetRel) : null;
|
|
969
|
+
const p = target ? target.page : null;
|
|
970
|
+
const base = String(meta.url || '').replace(/\/+$/, '');
|
|
971
|
+
const pageAbs = targetRel ? `${base}${pageUrl(targetRel)}` : '';
|
|
972
|
+
const missing = [];
|
|
973
|
+
const notes = [...meta.notes];
|
|
974
|
+
|
|
975
|
+
const requireField = (value, key) => {
|
|
976
|
+
if (!value || (Array.isArray(value) && !value.length)) missing.push(key);
|
|
977
|
+
return value;
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
const jsonLd = { '@context': 'https://schema.org' };
|
|
981
|
+
|
|
982
|
+
if (type === 'organization') {
|
|
983
|
+
const logo = requireField(meta.logo, 'logo');
|
|
984
|
+
jsonLd['@type'] = 'Organization';
|
|
985
|
+
jsonLd.name = requireField(meta.name, 'name') || '';
|
|
986
|
+
jsonLd.url = requireField(base, 'url') || '';
|
|
987
|
+
jsonLd.logo = { '@type': 'ImageObject', url: logo || '' };
|
|
988
|
+
jsonLd.description = meta.description || '';
|
|
989
|
+
jsonLd.sameAs = [];
|
|
990
|
+
jsonLd.contactPoint = [];
|
|
991
|
+
} else if (type === 'website') {
|
|
992
|
+
jsonLd['@type'] = 'WebSite';
|
|
993
|
+
jsonLd.name = requireField(meta.name, 'name') || '';
|
|
994
|
+
jsonLd.url = requireField(base, 'url') || '';
|
|
995
|
+
jsonLd.description = meta.description || '';
|
|
996
|
+
jsonLd.inLanguage = meta.lang || '';
|
|
997
|
+
jsonLd.potentialAction = [];
|
|
998
|
+
} else if (type === 'article') {
|
|
999
|
+
const image = p && p.og['og:image'] ? p.og['og:image'] : '';
|
|
1000
|
+
jsonLd['@type'] = 'Article';
|
|
1001
|
+
jsonLd.headline = requireField(p && p.title, 'headline') || '';
|
|
1002
|
+
jsonLd.description = (p && p.description) || '';
|
|
1003
|
+
jsonLd.image = image ? [image] : [];
|
|
1004
|
+
jsonLd.datePublished = (p && p.published) || '';
|
|
1005
|
+
jsonLd.dateModified = (p && p.modified) || (p && p.published) || '';
|
|
1006
|
+
jsonLd.author = p && p.author ? { '@type': 'Person', name: p.author } : [];
|
|
1007
|
+
jsonLd.publisher = meta.name ? { '@type': 'Organization', name: meta.name } : {};
|
|
1008
|
+
jsonLd.inLanguage = (p && p.lang) || meta.lang || '';
|
|
1009
|
+
jsonLd.mainEntityOfPage = pageAbs;
|
|
1010
|
+
if (!jsonLd.datePublished) missing.push('datePublished');
|
|
1011
|
+
if (!jsonLd.author.length) missing.push('author');
|
|
1012
|
+
if (!image) missing.push('image');
|
|
1013
|
+
} else if (type === 'faq') {
|
|
1014
|
+
const fromManifest = Array.isArray(manifest.data && manifest.data.faq)
|
|
1015
|
+
? manifest.data.faq
|
|
1016
|
+
.map((one) => ({
|
|
1017
|
+
q: collapse(str(one && (one.q || one.question))),
|
|
1018
|
+
a: collapse(str(one && (one.a || one.answer))),
|
|
1019
|
+
}))
|
|
1020
|
+
.filter((one) => one.q)
|
|
1021
|
+
: [];
|
|
1022
|
+
const items = fromManifest.length ? fromManifest : p ? extractFaq(target.html) : [];
|
|
1023
|
+
jsonLd['@type'] = 'FAQPage';
|
|
1024
|
+
jsonLd.mainEntity = items.map((one) => ({
|
|
1025
|
+
'@type': 'Question',
|
|
1026
|
+
name: one.q,
|
|
1027
|
+
acceptedAnswer: { '@type': 'Answer', text: one.a || '' },
|
|
1028
|
+
}));
|
|
1029
|
+
if (!items.length) {
|
|
1030
|
+
missing.push('mainEntity');
|
|
1031
|
+
notes.push('页面里没有 <details>/<summary> 问答,清单里也没有 faq[]:mainEntity 留空数组(不编造问答)');
|
|
1032
|
+
}
|
|
1033
|
+
} else if (type === 'breadcrumb') {
|
|
1034
|
+
const items = breadcrumbItems(absolute, targetRel);
|
|
1035
|
+
jsonLd['@type'] = 'BreadcrumbList';
|
|
1036
|
+
jsonLd.itemListElement = items.map((one, index) => ({
|
|
1037
|
+
'@type': 'ListItem',
|
|
1038
|
+
position: index + 1,
|
|
1039
|
+
name: one.name,
|
|
1040
|
+
item: base ? `${base}${one.url}` : one.url,
|
|
1041
|
+
}));
|
|
1042
|
+
if (!base) notes.push('没有站点 URL:面包屑的 item 用相对路径(Google 要求绝对地址,补 --base-url 或清单 site.url)');
|
|
1043
|
+
if (!items.length) missing.push('itemListElement');
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
const pretty = `${JSON.stringify(jsonLd, null, 2)}\n`;
|
|
1047
|
+
return {
|
|
1048
|
+
dir: absolute,
|
|
1049
|
+
type,
|
|
1050
|
+
json_ld: jsonLd,
|
|
1051
|
+
json: pretty,
|
|
1052
|
+
source: { page: targetRel || null, manifest: manifest.file },
|
|
1053
|
+
missing,
|
|
1054
|
+
notes,
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/* ------------------------------------------------------------------ sitemap.xml / robots.txt 门禁 */
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* 校验 sitemap.xml / robots.txt(不联网)。
|
|
1062
|
+
* `ok = 没有任何 error`;warn(重复 URL、相对地址、Sitemap: 域名不一致)不影响 exit code。
|
|
1063
|
+
*/
|
|
1064
|
+
export function checkSeoFiles(dir) {
|
|
1065
|
+
const absolute = path.resolve(String(dir || '.'));
|
|
1066
|
+
const issues = [];
|
|
1067
|
+
const add = (severity, file, rule, message, suggestion) => issues.push({ severity, file, rule, message, suggestion });
|
|
1068
|
+
|
|
1069
|
+
const sitemapPath = path.join(absolute, 'sitemap.xml');
|
|
1070
|
+
const sitemapText = readFileSafe(sitemapPath);
|
|
1071
|
+
const sitemap = { path: sitemapPath, exists: sitemapText !== null, xml_ok: false, locs: [], empty_locs: 0, duplicates: [], relative_locs: 0, errors: [] };
|
|
1072
|
+
if (sitemapText === null) {
|
|
1073
|
+
add('error', 'sitemap.xml', 'sitemap_missing', '没有 sitemap.xml', '生成标准 urlset(至少 1 条 <loc>),再在 robots.txt 里宣告');
|
|
1074
|
+
} else {
|
|
1075
|
+
const parsed = parseXml(sitemapText);
|
|
1076
|
+
sitemap.xml_ok = parsed.ok;
|
|
1077
|
+
sitemap.errors = parsed.errors;
|
|
1078
|
+
if (!parsed.ok) {
|
|
1079
|
+
for (const one of parsed.errors.slice(0, 5)) add('error', 'sitemap.xml', 'sitemap_xml', `XML 不合法:${one}`, '补闭合标签、把 & 写成 &');
|
|
1080
|
+
}
|
|
1081
|
+
const locs = sitemapLocs(sitemapText);
|
|
1082
|
+
sitemap.locs = locs;
|
|
1083
|
+
if (!locs.length) add('error', 'sitemap.xml', 'sitemap_empty', '<loc> 一条都没有', '至少收录首页 + 已发布页面');
|
|
1084
|
+
const byUrl = new Map();
|
|
1085
|
+
locs.forEach((loc, index) => {
|
|
1086
|
+
if (!loc) {
|
|
1087
|
+
sitemap.empty_locs += 1;
|
|
1088
|
+
add('error', 'sitemap.xml', 'sitemap_loc_empty', `第 ${index + 1} 条 <loc> 为空`, '删掉空条目,或补上绝对地址');
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const hit = byUrl.get(loc);
|
|
1092
|
+
if (hit) hit.push(index + 1);
|
|
1093
|
+
else byUrl.set(loc, [index + 1]);
|
|
1094
|
+
if (!/^https?:\/\//i.test(loc)) sitemap.relative_locs += 1;
|
|
1095
|
+
});
|
|
1096
|
+
for (const [url, positions] of byUrl) {
|
|
1097
|
+
if (positions.length < 2) continue;
|
|
1098
|
+
sitemap.duplicates.push({ url, positions });
|
|
1099
|
+
add('warn', 'sitemap.xml', 'sitemap_duplicate_url', `URL 重复:${url}(第 ${positions.join(' / ')} 条)`, '一条 URL 只留一条;重复会被爬虫判成低质量');
|
|
1100
|
+
}
|
|
1101
|
+
if (sitemap.relative_locs) {
|
|
1102
|
+
add('warn', 'sitemap.xml', 'sitemap_loc_relative', `${sitemap.relative_locs} 条 <loc> 不是绝对地址`, 'sitemap 协议要求绝对地址(https://域名/路径)');
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
const robotsPath = path.join(absolute, 'robots.txt');
|
|
1107
|
+
const robotsText = readFileSafe(robotsPath);
|
|
1108
|
+
const robots = { path: robotsPath, exists: robotsText !== null, directives: [], sitemap_lines: [], issues: [] };
|
|
1109
|
+
if (robotsText === null) {
|
|
1110
|
+
add('warn', 'robots.txt', 'robots_missing', '没有 robots.txt', '至少写 `User-agent: *` + `Allow: /` + `Sitemap: <站点>/sitemap.xml`');
|
|
1111
|
+
} else {
|
|
1112
|
+
const parsed = analyzeRobots(robotsText);
|
|
1113
|
+
robots.directives = parsed.directives;
|
|
1114
|
+
robots.sitemap_lines = parsed.sitemapLines;
|
|
1115
|
+
for (const one of parsed.issues) {
|
|
1116
|
+
robots.issues.push({ ...one });
|
|
1117
|
+
add(one.severity, 'robots.txt', one.rule, one.message, one.suggestion);
|
|
1118
|
+
}
|
|
1119
|
+
if (!parsed.sitemapLines.length) {
|
|
1120
|
+
add('warn', 'robots.txt', 'robots_no_sitemap', 'robots.txt 里没有 Sitemap: 行', '加一行 `Sitemap: https://<域名>/sitemap.xml`');
|
|
1121
|
+
}
|
|
1122
|
+
/** Sitemap: 行必须指向这份 sitemap.xml(路径 /sitemap.xml、域名与 sitemap 里的 loc 一致) */
|
|
1123
|
+
const sitemapOrigins = new Set(
|
|
1124
|
+
sitemap.locs
|
|
1125
|
+
.filter((loc) => /^https?:\/\//i.test(loc))
|
|
1126
|
+
.map((loc) => {
|
|
1127
|
+
try {
|
|
1128
|
+
return new URL(loc).origin;
|
|
1129
|
+
} catch {
|
|
1130
|
+
return '';
|
|
1131
|
+
}
|
|
1132
|
+
})
|
|
1133
|
+
.filter(Boolean),
|
|
1134
|
+
);
|
|
1135
|
+
for (const line of parsed.sitemapLines) {
|
|
1136
|
+
const value = line.value;
|
|
1137
|
+
if (!/^https?:\/\//i.test(value)) {
|
|
1138
|
+
add('warn', 'robots.txt', 'robots_sitemap_not_absolute', `第 ${line.line} 行 Sitemap: 不是绝对地址:${value || '(空)'}`, '写成 `Sitemap: https://<域名>/sitemap.xml`');
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
let url = null;
|
|
1142
|
+
try {
|
|
1143
|
+
url = new URL(value);
|
|
1144
|
+
} catch {
|
|
1145
|
+
add('warn', 'robots.txt', 'robots_sitemap_invalid', `第 ${line.line} 行 Sitemap: 不是合法 URL:${value}`, '检查协议与域名拼写');
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (url.pathname !== '/sitemap.xml') {
|
|
1149
|
+
add('warn', 'robots.txt', 'robots_sitemap_path', `第 ${line.line} 行 Sitemap: 指向 ${url.pathname},这份文件在 /sitemap.xml`, '路径与站点实际的 sitemap.xml 对齐');
|
|
1150
|
+
}
|
|
1151
|
+
if (sitemapOrigins.size && !sitemapOrigins.has(url.origin)) {
|
|
1152
|
+
add('warn', 'robots.txt', 'robots_sitemap_origin', `Sitemap: 的域名 ${url.origin} 与 sitemap.xml 里的域名 ${[...sitemapOrigins].join(' / ')} 不一致`, '两处用同一个站点域名');
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
const summary = { error: 0, warn: 0, info: 0, total: issues.length };
|
|
1158
|
+
for (const one of issues) summary[one.severity] = (summary[one.severity] || 0) + 1;
|
|
1159
|
+
return { dir: absolute, ok: summary.error === 0, sitemap, robots, issues, summary };
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/* ------------------------------------------------------------------ 写盘 / 命令
|
|
1163
|
+
|
|
1164
|
+
/** 写文本文件(自动建父目录);返回 `{ path, bytes, chars }` */
|
|
1165
|
+
function writeTextFile(file, content) {
|
|
1166
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1167
|
+
fs.writeFileSync(file, content, 'utf8');
|
|
1168
|
+
return { path: file, bytes: Buffer.byteLength(content, 'utf8'), chars: charCount(content) };
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/** 位置参数 `<目录>` → 绝对路径(不存在 / 不是目录直接 usage 错,exit 2) */
|
|
1172
|
+
function resolveDirArg(raw) {
|
|
1173
|
+
const dir = path.resolve(process.cwd(), String(raw || '.'));
|
|
1174
|
+
let stat = null;
|
|
1175
|
+
try {
|
|
1176
|
+
stat = fs.statSync(dir);
|
|
1177
|
+
} catch {
|
|
1178
|
+
stat = null;
|
|
1179
|
+
}
|
|
1180
|
+
if (!stat) throw new UsageError(`目录不存在:${dir}`);
|
|
1181
|
+
if (!stat.isDirectory()) throw new UsageError(`不是目录:${dir}`);
|
|
1182
|
+
return dir;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/* ------------------------------------------------------------------ seo audit */
|
|
1186
|
+
|
|
1187
|
+
export const seoAuditCommand = {
|
|
1188
|
+
name: 'seo audit',
|
|
1189
|
+
summary: '本地站点产物 SEO 体检:13 项加权评分(0-100)+ issues[](error/warn/info)+ 等级,只读',
|
|
1190
|
+
usage: 'wkgeo seo audit <目录> [--json]',
|
|
1191
|
+
args: [{ name: 'dir', required: true, desc: '站点产物目录(含 index.html 等静态页面)' }],
|
|
1192
|
+
flags: {},
|
|
1193
|
+
examples: ['wkgeo seo audit .tmp-build/seo-fixture', 'wkgeo seo audit ./dist --json'],
|
|
1194
|
+
notes: [
|
|
1195
|
+
'13 项(权重合计 100):title 10 / description 10 / keywords 4 / canonical 7 / og 12 / JSON-LD 10 / h1 9 / 标题层级 6 / 图片 alt 9 / 内链死链 12 / llms.txt 4 / sitemap.xml 4 / robots.txt 3。',
|
|
1196
|
+
'按页算的 10 项取「通过页数 / 总页数」的比例分;站点级的 3 项整目录只算一次。',
|
|
1197
|
+
'**报告命令**:有问题也 exit 0(看 `data.score` / `data.summary`);只有目录不存在(exit 2)或目录里没有 .html(exit 1)才非 0。',
|
|
1198
|
+
'只读:不联网、不写任何文件(要补文件用 `seo llms` / `seo schema`,要门禁用 `seo files`)。',
|
|
1199
|
+
],
|
|
1200
|
+
async run(ctx) {
|
|
1201
|
+
const { out } = ctx;
|
|
1202
|
+
const dir = resolveDirArg(ctx.positional.dir);
|
|
1203
|
+
const result = auditDirectory(dir);
|
|
1204
|
+
if (!out.json) {
|
|
1205
|
+
out.head(`SEO 审计 ${result.dir}`);
|
|
1206
|
+
out.line(` 页面 ${result.pages} 个 · 得分 ${result.score}/100(${result.grade}) · error ${result.summary.error} / warn ${result.summary.warn} / info ${result.summary.info}`);
|
|
1207
|
+
out.line('');
|
|
1208
|
+
out.line(' 逐项:');
|
|
1209
|
+
for (const rule of result.rules) {
|
|
1210
|
+
const mark = rule.passed === rule.total ? '✓' : '✗';
|
|
1211
|
+
out.line(` ${mark} ${rule.id.padEnd(14)} ${String(rule.score).padStart(3)}/${String(rule.weight).padStart(3)} ${rule.title}(${rule.passed}/${rule.total})`);
|
|
1212
|
+
}
|
|
1213
|
+
if (result.issues.length) {
|
|
1214
|
+
out.line('');
|
|
1215
|
+
out.line(' 问题:');
|
|
1216
|
+
for (const issue of result.issues.slice(0, 30)) {
|
|
1217
|
+
out.line(` [${issue.severity}] ${issue.file} ${issue.rule} ${issue.message}`);
|
|
1218
|
+
out.line(` ↳ ${issue.suggestion}`);
|
|
1219
|
+
}
|
|
1220
|
+
if (result.issues.length > 30) out.line(` … 还有 ${result.issues.length - 30} 条(--json 看全量)`);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (!out.json) out.ok(`审计完成:${result.score} 分(${result.grade})· ${result.summary.total} 条问题`);
|
|
1224
|
+
ctx.done(result);
|
|
1225
|
+
},
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
/* ------------------------------------------------------------------ seo llms */
|
|
1229
|
+
|
|
1230
|
+
export const seoLlmsCommand = {
|
|
1231
|
+
name: 'seo llms',
|
|
1232
|
+
summary: '按目录生成 llms.txt(一级/二级页面 + 一句话摘要)与 llms-full.txt(正文摘录),默认 dry-run',
|
|
1233
|
+
usage: 'wkgeo seo llms <目录> [--base-url <站点基址>] [--confirm] [--json]',
|
|
1234
|
+
args: [{ name: 'dir', required: true, desc: '站点产物目录(会写到 <目录>/llms.txt 与 <目录>/llms-full.txt)' }],
|
|
1235
|
+
flags: {
|
|
1236
|
+
'base-url': { type: 'string', desc: '生成绝对链接的站点基址(如 https://www.example.com;不给就写相对路径)' },
|
|
1237
|
+
confirm: { type: 'boolean', desc: '真的写盘(不加就是 dry-run,只打印)' },
|
|
1238
|
+
},
|
|
1239
|
+
examples: [
|
|
1240
|
+
'wkgeo seo llms .tmp-build/seo-fixture',
|
|
1241
|
+
'wkgeo seo llms .tmp-build/seo-fixture --base-url https://www.example.com --confirm',
|
|
1242
|
+
'wkgeo seo llms ./dist --json',
|
|
1243
|
+
],
|
|
1244
|
+
notes: [
|
|
1245
|
+
'**默认 dry-run**:把两份文件内容打印出来,一个字节都不写;要写必须显式 `--confirm`。',
|
|
1246
|
+
'llms.txt:站点标题 + 描述 + 「一级页面(目录根)/ 二级页面(子目录)」两组 `- [标题](URL):摘要`;摘要取 meta description,没有就取正文第一段。',
|
|
1247
|
+
'llms-full.txt:站点头 + 每页 `## 标题` / `URL:` / 正文纯文本摘录(每页上限 3000 字符)。',
|
|
1248
|
+
'标题 / 描述 / 摘要都从页面与站点清单里取,取不到就留空,不编造。',
|
|
1249
|
+
],
|
|
1250
|
+
async run(ctx) {
|
|
1251
|
+
const { out, flags } = ctx;
|
|
1252
|
+
const dir = resolveDirArg(ctx.positional.dir);
|
|
1253
|
+
const result = buildLlms(dir, { baseUrl: flags.baseUrl || '' });
|
|
1254
|
+
if (!out.json) {
|
|
1255
|
+
out.head(`llms.txt${flags.confirm === true ? '(写盘)' : '(dry-run,加 --confirm 才写)'} · ${result.dir}`);
|
|
1256
|
+
out.line(result.llms_txt.content.replace(/\n$/, ''));
|
|
1257
|
+
out.head(`llms-full.txt${flags.confirm === true ? '(写盘)' : '(dry-run,加 --confirm 才写)'}`);
|
|
1258
|
+
out.line(result.llms_full.content.replace(/\n$/, ''));
|
|
1259
|
+
}
|
|
1260
|
+
const written = [];
|
|
1261
|
+
if (flags.confirm === true) {
|
|
1262
|
+
written.push({ name: 'llms.txt', ...writeTextFile(result.llms_txt.path, result.llms_txt.content) });
|
|
1263
|
+
written.push({ name: 'llms-full.txt', ...writeTextFile(result.llms_full.path, result.llms_full.content) });
|
|
1264
|
+
if (!out.json) out.ok(`已写入 ${result.llms_txt.path} / ${result.llms_full.path}(${written[0].chars} / ${written[1].chars} 字符)`);
|
|
1265
|
+
} else if (!out.json) {
|
|
1266
|
+
out.ok('dry-run:没有写任何文件(加 --confirm 写入 llms.txt / llms-full.txt)');
|
|
1267
|
+
}
|
|
1268
|
+
ctx.done({
|
|
1269
|
+
dir: result.dir,
|
|
1270
|
+
dry_run: flags.confirm !== true,
|
|
1271
|
+
base_url: result.base_url,
|
|
1272
|
+
site: result.site,
|
|
1273
|
+
notes: result.notes,
|
|
1274
|
+
pages: result.pages,
|
|
1275
|
+
llms_txt: { path: result.llms_txt.path, chars: result.llms_txt.chars, content: result.llms_txt.content },
|
|
1276
|
+
llms_full: { path: result.llms_full.path, chars: result.llms_full.chars, content: result.llms_full.content },
|
|
1277
|
+
written,
|
|
1278
|
+
});
|
|
1279
|
+
},
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
/* ------------------------------------------------------------------ seo schema */
|
|
1283
|
+
|
|
1284
|
+
export const seoSchemaCommand = {
|
|
1285
|
+
name: 'seo schema',
|
|
1286
|
+
summary: '生成 organization / website / article / faq / breadcrumb 的 JSON-LD(默认打印,--confirm 写 <目录>/seo/schema.<type>.jsonld)',
|
|
1287
|
+
usage: 'wkgeo seo schema <目录> --type <organization|website|article|faq|breadcrumb> [--page <相对页面>] [--confirm] [--json]',
|
|
1288
|
+
args: [{ name: 'dir', required: true, desc: '站点产物目录(字段从目录里的页面/清单提取)' }],
|
|
1289
|
+
flags: {
|
|
1290
|
+
type: { type: 'string', required: true, desc: `JSON-LD 类型:${SEO_SCHEMA_TYPES.join('|')}` },
|
|
1291
|
+
page: { type: 'string', desc: '取哪一页做数据源(相对目录路径;默认 index.html)。article / breadcrumb 用得上' },
|
|
1292
|
+
confirm: { type: 'boolean', desc: '真的写盘(不加就只打印 JSON)' },
|
|
1293
|
+
},
|
|
1294
|
+
examples: [
|
|
1295
|
+
'wkgeo seo schema .tmp-build/seo-fixture --type organization',
|
|
1296
|
+
'wkgeo seo schema .tmp-build/seo-fixture --type article --page about.html --confirm',
|
|
1297
|
+
'wkgeo seo schema .tmp-build/seo-fixture --type breadcrumb --page blog/index.html --json',
|
|
1298
|
+
],
|
|
1299
|
+
notes: [
|
|
1300
|
+
'**默认只打印 JSON**;`--confirm` 才写 `<目录>/seo/schema.<type>.jsonld`(目录自动创建)。',
|
|
1301
|
+
'字段来源:`site-manifest.json` / `manifest.json` / `site.json` → 目标页面的 title / description / og:image / author / 时间 → 目录名。',
|
|
1302
|
+
'**缺的字段留空串 / 空数组 / 空对象**(并在 `data.missing` / `data.notes` 里点名),不编造公司名、地址、评分、日期。',
|
|
1303
|
+
'faq 只从页面 `<details><summary>` 或清单 `faq[]` 取;没有就是空 `mainEntity`。breadcrumb 只从目录层级 + 页面标题推。',
|
|
1304
|
+
],
|
|
1305
|
+
async run(ctx) {
|
|
1306
|
+
const { out, flags } = ctx;
|
|
1307
|
+
const dir = resolveDirArg(ctx.positional.dir);
|
|
1308
|
+
const type = String(flags.type || '').trim();
|
|
1309
|
+
const result = buildSchema(dir, type, { page: flags.page || '' });
|
|
1310
|
+
const target = path.join(dir, 'seo', `schema.${type}.jsonld`);
|
|
1311
|
+
if (!out.json) {
|
|
1312
|
+
out.head(`JSON-LD ${type}${flags.confirm === true ? '(写盘)' : '(dry-run,加 --confirm 才写)'} · ${result.source.page || '(无页面)'}`);
|
|
1313
|
+
out.line(result.json.replace(/\n$/, ''));
|
|
1314
|
+
if (result.missing.length) out.line(`\n 缺的字段(留空,未编造):${result.missing.join('、')}`);
|
|
1315
|
+
for (const note of result.notes) out.line(` · ${note}`);
|
|
1316
|
+
}
|
|
1317
|
+
const written = [];
|
|
1318
|
+
if (flags.confirm === true) {
|
|
1319
|
+
written.push({ name: `schema.${type}.jsonld`, ...writeTextFile(target, result.json) });
|
|
1320
|
+
if (!out.json) out.ok(`已写入 ${target}(${written[0].chars} 字符)`);
|
|
1321
|
+
} else if (!out.json) {
|
|
1322
|
+
out.ok(`dry-run:没有写文件(加 --confirm 写入 ${target})`);
|
|
1323
|
+
}
|
|
1324
|
+
ctx.done({
|
|
1325
|
+
dir: result.dir,
|
|
1326
|
+
type: result.type,
|
|
1327
|
+
dry_run: flags.confirm !== true,
|
|
1328
|
+
path: target,
|
|
1329
|
+
json_ld: result.json_ld,
|
|
1330
|
+
json: result.json,
|
|
1331
|
+
source: result.source,
|
|
1332
|
+
missing: result.missing,
|
|
1333
|
+
notes: result.notes,
|
|
1334
|
+
written,
|
|
1335
|
+
});
|
|
1336
|
+
},
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
/* ------------------------------------------------------------------ seo files */
|
|
1340
|
+
|
|
1341
|
+
export const seoFilesCommand = {
|
|
1342
|
+
name: 'seo files',
|
|
1343
|
+
summary: '校验 sitemap.xml(XML 良构 / <loc> 非空 / URL 去重)与 robots.txt(语法 / Sitemap: 一致),不联网',
|
|
1344
|
+
usage: 'wkgeo seo files <目录> [--json]',
|
|
1345
|
+
args: [{ name: 'dir', required: true, desc: '站点产物目录(读 sitemap.xml 与 robots.txt)' }],
|
|
1346
|
+
flags: {},
|
|
1347
|
+
examples: ['wkgeo seo files .tmp-build/seo-fixture', 'wkgeo seo files ./dist --json'],
|
|
1348
|
+
notes: [
|
|
1349
|
+
'**门禁命令**:任何 error ⇒ exit 1(`--json` 时完整 issues 在 `error.details`);warn 不影响退出码。',
|
|
1350
|
+
'error:sitemap.xml 缺失 / XML 不合法 / `<loc>` 为空 / 一条都没有;robots.txt 某行语法不对。',
|
|
1351
|
+
'warn:URL 重复 / `<loc>` 不是绝对地址 / robots.txt 缺失或没有 `Sitemap:` 行 / `Sitemap:` 与 sitemap.xml 的路径或域名不一致。',
|
|
1352
|
+
'**不联网**:只校验本地文件之间的关系,不验证 URL 能不能访问(线上可达性是发布后的事)。',
|
|
1353
|
+
],
|
|
1354
|
+
async run(ctx) {
|
|
1355
|
+
const { out } = ctx;
|
|
1356
|
+
const dir = resolveDirArg(ctx.positional.dir);
|
|
1357
|
+
const result = checkSeoFiles(dir);
|
|
1358
|
+
if (!out.json) {
|
|
1359
|
+
out.head(`SEO 文件校验 ${result.dir}`);
|
|
1360
|
+
out.line(` sitemap.xml:${result.sitemap.exists ? (result.sitemap.xml_ok ? 'XML 合法' : 'XML 不合法') : '缺失'} · ${result.sitemap.locs.length} 条 <loc> · 重复 ${result.sitemap.duplicates.length} · 空 <loc> ${result.sitemap.empty_locs}`);
|
|
1361
|
+
out.line(` robots.txt:${result.robots.exists ? '存在' : '缺失'} · Sitemap: 行 ${result.robots.sitemap_lines.length} · 指令 ${result.robots.directives.length}`);
|
|
1362
|
+
if (result.issues.length) {
|
|
1363
|
+
out.line('');
|
|
1364
|
+
out.line(' 问题:');
|
|
1365
|
+
for (const issue of result.issues) {
|
|
1366
|
+
out.line(` [${issue.severity}] ${issue.file} ${issue.rule} ${issue.message}`);
|
|
1367
|
+
out.line(` ↳ ${issue.suggestion}`);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
if (!result.ok) {
|
|
1372
|
+
throw new CliError(`SEO 文件校验未通过:${result.summary.error} 个 error / ${result.summary.warn} 个 warn`, {
|
|
1373
|
+
kind: 'validate',
|
|
1374
|
+
code: 'ESEOFILES',
|
|
1375
|
+
exitCode: 1,
|
|
1376
|
+
hint: '按上面逐条改;`--json` 的 `error.details.issues` 有完整清单',
|
|
1377
|
+
details: result,
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
if (!out.json) out.ok(`SEO 文件校验通过:${result.summary.warn} 个 warn(不影响退出码)`);
|
|
1381
|
+
ctx.done(result);
|
|
1382
|
+
},
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
/** `seo` 组四条命令(注册在 `cli/lib/commands/index.mjs`) */
|
|
1386
|
+
export const seoCommands = [seoAuditCommand, seoLlmsCommand, seoSchemaCommand, seoFilesCommand];
|