diff --git a/frontend/application/components/BlogPostClient.tsx b/frontend/application/components/BlogPostClient.tsx index 6fbe803b..4ecaaf64 100644 --- a/frontend/application/components/BlogPostClient.tsx +++ b/frontend/application/components/BlogPostClient.tsx @@ -214,6 +214,11 @@ export default function BlogPostClient({ blog, publishedDate, authorName, author
تیم: {authorTeam || blog.authorTeam || BLOG_TEAM_FALLBACK}
+ {typeof blog.authorRole === 'string' && blog.authorRole.trim() && ( +
+ نقش نویسنده: {blog.authorRole.trim()} +
+ )}
diff --git a/frontend/application/components/__tests__/BlogPostClient.test.tsx b/frontend/application/components/__tests__/BlogPostClient.test.tsx index c500de33..754ad6ce 100644 --- a/frontend/application/components/__tests__/BlogPostClient.test.tsx +++ b/frontend/application/components/__tests__/BlogPostClient.test.tsx @@ -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(); + expect(screen.getByText("نقش نویسنده: پژوهش مراقبت گوش و نگهداری ایمن")).toBeInTheDocument(); + rerender(); + expect(screen.queryByText(/نقش نویسنده:/)).not.toBeInTheDocument(); + }); + it("registers blog view count on mount via API", async () => { render( { + it('never merges intervening care lists or section headings into a question', () => { + const html = `

تا زمان معاینه چه کارهایی کم‌خطرتر است؟

+
  • از دستکاری گوش خودداری کنید.
+

این اقدامات درمان نیستند.

+

چه چیزهایی داخل گوش نریزیم؟

مواد خانگی استفاده نکنید.

+

پرسش‌های رایج

آیا بو یعنی عفونت است؟

خیر، معاینه لازم است.

`; + expect(extractFaqsFromHtml(html)).toEqual([ + { question: 'چه چیزهایی داخل گوش نریزیم؟', answer: 'مواد خانگی استفاده نکنید.' }, + { question: 'آیا بو یعنی عفونت است؟', answer: 'خیر، معاینه لازم است.' }, + ]); + }); +}); diff --git a/frontend/application/lib/extractFaqs.ts b/frontend/application/lib/extractFaqs.ts index f48e7433..88328299 100644 --- a/frontend/application/lib/extractFaqs.ts +++ b/frontend/application/lib/extractFaqs.ts @@ -61,11 +61,11 @@ export function extractFaqsFromHtml(html: string): FAQItem[] { // 3. Headings with questions followed immediately by paragraph answers: // e.g.

پرسش: آیا این مکمل برای سگ مفید است؟

بله، کاملاً مفید است.

- const headingRegex = /]*>([\s\S]*?)<\/h[2-4]>\s*]*>([\s\S]*?)<\/p>/gi; + const headingRegex = /]*>((?:(?!<\/?h[1-6]\b)[\s\S])*?)<\/h\1>\s*]*>([\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('؟') ||