fix(blog): expose author role and bound FAQ heading extraction
Deploy Canina / deploy (push) Successful in 10m28s

This commit is contained in:
Canina Engineering authored and devops committed 2026-10-25 08:19:44 +00:00
1 parent 0ab2980ff4
commit 13dceaa460
4 files changed
+32 -3

No files matched your search

@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { extractFaqsFromHtml } from './extractFaqs';
describe('FAQ heading boundaries', () => {
it('never merges intervening care lists or section headings into a question', () => {
const html = `<h2>تا زمان معاینه چه کارهایی کم‌خطرتر است؟</h2>
<ul><li>از دستکاری گوش خودداری کنید.</li></ul>
<p>این اقدامات درمان نیستند.</p>
<h2>چه چیزهایی داخل گوش نریزیم؟</h2><p>مواد خانگی استفاده نکنید.</p>
<h2>پرسش‌های رایج</h2><h3>آیا بو یعنی عفونت است؟</h3><p>خیر، معاینه لازم است.</p>`;
expect(extractFaqsFromHtml(html)).toEqual([
{ question: 'چه چیزهایی داخل گوش نریزیم؟', answer: 'مواد خانگی استفاده نکنید.' },
{ question: 'آیا بو یعنی عفونت است؟', answer: 'خیر، معاینه لازم است.' },
]);
});
});
+3 -3
View File
@@ -61,11 +61,11 @@ export function extractFaqsFromHtml(html: string): FAQItem[] {
// 3. Headings with questions followed immediately by paragraph answers:
// e.g. <h2>پرسش: آیا این مکمل برای سگ مفید است؟</h2> <p>بله، کاملاً مفید است.</p>
const headingRegex = /<h[2-4][^>]*>([\s\S]*?)<\/h[2-4]>\s*<p[^>]*>([\s\S]*?)<\/p>/gi;
const headingRegex = /<h([2-4])\b[^>]*>((?:(?!<\/?h[1-6]\b)[\s\S])*?)<\/h\1>\s*<p[^>]*>([\s\S]*?)<\/p>/gi;
let headingMatch;
while ((headingMatch = headingRegex.exec(html)) !== null) {
const rawHeading = headingMatch[1].replace(/<[^>]+>/g, '').trim();
const rawParagraph = headingMatch[2].replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
const rawHeading = headingMatch[2].replace(/<[^>]+>/g, '').trim();
const rawParagraph = headingMatch[3].replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
if (
(rawHeading.endsWith('?') ||
rawHeading.endsWith('؟') ||