feat(kb): 新增一件代发 FAQ 知识库
This commit is contained in:
+12
-1
@@ -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 & 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>'), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user