fix(stage): route blog revalidation to Next and omit unrelated article media
Deploy Canina / deploy (push) Successful in 3m16s
Deploy Canina / deploy (push) Successful in 3m16s
This commit is contained in:
1 parent
85ef01d337
commit
55d11fa597
8 files changed
+106
-15
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
vi.mock('../../../lib/seo', () => ({ getSeoConfig: async () => ({brandNameFa:'Canina', ogImageUrl:'https://example.org/unrelated.webp'}), formatPageTitle: (s:string) => s }));
|
||||
vi.mock('../../../components/BlogPostClient', () => ({default: () => null}));
|
||||
vi.mock('next/navigation', () => ({notFound: () => {throw Error('404')}}));
|
||||
import Page, {generateMetadata} from './page';
|
||||
const base = {title:'Existing article',content:'Body',slug:'existing',publishedAt:'2026-11-15T05:41:53Z'};
|
||||
let blog: any;
|
||||
beforeEach(() => {blog={...base}; vi.stubGlobal('fetch',vi.fn(async () => ({ok:true,json:async () => blog})));});
|
||||
describe('article-owned media', () => {
|
||||
it.each([null,undefined,'',' '])('omits unrelated imagery for %s', async (image) => {
|
||||
blog.imageUrl=image; blog.ogImage=image;
|
||||
const metadata:any=await generateMetadata({params:Promise.resolve({slug:'existing'})});
|
||||
expect(metadata.openGraph.images).toEqual([]);
|
||||
expect(metadata.twitter.images).toEqual([]);
|
||||
expect(metadata.twitter.card).toBe('summary');
|
||||
const page:any=await Page({params:Promise.resolve({slug:'existing'})});
|
||||
const schema=JSON.parse(page.props.children[0].props.dangerouslySetInnerHTML.__html);
|
||||
expect(schema).not.toHaveProperty('image');
|
||||
});
|
||||
it('retains authored OG precedence and Article image', async () => {
|
||||
blog.imageUrl='/uploads/article.webp'; blog.ogImage='/uploads/social.webp';
|
||||
const metadata:any=await generateMetadata({params:Promise.resolve({slug:'existing'})});
|
||||
expect(metadata.openGraph.images[0].url).toBe('/uploads/social.webp');
|
||||
const page:any=await Page({params:Promise.resolve({slug:'existing'})});
|
||||
expect(JSON.parse(page.props.children[0].props.dangerouslySetInnerHTML.__html).image[0]).toContain('/uploads/article.webp');
|
||||
});
|
||||
});
|
||||
@@ -77,7 +77,7 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
(typeof blog.content === 'string' ? blog.content.substring(0, 155).replace(/<[^>]+>/g, '') : '') ||
|
||||
config.defaultMetaDescription;
|
||||
const canonicalUrl = blog.canonicalUrl ? blog.canonicalUrl.replace(/\/+$/, '') : `${siteUrl}/blog/${slug}`;
|
||||
const ogImageUrl = blog.ogImage || blog.imageUrl || config.ogImageUrl;
|
||||
const ogImageUrl = (typeof blog.ogImage === 'string' ? blog.ogImage.trim() : '') || (typeof blog.imageUrl === 'string' ? blog.imageUrl.trim() : '');
|
||||
const ogTitle = blog.ogTitle || title;
|
||||
const ogDesc = blog.ogDescription || description;
|
||||
|
||||
@@ -133,14 +133,14 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
openGraph: {
|
||||
title: ogTitle,
|
||||
description: ogDesc,
|
||||
images: [
|
||||
images: ogImageUrl ? [
|
||||
{
|
||||
url: ogImageUrl,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: blog.imageAlt || blog.title || title,
|
||||
},
|
||||
],
|
||||
] : [],
|
||||
url: canonicalUrl,
|
||||
siteName: config.brandNameFa,
|
||||
type: "article",
|
||||
@@ -150,10 +150,10 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
tags: blog.tags?.map((t: any) => typeof t === 'string' ? t : t?.name).filter(Boolean) || [],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
card: ogImageUrl ? "summary_large_image" : "summary",
|
||||
title: ogTitle,
|
||||
description: ogDesc,
|
||||
images: [ogImageUrl],
|
||||
images: ogImageUrl ? [ogImageUrl] : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -205,9 +205,9 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug:
|
||||
},
|
||||
headline: blog.title,
|
||||
description: blog.excerpt || blog.metaDescription || blog.title,
|
||||
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}`],
|
||||
...(typeof blog.imageUrl === 'string' && blog.imageUrl.trim()
|
||||
? { image: [new URL(blog.imageUrl.trim(), siteUrl).href] }
|
||||
: {}),
|
||||
datePublished: publishedIso,
|
||||
dateModified: modifiedIso,
|
||||
author: authorSchema,
|
||||
|
||||
@@ -74,6 +74,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* Authored body links remain recognizable without relying on color alone. */
|
||||
.article-html-content a {
|
||||
color: var(--color-canina-blue);
|
||||
font-weight: 700;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 4px;
|
||||
}
|
||||
.article-html-content a:hover { color: var(--color-medical-gray-900); }
|
||||
|
||||
/* Sonner Toasts Vazirmatn Font & Mobile Offset */
|
||||
[data-sonner-toaster] {
|
||||
font-family: "Vazirmatn", sans-serif !important;
|
||||
|
||||
Reference in new issue
Block a user