fix(blog): expose author role and bound FAQ heading extraction
Deploy Canina / deploy (push) Successful in 10m28s
Deploy Canina / deploy (push) Successful in 10m28s
This commit is contained in:
1 parent
0ab2980ff4
commit
13dceaa460
4 files changed
+32
-3
No files matched your search
@@ -214,6 +214,11 @@ export default function BlogPostClient({ blog, publishedDate, authorName, author
|
||||
<div className="font-bold text-xs text-medical-gray-400 mt-0.5">
|
||||
تیم: {authorTeam || blog.authorTeam || BLOG_TEAM_FALLBACK}
|
||||
</div>
|
||||
{typeof blog.authorRole === 'string' && blog.authorRole.trim() && (
|
||||
<div className="font-bold text-xs text-medical-gray-500 mt-1">
|
||||
نقش نویسنده: {blog.authorRole.trim()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
@@ -119,6 +119,14 @@ describe("BlogPostClient Component", () => {
|
||||
expect(document.querySelectorAll("time[datetime]").length).toBe(2);
|
||||
});
|
||||
|
||||
it("displays an explicit author role without inventing one for older articles", () => {
|
||||
const props = { sanitizedContent: mockBlog.content, publishedDate: "۱۴۰۵/۸/۳", authorName: "کارشناس کنینا" };
|
||||
const { rerender } = render(<BlogPostClient {...props} blog={{ ...mockBlog, authorRole: "پژوهش مراقبت گوش و نگهداری ایمن" }} />);
|
||||
expect(screen.getByText("نقش نویسنده: پژوهش مراقبت گوش و نگهداری ایمن")).toBeInTheDocument();
|
||||
rerender(<BlogPostClient {...props} blog={{ ...mockBlog, authorRole: " " }} />);
|
||||
expect(screen.queryByText(/نقش نویسنده:/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("registers blog view count on mount via API", async () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
|
||||
@@ -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: 'خیر، معاینه لازم است.' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -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('؟') ||
|
||||
|
||||
Reference in new issue
Block a user