feat(kb): 新增一件代发 FAQ 知识库

This commit is contained in:
wangliang
2026-10-23 15:11:01 +08:00
parent 8ae8d2b468
commit dfc3b497f5
8 changed files with 300 additions and 15 deletions
+12 -1
View File
@@ -5,7 +5,7 @@ const assert = require('node:assert/strict');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { extractFaqFromLdJson } = require('../src/faq-fetcher');
const { extractFaqFromLdJson, extractFaqFromNuxt } = require('../src/faq-fetcher');
const { updateMarkdownFile } = require('../src/faq-update');
test('faq: extracts FAQPage JSON-LD questions', () => {
@@ -38,3 +38,14 @@ test('faq: normalized question match avoids duplicate append', () => {
assert.equal((out.match(/### Q:/g) || []).length, 1);
assert.match(out, /new/);
});
test('faq: extracts FAQ from Nuxt SSR payload (no JSON-LD)', () => {
const html = '<html><script>__NUXT__=(function(a){return {data:[{info:{content:[{title:"Q1?",content:"<p>A1</p>"},{title:"Q2?",content:"<p>A2 &amp; more</p>"}]}}]}})();</script></html>';
const qs = extractFaqFromNuxt(html);
assert.deepEqual(qs, [{ q: 'Q1?', a: 'A1' }, { q: 'Q2?', a: 'A2 & more' }]);
});
test('faq: nuxt extractor tolerates missing/broken payload', () => {
assert.deepEqual(extractFaqFromNuxt('<html>no payload</html>'), []);
assert.deepEqual(extractFaqFromNuxt('<script>__NUXT__=not-js;</script>'), []);
});