357e26ab49
Finish/交付写盘前自动回填 mindspace-geo,扩展 storage publications 扫描与 geo meta 解析,并增加 143 生产回填脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
extractFaqFromHeadings,
|
|
parseMindspaceGeoMeta,
|
|
resolveGeoFaq,
|
|
resolveGeoKeywords,
|
|
} from './mindspace-geo-meta.mjs';
|
|
|
|
test('parseMindspaceGeoMeta reads author faq and keywords', () => {
|
|
const html = `<meta name="mindspace-geo" content='{"summary":"攻略","keywords":["旅游"],"faq":[{"q":"怎么去?","a":"高铁直达"}]}'>`;
|
|
const meta = parseMindspaceGeoMeta(html);
|
|
assert.equal(meta.summary, '攻略');
|
|
assert.deepEqual(meta.keywords, ['旅游']);
|
|
assert.equal(meta.faq.length, 1);
|
|
});
|
|
|
|
test('parseMindspaceGeoMeta reads legacy single-quoted json with apostrophes in faq', () => {
|
|
const html = `<meta name="mindspace-geo" content='{"summary":"业绩回顾","keywords":["报告"],"faq":[{"q":"费比规则?","a":"单客户费比上限18%,超标须特批"}]}'>`;
|
|
const meta = parseMindspaceGeoMeta(html);
|
|
assert.equal(meta.summary, '业绩回顾');
|
|
assert.equal(meta.faq[0].a, '单客户费比上限18%,超标须特批');
|
|
});
|
|
|
|
test('extractFaqFromHeadings builds faq from h2 and paragraph', () => {
|
|
const html = `<body>
|
|
<h2>最佳季节</h2><p>春秋两季气候最舒适,适合徒步与摄影。</p>
|
|
<h2>交通方式</h2><p>可乘坐高铁到仙居站,再转乘景区巴士。</p>
|
|
</body>`;
|
|
const faq = extractFaqFromHeadings(html);
|
|
assert.equal(faq.length, 2);
|
|
assert.equal(faq[0].q, '最佳季节');
|
|
assert.match(faq[0].a, /春秋/);
|
|
});
|
|
|
|
test('resolveGeoFaq prefers author faq over extracted headings', () => {
|
|
const html = `<meta name="mindspace-geo" content='{"faq":[{"q":"作者问题","a":"作者答案"}]}'>
|
|
<h2>自动问题</h2><p>自动答案内容足够长以通过校验。</p>`;
|
|
const faq = resolveGeoFaq(html);
|
|
assert.equal(faq[0].q, '作者问题');
|
|
});
|
|
|
|
test('resolveGeoKeywords falls back to cover tag and h2 headings', () => {
|
|
const html = `<title>仙居玩水攻略</title>
|
|
<meta name="mindspace-cover" content='{"tag":"旅行","subtitle":"淡竹白溪"}'>
|
|
<h2>装备清单</h2>`;
|
|
const keywords = resolveGeoKeywords(html);
|
|
assert.ok(keywords.includes('旅行'));
|
|
assert.ok(keywords.includes('装备清单'));
|
|
});
|