diff --git a/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx b/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx index 5f80390e..d67b24c6 100644 --- a/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx +++ b/frontend/application/app/blog/[slug]/blog-slug-page.test.tsx @@ -82,9 +82,9 @@ describe('BlogPostPage FAQPage Schema injection (SEO-P1-07)', () => { const jsx=await BlogPostPage({params:Promise.resolve({slug:'fresh'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBe('2026-01-01T12:00:00.000Z'); expect(json.author['@type']).toBe('Organization'); expect(json.author.name).toBe('کنینا'); }); - it('omits dateModified when only technical updatedAt exists', async () => { + it('uses publication as dateModified when only technical updatedAt exists', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ok:true,json:async()=>({slug:'technical',title:'Technical',content:'
x
',publishedAt:'2026-01-01T01:00:00Z',updatedAt:'2026-01-01T12:00:00Z',contentUpdatedAt:null})})); - const jsx=await BlogPostPage({params:Promise.resolve({slug:'technical'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBeUndefined(); + const jsx=await BlogPostPage({params:Promise.resolve({slug:'technical'})}); const script:any=React.Children.toArray(jsx.props.children)[0]; const json=JSON.parse(script.props.dangerouslySetInnerHTML.__html); expect(json.dateModified).toBe('2026-01-01T01:00:00.000Z'); }); it('uses the stable Organization fallback visibly and in metadata', async () => { diff --git a/frontend/application/app/blog/[slug]/page.tsx b/frontend/application/app/blog/[slug]/page.tsx index 56cc0ae2..78640308 100644 --- a/frontend/application/app/blog/[slug]/page.tsx +++ b/frontend/application/app/blog/[slug]/page.tsx @@ -1,4 +1,4 @@ -import { validContentUpdatedAt } from "../../../lib/blogDates"; +import { persianDate, validContentUpdatedAt } from "../../../lib/blogDates"; import { resolveBlogAuthorIdentity } from "../../../lib/blogAuthor"; import React from "react"; import { notFound } from 'next/navigation'; @@ -23,7 +23,7 @@ function safeLocalDate(val: any): string { if (!val) return ''; try { const d = new Date(val); - return isNaN(d.getTime()) ? '' : d.toLocaleDateString('fa-IR'); + return isNaN(d.getTime()) ? '' : persianDate(d.toISOString()); } catch { return ''; } @@ -95,7 +95,8 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str const resolvedAuthor = resolveBlogAuthorIdentity(blog); const publishedTime = safeIso(blog.publishedAt) || safeIso(blog.createdAt); - const modifiedTime = safeIso(validContentUpdatedAt(blog)); + // Technical writes are not substantive edits; unedited articles retain the real publication date. + const modifiedTime = safeIso(validContentUpdatedAt(blog)) || publishedTime; const keywordsList = blog.focusKeywords ? blog.focusKeywords.split(',').map((k: string) => k.trim()) @@ -181,8 +182,8 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug: ? blog.canonicalUrl.replace(/\/+$/, '') : `${siteUrl}/blog/${slug}`; - const publishedIso = safeIso(blog.publishedAt) || safeIso(blog.createdAt) || new Date().toISOString(); - const modifiedIso = safeIso(validContentUpdatedAt(blog)); + const publishedIso = safeIso(blog.publishedAt) || safeIso(blog.createdAt); + const modifiedIso = safeIso(validContentUpdatedAt(blog)) || publishedIso; const sanitizedContent = sanitizeBlogHtml(blog.content); const schemaType = blog.schemaType || 'BlogPosting'; @@ -210,7 +211,7 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug: image: blog.imageUrl ? [blog.imageUrl.startsWith('http') ? blog.imageUrl : `${siteUrl}${blog.imageUrl.startsWith('/') ? '' : '/'}${blog.imageUrl}`] : [config.ogImageUrl.startsWith('http') ? config.ogImageUrl : `${siteUrl}${config.ogImageUrl.startsWith('/') ? '' : '/'}${config.ogImageUrl}`], - datePublished: publishedIso, + ...(publishedIso ? { datePublished: publishedIso } : {}), ...(modifiedIso ? { dateModified: modifiedIso } : {}), author: authorSchema, publisher: { diff --git a/frontend/application/app/blog/[slug]/timestamp-metadata.test.tsx b/frontend/application/app/blog/[slug]/timestamp-metadata.test.tsx new file mode 100644 index 00000000..a9aad72f --- /dev/null +++ b/frontend/application/app/blog/[slug]/timestamp-metadata.test.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import { afterEach, expect, it, vi } from 'vitest'; +import { renderToStaticMarkup } from 'react-dom/server'; +import BlogPostPage, { generateMetadata } from './page'; +import { validContentUpdatedAt } from '../../../lib/blogDates'; + +vi.mock('../../../lib/seo', () => ({ + getSeoConfig: async () => ({ brandNameFa: 'کنینا', canonicalBaseUrl: 'https://canina.ir', ogImageUrl: 'https://canina.ir/default.webp' }), + formatPageTitle: (title: string) => title, +})); +vi.mock('../../../components/BlogPostClient', () => ({ + default: ({ blog, publishedDate }: { blog: any; publishedDate: string }) =>Article
', ...fields, + }) })); + const params = Promise.resolve({ slug: 'timestamp-contract' }); + const metadata = await generateMetadata({ params }); + const jsx = await BlogPostPage({ params }); + const script: any = React.Children.toArray(jsx.props.children)[0]; + return { og: metadata.openGraph as any, robots: metadata.robots, + article: JSON.parse(script.props.dangerouslySetInnerHTML.__html), html: renderToStaticMarkup(jsx) }; +} + +it.each([null, undefined, 'invalid', published, '2026-10-28T00:00:00Z'])( + 'uses real publication for unedited/invalid/chronologically inapplicable content date %s', async (contentUpdatedAt) => { + const { og, article, html, robots } = await readDates({ publishedAt: published, + contentUpdatedAt, updatedAt: '2026-10-30T09:00:00Z', imageUrl: '/attached.webp' }); + expect(og.publishedTime).toBe(published); + expect(og.modifiedTime).toBe(published); + expect(article.datePublished).toBe(published); + expect(article.dateModified).toBe(published); + expect(html).not.toContain('آخرین بهروزرسانی'); + // Stage noindex remains an independent HTTP acceptance check; no robots change in this slice. + }); +it('uses actual substantive update consistently without changing publication', async () => { + const modified = '2026-10-29T12:00:00.000Z'; + const { og, article, html } = await readDates({ publishedAt: published, contentUpdatedAt: modified }); + expect(og.modifiedTime).toBe(modified); + expect(article.dateModified).toBe(modified); + expect(article.datePublished).toBe(published); + expect(html).toContain('آخرین بهروزرسانی'); +}); +it.each([null, 'invalid'])('uses the valid existing createdAt fallback when publishedAt is %s', async (publishedAt) => { + const { og, article } = await readDates({ publishedAt, createdAt: published }); + expect(og.publishedTime).toBe(published); + expect(og.modifiedTime).toBe(published); + expect(article.datePublished).toBe(published); + expect(article.dateModified).toBe(published); +}); +it.each([{}, { publishedAt: 'invalid', createdAt: 'invalid', contentUpdatedAt: '2026-10-30T00:00:00Z' }])( + 'does not invent rendering-time publication or modification when unknown: %j', async (fields) => { + const { og, article } = await readDates(fields); + expect(og.publishedTime).toBeUndefined(); + expect(og.modifiedTime).toBeUndefined(); + expect(article).not.toHaveProperty('datePublished'); + expect(article).not.toHaveProperty('dateModified'); + }); +it('formats visible publication using Persian calendar and Tehran rather than server timezone', async () => { + const { html } = await readDates({ publishedAt: '2026-10-29T21:00:00Z' }); + const expected = new Intl.DateTimeFormat('fa-IR-u-ca-persian', { + year: 'numeric', month: 'numeric', day: 'numeric', timeZone: 'Asia/Tehran', + }).format(new Date('2026-10-29T21:00:00Z')); + expect(html).toContain(`تاریخ انتشار: ${expected}`); +}); diff --git a/frontend/application/app/blog/[slug]/timestamp-visible.test.tsx b/frontend/application/app/blog/[slug]/timestamp-visible.test.tsx new file mode 100644 index 00000000..438e8294 --- /dev/null +++ b/frontend/application/app/blog/[slug]/timestamp-visible.test.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { expect, it } from 'vitest'; +import BlogPostClient from '../../../components/BlogPostClient'; + +it.each([null, undefined, 'invalid', '2026-10-29T07:11:40.925Z', '2026-10-28T00:00:00Z'])( + 'actual client keeps publication but no visible update for %s despite later technical writes', (contentUpdatedAt) => { + const html = renderToStaticMarkup(