@cobola/dsh-geo 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +65 -0
- package/CHANGELOG.md +27 -0
- package/CONTRIBUTING.md +86 -0
- package/LICENSE +176 -0
- package/NOTICE +14 -0
- package/README.md +228 -2
- package/SECURITY.md +46 -0
- package/bin/dsh-geo.js +381 -0
- package/client.js +707 -0
- package/cordis.patch.yml +4 -0
- package/docs/.nojekyll +0 -0
- package/docs/CI.md +118 -0
- package/docs/GOOGLE.md +57 -0
- package/docs/NPM-TRUSTED-PUBLISHING.md +69 -0
- package/docs/PROFILES.md +51 -0
- package/docs/RULES.md +108 -0
- package/docs/icons/geo.svg +8 -0
- package/docs/index.json +41 -0
- package/icon.svg +8 -0
- package/index.js +381 -0
- package/lib/audit.js +62 -0
- package/lib/fetch.js +650 -0
- package/lib/html.js +651 -0
- package/lib/platforms/bing.js +95 -0
- package/lib/platforms/index.js +70 -0
- package/lib/profiles.js +62 -0
- package/lib/report.js +404 -0
- package/lib/robots.js +209 -0
- package/lib/rules.js +939 -0
- package/lib/scan.js +604 -0
- package/lib/score.js +145 -0
- package/lib/store.js +283 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +77 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bing / Copilot profile.
|
|
3
|
+
*
|
|
4
|
+
* Separate from the Core score: these checks reflect Bing's own documentation
|
|
5
|
+
* and do not change the site's Core visibility score.
|
|
6
|
+
*
|
|
7
|
+
* Sources (retrieved 2026-11-29):
|
|
8
|
+
* - Bing Webmaster Guidelines
|
|
9
|
+
* https://www.bing.com/webmasters/help/webmaster-guidelines-30fba23a
|
|
10
|
+
* - Robots meta tags and attributes Bing supports
|
|
11
|
+
* https://www.bing.com/webmasters/help/robots-meta-tags-and-attributes-that-bing-supports-5198d240
|
|
12
|
+
* - Sitemaps in AI-powered search
|
|
13
|
+
* https://blogs.bing.com/webmaster/July-2025/Keep-Content-Discoverable-with-Sitemaps-in-AI-Powered-Search
|
|
14
|
+
*/
|
|
15
|
+
export const BING_PROFILE = {
|
|
16
|
+
id: 'bing',
|
|
17
|
+
title: 'Bing / Copilot',
|
|
18
|
+
sources: [
|
|
19
|
+
'https://www.bing.com/webmasters/help/webmaster-guidelines-30fba23a',
|
|
20
|
+
'https://www.bing.com/webmasters/help/robots-meta-tags-and-attributes-that-bing-supports-5198d240',
|
|
21
|
+
'https://blogs.bing.com/webmaster/July-2025/Keep-Content-Discoverable-with-Sitemaps-in-AI-Powered-Search',
|
|
22
|
+
],
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
id: 'bing.bingbot-access',
|
|
26
|
+
weight: 4,
|
|
27
|
+
title: 'Bingbot 可抓取',
|
|
28
|
+
fix: '在 robots.txt 中允许 Bingbot 抓取公开页面;Bing Search 与 Copilot grounding 都依赖它。',
|
|
29
|
+
evaluate({ scan }) {
|
|
30
|
+
if (!scan.robots.found) return { status: 'pass', evidence: '无 robots.txt,默认允许 Bingbot' };
|
|
31
|
+
if (scan.robots.unreachable) return { status: 'warn', evidence: 'robots.txt 不可访问,Bingbot 抓取可能受影响' };
|
|
32
|
+
const access = scan.robots.bingbot ?? { allowed: true, previewAllowed: true };
|
|
33
|
+
if (access.allowed === false) return { status: 'fail', evidence: 'robots.txt 明确禁止 Bingbot 抓取' };
|
|
34
|
+
if (access.previewAllowed === false) return { status: 'warn', evidence: 'Bingbot 可抓取,但 BingPreview 被禁止' };
|
|
35
|
+
return { status: 'pass', evidence: 'robots.txt 允许 Bingbot' };
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'bing.bingbot-directives',
|
|
40
|
+
weight: 2,
|
|
41
|
+
title: '页面级 bingbot 指令不误伤',
|
|
42
|
+
fix: '避免在 meta name="bingbot" 或 X-Robots-Tag 中对公开页面使用 noindex;nosnippet 仅用于确实不应出现在摘要中的内容。',
|
|
43
|
+
evaluate({ factsPages }) {
|
|
44
|
+
if (factsPages.length === 0) return { status: 'fail', evidence: '未抓取到 HTML 页面' };
|
|
45
|
+
const blocked = [];
|
|
46
|
+
const nosnippet = [];
|
|
47
|
+
for (const page of factsPages) {
|
|
48
|
+
const meta = page.facts.metaBingbot ?? '';
|
|
49
|
+
const header = (page.headers?.['x-robots-tag'] ?? '').toLowerCase();
|
|
50
|
+
if (meta.includes('noindex') || /bingbot\s*:\s*[^,]*noindex/.test(header)) {
|
|
51
|
+
blocked.push(page.path);
|
|
52
|
+
} else if (meta.includes('nosnippet') || /bingbot\s*:\s*[^,]*nosnippet/.test(header)) {
|
|
53
|
+
nosnippet.push(page.path);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (blocked.length > 0) return { status: 'fail', evidence: `bingbot noindex:${blocked.slice(0, 3).join(', ')}` };
|
|
57
|
+
if (nosnippet.length > 0) return { status: 'warn', evidence: `bingbot nosnippet:${nosnippet.slice(0, 3).join(', ')}` };
|
|
58
|
+
return { status: 'pass', evidence: '没有 bingbot 级别的 noindex/nosnippet 指令' };
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'bing.sitemap',
|
|
63
|
+
weight: 2,
|
|
64
|
+
title: 'XML sitemap 可供 Bing 使用',
|
|
65
|
+
fix: '发布并声明 /sitemap.xml;Bing 持续支持 Sitemap 协议,它仍是 AI 搜索发现内容的基础信号。',
|
|
66
|
+
evaluate({ scan }) {
|
|
67
|
+
if (scan.sitemap.valid) return { status: 'pass', evidence: `${scan.sitemap.urlCount} 个 URL` };
|
|
68
|
+
if (scan.sitemap.found) return { status: 'warn', evidence: 'sitemap 可访问但无有效 URL' };
|
|
69
|
+
return { status: 'fail', evidence: '未找到可用的 XML sitemap' };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'bing.webmaster-verification',
|
|
74
|
+
weight: 1,
|
|
75
|
+
title: 'Bing Webmaster 验证标识',
|
|
76
|
+
fix: '在首页添加 <meta name="msvalidate.01" content="...">,用于 Bing Webmaster Tools 站点验证与 IndexNow 管理。',
|
|
77
|
+
evaluate({ primary }) {
|
|
78
|
+
if (!primary) return { status: 'fail', evidence: '未抓取到 HTML 入口页' };
|
|
79
|
+
if (primary.facts.meta['msvalidate.01']) return { status: 'pass', evidence: '存在 msvalidate.01 验证 meta' };
|
|
80
|
+
return { status: 'skip', evidence: '未提供 msvalidate.01;这是可选的站长平台验证标识' };
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'bing.snippet-controls',
|
|
85
|
+
weight: 1,
|
|
86
|
+
title: '使用 Bing 支持的摘要控制',
|
|
87
|
+
fix: '如需对部分内容控制摘要展示,使用 Bing 支持的 data-nosnippet 属性,而不是整页 noindex。',
|
|
88
|
+
evaluate({ factsPages }) {
|
|
89
|
+
const pages = factsPages.filter((page) => (page.facts.dataNosnippetCount ?? 0) > 0);
|
|
90
|
+
if (pages.length > 0) return { status: 'pass', evidence: `${pages.length} 个页面使用 data-nosnippet` };
|
|
91
|
+
return { status: 'skip', evidence: '未使用 data-nosnippet;只有需要局部摘要控制时才需要' };
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform profile evaluation.
|
|
3
|
+
*
|
|
4
|
+
* Profiles score separately from Core: a profile's score never changes the
|
|
5
|
+
* site's Core total. Every profile declares its official sources, and each
|
|
6
|
+
* rule returns evidence, a repair hint and an explicit status.
|
|
7
|
+
*/
|
|
8
|
+
import { BING_PROFILE } from './bing.js';
|
|
9
|
+
|
|
10
|
+
export const PLATFORM_PROFILES = [BING_PROFILE];
|
|
11
|
+
|
|
12
|
+
const STATUS_FACTOR = { pass: 1, warn: 0.5, fail: 0, skip: 0 };
|
|
13
|
+
|
|
14
|
+
function round1(value) {
|
|
15
|
+
return Math.round(value * 10) / 10;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function scoreProfile(profile, ctx) {
|
|
19
|
+
const findings = profile.rules.map((rule) => {
|
|
20
|
+
let outcome;
|
|
21
|
+
try {
|
|
22
|
+
outcome = rule.evaluate(ctx);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
outcome = { status: 'fail', evidence: `规则执行异常:${error?.message ?? String(error)}` };
|
|
25
|
+
}
|
|
26
|
+
if (!outcome || !['pass', 'warn', 'fail', 'skip'].includes(outcome.status)) {
|
|
27
|
+
outcome = { status: 'fail', evidence: '规则未返回有效结论' };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
id: rule.id,
|
|
31
|
+
platform: profile.id,
|
|
32
|
+
weight: rule.weight,
|
|
33
|
+
title: rule.title,
|
|
34
|
+
status: outcome.status,
|
|
35
|
+
evidence: outcome.evidence ?? '',
|
|
36
|
+
fix: rule.fix,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const applicable = findings.reduce((sum, finding) => sum + (finding.status === 'skip' ? 0 : finding.weight), 0);
|
|
41
|
+
const earned = findings.reduce((sum, finding) => sum + finding.weight * (STATUS_FACTOR[finding.status] ?? 0), 0);
|
|
42
|
+
const total = applicable > 0 ? round1((earned / applicable) * 100) : 0;
|
|
43
|
+
const actions = findings
|
|
44
|
+
.filter((finding) => finding.status === 'fail' || finding.status === 'warn')
|
|
45
|
+
.sort((a, b) => b.weight - a.weight || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
id: profile.id,
|
|
49
|
+
title: profile.title,
|
|
50
|
+
sources: [...profile.sources],
|
|
51
|
+
total,
|
|
52
|
+
scored: applicable > 0,
|
|
53
|
+
counts: {
|
|
54
|
+
pass: findings.filter((finding) => finding.status === 'pass').length,
|
|
55
|
+
warn: findings.filter((finding) => finding.status === 'warn').length,
|
|
56
|
+
fail: findings.filter((finding) => finding.status === 'fail').length,
|
|
57
|
+
skip: findings.filter((finding) => finding.status === 'skip').length,
|
|
58
|
+
},
|
|
59
|
+
findings,
|
|
60
|
+
actions,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Evaluate every platform profile against one scan artifact.
|
|
66
|
+
* @param {{scan: object, primary: object|null, pages: object[], factsPages: object[]}} ctx
|
|
67
|
+
*/
|
|
68
|
+
export function evaluatePlatforms(ctx) {
|
|
69
|
+
return PLATFORM_PROFILES.map((profile) => scoreProfile(profile, ctx));
|
|
70
|
+
}
|
package/lib/profiles.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform evidence registry. Profiles are metadata and source boundaries, not
|
|
3
|
+
* extra score weight. A profile may later add platform-specific checks without
|
|
4
|
+
* contaminating the Core score.
|
|
5
|
+
*/
|
|
6
|
+
export const PLATFORM_PROFILES = Object.freeze({
|
|
7
|
+
core: Object.freeze({
|
|
8
|
+
id: 'core', title: '跨平台基础', maturity: 'implemented',
|
|
9
|
+
sources: [],
|
|
10
|
+
scope: 'crawlability, indexability, page structure, duplicate URLs, entity clarity',
|
|
11
|
+
}),
|
|
12
|
+
google: Object.freeze({
|
|
13
|
+
id: 'google', title: 'Google Search / AI features', maturity: 'implemented',
|
|
14
|
+
sources: ['https://developers.google.com/search/docs/fundamentals/ai-optimization-guide'],
|
|
15
|
+
scope: 'Googlebot access, Search technical requirements, people-first content, Google-specific controls',
|
|
16
|
+
}),
|
|
17
|
+
bing: Object.freeze({
|
|
18
|
+
id: 'bing', title: 'Bing / Copilot', maturity: 'source-mapped',
|
|
19
|
+
sources: [
|
|
20
|
+
'https://www.bing.com/webmasters/help/webmaster-guidelines-30fba23a',
|
|
21
|
+
'https://www.bing.com/webmasters/help/robots-meta-tags-and-attributes-that-bing-supports-5198d240',
|
|
22
|
+
'https://www.bing.com/indexnow',
|
|
23
|
+
],
|
|
24
|
+
scope: 'Bingbot, Copilot grounding, data-nosnippet, AI controls, IndexNow',
|
|
25
|
+
}),
|
|
26
|
+
baidu: Object.freeze({
|
|
27
|
+
id: 'baidu', title: '百度搜索', maturity: 'source-mapped',
|
|
28
|
+
sources: [
|
|
29
|
+
'https://ziyuan.baidu.com/college/articleinfo?id=193undefinedpage%3D1&page=6',
|
|
30
|
+
'https://ziyuan.baidu.com/college/courseinfo?id=1399',
|
|
31
|
+
],
|
|
32
|
+
scope: 'Baiduspider, 百度搜索资源平台, sitemap/submission, Chinese search crawlability',
|
|
33
|
+
limitation: '百度 AI 引用选择标准没有完整公开;不把推测当作规则。',
|
|
34
|
+
}),
|
|
35
|
+
openai: Object.freeze({
|
|
36
|
+
id: 'openai', title: 'OpenAI Search', maturity: 'source-mapped',
|
|
37
|
+
sources: ['https://developers.openai.com/api/docs/bots'],
|
|
38
|
+
scope: 'OAI-SearchBot vs GPTBot access controls',
|
|
39
|
+
limitation: '不推导未公开的 ChatGPT 引用排序公式。',
|
|
40
|
+
}),
|
|
41
|
+
perplexity: Object.freeze({
|
|
42
|
+
id: 'perplexity', title: 'Perplexity', maturity: 'source-mapped',
|
|
43
|
+
sources: ['https://docs.perplexity.ai/docs/resources/perplexity-crawlers'],
|
|
44
|
+
scope: 'Perplexity crawler identity, robots and fetchability',
|
|
45
|
+
limitation: '不推导未公开的引用排序公式。',
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export function listProfiles() {
|
|
50
|
+
return Object.values(PLATFORM_PROFILES).map((profile) => ({
|
|
51
|
+
id: profile.id,
|
|
52
|
+
title: profile.title,
|
|
53
|
+
maturity: profile.maturity,
|
|
54
|
+
scope: profile.scope,
|
|
55
|
+
sources: [...profile.sources],
|
|
56
|
+
...(profile.limitation ? { limitation: profile.limitation } : {}),
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function profileById(id) {
|
|
61
|
+
return PLATFORM_PROFILES[id] ?? null;
|
|
62
|
+
}
|
package/lib/report.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human reports, fix plans, and scan-to-scan diffs.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is a pure function of score reports (plus the scan artifact
|
|
5
|
+
* for header facts), so the Markdown and JSON written to `.dsh-geo/` are
|
|
6
|
+
* reproducible for the same input.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const REPORT_FORMAT_VERSION = 1;
|
|
10
|
+
|
|
11
|
+
const DIMENSION_WEIGHTS = {
|
|
12
|
+
discoverability: 25,
|
|
13
|
+
parsability: 20,
|
|
14
|
+
citability: 25,
|
|
15
|
+
trust: 15,
|
|
16
|
+
manifest: 15,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const STATUS_LABEL = {
|
|
20
|
+
pass: '通过',
|
|
21
|
+
warn: '部分通过',
|
|
22
|
+
fail: '失败',
|
|
23
|
+
skip: '不适用',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const STATUS_FACTOR = { pass: 1, warn: 0.5, fail: 0, skip: 0 };
|
|
27
|
+
|
|
28
|
+
function round1(value) {
|
|
29
|
+
return Math.round(value * 10) / 10;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function signed(value) {
|
|
33
|
+
if (value > 0) return `+${value}`;
|
|
34
|
+
return String(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function siteHost(url) {
|
|
38
|
+
try {
|
|
39
|
+
return new URL(url).hostname.replace(/^www\./, '').toLowerCase();
|
|
40
|
+
} catch {
|
|
41
|
+
return String(url ?? '').toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Two reports can be compared only when they audit the same site. */
|
|
46
|
+
export function comparableSites(previousUrl, currentUrl) {
|
|
47
|
+
return siteHost(previousUrl) === siteHost(currentUrl);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Compare a previous score report with the current one.
|
|
52
|
+
* @param {object} previous
|
|
53
|
+
* @param {object} current
|
|
54
|
+
* @returns {object|null} null when either side is missing.
|
|
55
|
+
*/
|
|
56
|
+
export function diffReports(previous, current) {
|
|
57
|
+
if (!previous || !current) return null;
|
|
58
|
+
|
|
59
|
+
const before = new Map(previous.findings.map((finding) => [finding.id, finding.status]));
|
|
60
|
+
const fixed = [];
|
|
61
|
+
const regressed = [];
|
|
62
|
+
const changed = [];
|
|
63
|
+
let stillFailing = 0;
|
|
64
|
+
|
|
65
|
+
for (const finding of current.findings) {
|
|
66
|
+
const was = before.get(finding.id);
|
|
67
|
+
if (was === undefined) continue;
|
|
68
|
+
const now = finding.status;
|
|
69
|
+
if (was === now) {
|
|
70
|
+
if (now !== 'pass' && now !== 'skip') stillFailing += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (now === 'pass') {
|
|
74
|
+
if (was !== 'skip') fixed.push({ ruleId: finding.id, title: finding.title, dimension: finding.dimension, from: was });
|
|
75
|
+
} else if (was === 'pass') {
|
|
76
|
+
regressed.push({ ruleId: finding.id, title: finding.title, dimension: finding.dimension, to: now });
|
|
77
|
+
} else if ((STATUS_FACTOR[now] ?? 0) > (STATUS_FACTOR[was] ?? 0)) {
|
|
78
|
+
changed.push({ ruleId: finding.id, title: finding.title, dimension: finding.dimension, from: was, to: now, direction: 'up' });
|
|
79
|
+
} else {
|
|
80
|
+
changed.push({ ruleId: finding.id, title: finding.title, dimension: finding.dimension, from: was, to: now, direction: 'down' });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
previous: {
|
|
86
|
+
startUrl: previous.startUrl,
|
|
87
|
+
scannedAt: previous.scannedAt,
|
|
88
|
+
total: previous.total,
|
|
89
|
+
grade: previous.grade,
|
|
90
|
+
},
|
|
91
|
+
total: {
|
|
92
|
+
before: previous.total,
|
|
93
|
+
after: current.total,
|
|
94
|
+
delta: round1(current.total - previous.total),
|
|
95
|
+
},
|
|
96
|
+
dimensions: current.dimensions.map((dimension) => {
|
|
97
|
+
const old = previous.dimensions.find((entry) => entry.id === dimension.id);
|
|
98
|
+
const beforeScore = old ? old.score : 0;
|
|
99
|
+
return {
|
|
100
|
+
id: dimension.id,
|
|
101
|
+
title: dimension.title,
|
|
102
|
+
before: beforeScore,
|
|
103
|
+
after: dimension.score,
|
|
104
|
+
delta: round1(dimension.score - beforeScore),
|
|
105
|
+
};
|
|
106
|
+
}),
|
|
107
|
+
fixed,
|
|
108
|
+
regressed,
|
|
109
|
+
changed,
|
|
110
|
+
counts: {
|
|
111
|
+
fixed: fixed.length,
|
|
112
|
+
regressed: regressed.length,
|
|
113
|
+
changed: changed.length,
|
|
114
|
+
stillFailing,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function escapeInline(value) {
|
|
120
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A prioritized, grouped repair list derived from every non-pass finding.
|
|
125
|
+
* @param {object} report
|
|
126
|
+
* @param {{scan?: object, diff?: object|null}} [context]
|
|
127
|
+
*/
|
|
128
|
+
export function buildFixPlan(report, context = {}) {
|
|
129
|
+
const { scan = null, diff = null } = context;
|
|
130
|
+
const actions = report.findings
|
|
131
|
+
.filter((finding) => finding.status === 'fail' || finding.status === 'warn')
|
|
132
|
+
.map((finding) => {
|
|
133
|
+
const dimensionWeight = DIMENSION_WEIGHTS[finding.dimension] ?? 0;
|
|
134
|
+
const factor = finding.status === 'fail' ? 1 : 0.5;
|
|
135
|
+
return {
|
|
136
|
+
ruleId: finding.id,
|
|
137
|
+
dimension: finding.dimension,
|
|
138
|
+
dimensionTitle: report.dimensions.find((dimension) => dimension.id === finding.dimension)?.title ?? finding.dimension,
|
|
139
|
+
title: finding.title,
|
|
140
|
+
status: finding.status,
|
|
141
|
+
weight: finding.weight,
|
|
142
|
+
impact: round1(factor * finding.weight * dimensionWeight),
|
|
143
|
+
evidence: escapeInline(finding.evidence),
|
|
144
|
+
fix: escapeInline(finding.fix),
|
|
145
|
+
verify: `重新扫描后规则 \`${finding.id}\` 应为 pass`,
|
|
146
|
+
};
|
|
147
|
+
})
|
|
148
|
+
.sort((a, b) => b.impact - a.impact || (a.ruleId < b.ruleId ? -1 : a.ruleId > b.ruleId ? 1 : 0));
|
|
149
|
+
|
|
150
|
+
const dimensionOrder = report.dimensions.map((dimension) => dimension.id);
|
|
151
|
+
actions.sort((a, b) => b.impact - a.impact
|
|
152
|
+
|| dimensionOrder.indexOf(a.dimension) - dimensionOrder.indexOf(b.dimension)
|
|
153
|
+
|| (a.ruleId < b.ruleId ? -1 : a.ruleId > b.ruleId ? 1 : 0));
|
|
154
|
+
|
|
155
|
+
const generatedAt = scan?.scannedAt ?? report.scannedAt ?? null;
|
|
156
|
+
const payload = {
|
|
157
|
+
formatVersion: REPORT_FORMAT_VERSION,
|
|
158
|
+
generatedAt,
|
|
159
|
+
url: report.startUrl,
|
|
160
|
+
rubricVersion: report.rubricVersion,
|
|
161
|
+
score: { total: report.total, grade: report.grade, gradeLabel: report.gradeLabel },
|
|
162
|
+
previous: diff ? diff.previous : null,
|
|
163
|
+
actionCount: actions.length,
|
|
164
|
+
actions,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
actions,
|
|
169
|
+
json: payload,
|
|
170
|
+
markdown: renderFixPlanMarkdown(report, actions, { scan, diff }),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renderFixPlanMarkdown(report, actions, { scan, diff }) {
|
|
175
|
+
const lines = [];
|
|
176
|
+
lines.push(`# GEO 修复清单 — ${report.startUrl}`);
|
|
177
|
+
lines.push('');
|
|
178
|
+
const facts = [
|
|
179
|
+
`总分 **${report.total} / 100**(${report.grade} ${report.gradeLabel})`,
|
|
180
|
+
`规则版本 \`${report.rubricVersion}\``,
|
|
181
|
+
];
|
|
182
|
+
if (scan?.scannedAt) facts.push(`扫描时间 ${scan.scannedAt}`);
|
|
183
|
+
if (scan?.stats) facts.push(`抓取 ${scan.stats.pages} 页 / ${scan.stats.requested} 个请求`);
|
|
184
|
+
if (diff) facts.push(`对照上次 ${diff.previous.scannedAt} ${diff.previous.total} → ${report.total}(${signed(diff.total.delta)})`);
|
|
185
|
+
lines.push(`> ${facts.join(' · ')}`);
|
|
186
|
+
lines.push('');
|
|
187
|
+
lines.push('按影响力排序,先做前面的项。每项都给出证据与验收条件;改完用同一规则复扫确认。');
|
|
188
|
+
lines.push('');
|
|
189
|
+
|
|
190
|
+
if (diff) {
|
|
191
|
+
lines.push('## 与上次扫描相比');
|
|
192
|
+
lines.push('');
|
|
193
|
+
const fixedList = diff.fixed.length > 0 ? diff.fixed.map((entry) => `\`${entry.ruleId}\``).join('、') : '无';
|
|
194
|
+
const regressedList = diff.regressed.length > 0 ? diff.regressed.map((entry) => `\`${entry.ruleId}\``).join('、') : '无';
|
|
195
|
+
lines.push(`- 已修复:${fixedList}`);
|
|
196
|
+
lines.push(`- 出现回归:${regressedList}`);
|
|
197
|
+
lines.push(`- 仍未通过:${diff.counts.stillFailing} 项`);
|
|
198
|
+
lines.push('');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (actions.length === 0) {
|
|
202
|
+
lines.push('## 结论');
|
|
203
|
+
lines.push('');
|
|
204
|
+
lines.push('所有检查项均已通过,没有需要修复的项。保持当前结构,并在每次内容或模板改动后复扫。');
|
|
205
|
+
lines.push('');
|
|
206
|
+
return `${lines.join('\n')}\n`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
lines.push('## 修复顺序');
|
|
210
|
+
lines.push('');
|
|
211
|
+
const top = actions.slice(0, 5);
|
|
212
|
+
top.forEach((action, index) => {
|
|
213
|
+
lines.push(`${index + 1}. **${action.dimensionTitle} / ${action.title}**(${STATUS_LABEL[action.status]},权重 ${action.weight})`);
|
|
214
|
+
lines.push(` - 证据:${action.evidence}`);
|
|
215
|
+
lines.push(` - 做法:${action.fix}`);
|
|
216
|
+
lines.push(` - 验收:${action.verify}`);
|
|
217
|
+
});
|
|
218
|
+
lines.push('');
|
|
219
|
+
|
|
220
|
+
const dimensions = report.dimensions;
|
|
221
|
+
for (const dimension of dimensions) {
|
|
222
|
+
const own = actions.filter((action) => action.dimension === dimension.id);
|
|
223
|
+
if (own.length === 0) continue;
|
|
224
|
+
lines.push(`## ${dimension.title}(${dimension.score} / 100,权重 ${dimension.weight})`);
|
|
225
|
+
lines.push('');
|
|
226
|
+
for (const action of own) {
|
|
227
|
+
lines.push(`### [${action.ruleId}] ${action.title}`);
|
|
228
|
+
lines.push('');
|
|
229
|
+
lines.push(`- 状态:${STATUS_LABEL[action.status]}(权重 ${action.weight})`);
|
|
230
|
+
lines.push(`- 证据:${action.evidence}`);
|
|
231
|
+
lines.push(`- 做法:${action.fix}`);
|
|
232
|
+
lines.push(`- 验收:${action.verify}`);
|
|
233
|
+
lines.push('');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const platformActions = (report.platforms ?? []).flatMap((platform) =>
|
|
238
|
+
(platform.actions ?? []).map((action) => ({ ...action, platformTitle: platform.title })));
|
|
239
|
+
if (platformActions.length > 0) {
|
|
240
|
+
lines.push('## 平台适配建议(不计入 Core 总分)');
|
|
241
|
+
lines.push('');
|
|
242
|
+
for (const action of platformActions) {
|
|
243
|
+
lines.push(`### [${action.platformTitle}] ${action.title}`);
|
|
244
|
+
lines.push('');
|
|
245
|
+
lines.push(`- 状态:${STATUS_LABEL[action.status]}(权重 ${action.weight})`);
|
|
246
|
+
lines.push(`- 证据:${escapeInline(action.evidence)}`);
|
|
247
|
+
lines.push(`- 做法:${escapeInline(action.fix)}`);
|
|
248
|
+
lines.push('');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
lines.push('## 复扫');
|
|
253
|
+
lines.push('');
|
|
254
|
+
lines.push('改完代码后,用同一个站点与同一个参考时间复扫,才能把分数变化归因到改动本身:');
|
|
255
|
+
lines.push('');
|
|
256
|
+
lines.push('```sh');
|
|
257
|
+
lines.push(`dsh-geo scan ${report.startUrl} --save --now ${scan?.scannedAt ?? '<首次扫描时间>'}`);
|
|
258
|
+
lines.push('dsh-geo diff .dsh-geo/history/<改动前>.json .dsh-geo/latest.json');
|
|
259
|
+
lines.push('```');
|
|
260
|
+
lines.push('');
|
|
261
|
+
lines.push('或者在 agent 会话里重新运行 `geo_scan`,报告会自动写入 `.dsh-geo/` 并与上次对比。');
|
|
262
|
+
lines.push('');
|
|
263
|
+
return `${lines.join('\n')}\n`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Markdown summary for one audit, written to `.dsh-geo/report.md`.
|
|
268
|
+
* @param {object} report
|
|
269
|
+
* @param {{scan?: object, diff?: object|null}} [context]
|
|
270
|
+
*/
|
|
271
|
+
export function renderAuditMarkdown(report, context = {}) {
|
|
272
|
+
const { scan = null, diff = null } = context;
|
|
273
|
+
const lines = [];
|
|
274
|
+
lines.push(`# GEO 体检报告 — ${report.startUrl}`);
|
|
275
|
+
lines.push('');
|
|
276
|
+
lines.push(`> 总分 **${report.total} / 100**(${report.grade} ${report.gradeLabel})· 规则 \`${report.rubricVersion}\`${scan?.scannedAt ? ` · 扫描时间 ${scan.scannedAt}` : ''}`);
|
|
277
|
+
lines.push('');
|
|
278
|
+
if (report.blockedByRobots) {
|
|
279
|
+
lines.push('> **robots.txt 拒绝了扫描 UA**,本次没有抓取任何页面。修复 robots 或经所有者确认后使用 `--no-robots` 重扫。');
|
|
280
|
+
lines.push('');
|
|
281
|
+
}
|
|
282
|
+
lines.push('## 五维得分');
|
|
283
|
+
lines.push('');
|
|
284
|
+
lines.push('| 维度 | 得分 | 权重 | 通过 | 部分 | 失败 | 不适用 |');
|
|
285
|
+
lines.push('|---|---|---|---|---|---|---|');
|
|
286
|
+
for (const dimension of report.dimensions) {
|
|
287
|
+
const { pass, warn, fail, skip } = dimension.counts;
|
|
288
|
+
lines.push(`| ${dimension.title} | ${dimension.score} | ${dimension.weight} | ${pass} | ${warn} | ${fail} | ${skip} |`);
|
|
289
|
+
}
|
|
290
|
+
lines.push('');
|
|
291
|
+
lines.push(`检查项合计:通过 ${report.counts.pass} / 部分 ${report.counts.warn} / 失败 ${report.counts.fail} / 不适用 ${report.counts.skip}`);
|
|
292
|
+
lines.push('');
|
|
293
|
+
|
|
294
|
+
if (Array.isArray(report.platforms) && report.platforms.length > 0) {
|
|
295
|
+
lines.push('## 平台适配(参考,不计入 Core 总分)');
|
|
296
|
+
lines.push('');
|
|
297
|
+
lines.push('| 平台 | 分数 | 通过 | 部分 | 失败 | 不适用 |');
|
|
298
|
+
lines.push('|---|---|---|---|---|---|');
|
|
299
|
+
for (const platform of report.platforms) {
|
|
300
|
+
const { pass, warn, fail, skip } = platform.counts;
|
|
301
|
+
lines.push(`| ${platform.title} | ${platform.total} | ${pass} | ${warn} | ${fail} | ${skip} |`);
|
|
302
|
+
}
|
|
303
|
+
lines.push('');
|
|
304
|
+
for (const platform of report.platforms) {
|
|
305
|
+
if (platform.actions.length === 0) continue;
|
|
306
|
+
lines.push(`**${platform.title}:**`);
|
|
307
|
+
for (const action of platform.actions) {
|
|
308
|
+
lines.push(`- ${action.title} — ${escapeInline(action.evidence)}`);
|
|
309
|
+
}
|
|
310
|
+
lines.push('');
|
|
311
|
+
}
|
|
312
|
+
lines.push('平台检查只反映该平台公开文档中的可验证事项,不代表该平台的排名或引用结果。');
|
|
313
|
+
lines.push('');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (diff) {
|
|
317
|
+
lines.push('## 对照上次');
|
|
318
|
+
lines.push('');
|
|
319
|
+
lines.push(`上次 ${diff.previous.scannedAt}:${diff.previous.total} → 本次 ${report.total}(${signed(diff.total.delta)})`);
|
|
320
|
+
lines.push('');
|
|
321
|
+
for (const dimension of diff.dimensions) {
|
|
322
|
+
if (dimension.delta === 0) continue;
|
|
323
|
+
lines.push(`- ${dimension.title}:${dimension.before} → ${dimension.after}(${signed(dimension.delta)})`);
|
|
324
|
+
}
|
|
325
|
+
if (diff.regressed.length > 0) {
|
|
326
|
+
lines.push('');
|
|
327
|
+
lines.push(`**回归项:** ${diff.regressed.map((entry) => `\`${entry.ruleId}\``).join('、')}`);
|
|
328
|
+
}
|
|
329
|
+
lines.push('');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const top = report.actions.slice(0, 8);
|
|
333
|
+
if (top.length > 0) {
|
|
334
|
+
lines.push('## 优先修复');
|
|
335
|
+
lines.push('');
|
|
336
|
+
top.forEach((action, index) => {
|
|
337
|
+
lines.push(`${index + 1}. **${action.dimensionTitle} · ${action.title}** — ${action.evidence}`);
|
|
338
|
+
lines.push(` ${action.fix}`);
|
|
339
|
+
});
|
|
340
|
+
lines.push('');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (scan?.stats) {
|
|
344
|
+
lines.push('## 抓取概况');
|
|
345
|
+
lines.push('');
|
|
346
|
+
lines.push(`- 页面:${scan.stats.pages}(请求 ${scan.stats.requested} 次,传输 ${scan.stats.bytes} 字节)`);
|
|
347
|
+
lines.push(`- robots.txt:${scan.robots?.found ? '存在' : '不存在'}`);
|
|
348
|
+
lines.push(`- sitemap:${scan.sitemap?.valid ? `${scan.sitemap.urlCount} 个 URL` : '无可用 sitemap'}`);
|
|
349
|
+
lines.push(`- llms.txt:${scan.llms?.found ? (scan.llms.valid ? '有效' : '存在但结构无效') : '不存在'}`);
|
|
350
|
+
if (scan.errors?.length > 0) {
|
|
351
|
+
lines.push(`- 抓取错误:${scan.errors.length} 条(详见 latest.json 的 \`errors\`)`);
|
|
352
|
+
}
|
|
353
|
+
lines.push('');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
lines.push('完整的机器可读结果见 `.dsh-geo/latest.json`,修复清单见 `.dsh-geo/fix-plan.md`。');
|
|
357
|
+
lines.push('');
|
|
358
|
+
return lines.join('\n');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Compact, model-facing summary of a score report.
|
|
363
|
+
* @param {object} report
|
|
364
|
+
* @param {{limit?: number}} [options]
|
|
365
|
+
*/
|
|
366
|
+
export function summarizeReport(report, options = {}) {
|
|
367
|
+
const limit = options.limit ?? 5;
|
|
368
|
+
return {
|
|
369
|
+
total: report.total,
|
|
370
|
+
grade: report.grade,
|
|
371
|
+
gradeLabel: report.gradeLabel,
|
|
372
|
+
counts: report.counts,
|
|
373
|
+
dimensions: report.dimensions.map((dimension) => ({
|
|
374
|
+
id: dimension.id,
|
|
375
|
+
title: dimension.title,
|
|
376
|
+
weight: dimension.weight,
|
|
377
|
+
score: dimension.score,
|
|
378
|
+
})),
|
|
379
|
+
platforms: (report.platforms ?? []).map((platform) => ({
|
|
380
|
+
id: platform.id,
|
|
381
|
+
title: platform.title,
|
|
382
|
+
total: platform.total,
|
|
383
|
+
counts: platform.counts,
|
|
384
|
+
actions: platform.actions.slice(0, 3).map((action) => ({
|
|
385
|
+
ruleId: action.id,
|
|
386
|
+
title: action.title,
|
|
387
|
+
status: action.status,
|
|
388
|
+
weight: action.weight,
|
|
389
|
+
evidence: action.evidence,
|
|
390
|
+
fix: action.fix,
|
|
391
|
+
})),
|
|
392
|
+
})),
|
|
393
|
+
topActions: report.actions.slice(0, limit).map((action) => ({
|
|
394
|
+
ruleId: action.ruleId,
|
|
395
|
+
dimension: action.dimension,
|
|
396
|
+
dimensionTitle: action.dimensionTitle,
|
|
397
|
+
title: action.title,
|
|
398
|
+
status: action.status,
|
|
399
|
+
weight: action.weight,
|
|
400
|
+
evidence: action.evidence,
|
|
401
|
+
fix: action.fix,
|
|
402
|
+
})),
|
|
403
|
+
};
|
|
404
|
+
}
|