fix(blog): publish truthful image and team SEO metadata
Deploy Canina / deploy (push) Successful in 4m50s
Deploy Canina / deploy (push) Successful in 4m50s
This commit is contained in:
1 parent
5897abcbad
commit
44d74d35e6
4 files changed
+41
-3
No files matched your search
@@ -109,6 +109,10 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
keywords: keywordsList,
|
||||
alternates: {
|
||||
canonical: canonicalUrl,
|
||||
languages: {
|
||||
'fa-IR': canonicalUrl,
|
||||
'x-default': canonicalUrl,
|
||||
},
|
||||
},
|
||||
robots: isStaging
|
||||
? {
|
||||
@@ -138,8 +142,6 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
images: [
|
||||
{
|
||||
url: ogImageUrl,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: blog.imageAlt || blog.title || title,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { afterEach, expect, it, vi } from 'vitest';
|
||||
import { generateMetadata } from './page';
|
||||
|
||||
vi.mock('../../../lib/seo', () => ({
|
||||
getSeoConfig: async () => ({ brandNameFa: 'کنینا', canonicalBaseUrl: 'https://canina.ir', ogImageUrl: '/fallback.png' }),
|
||||
formatPageTitle: (title: string) => title,
|
||||
}));
|
||||
|
||||
afterEach(() => { vi.unstubAllGlobals(); vi.unstubAllEnvs(); });
|
||||
|
||||
it('uses the exact canonical for monolingual self-referencing language hints', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({ title: 'Ear care', canonicalUrl: 'https://canina.ir/blog/ear-care/' }) }));
|
||||
const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'ear-care' }) });
|
||||
expect(metadata.alternates).toEqual({ canonical: 'https://canina.ir/blog/ear-care', languages: { 'fa-IR': 'https://canina.ir/blog/ear-care', 'x-default': 'https://canina.ir/blog/ear-care' } });
|
||||
});
|
||||
|
||||
it('does not invent dimensions for a publisher supplied OG asset', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({ title: 'Ear care', imageUrl: '/ear-800x450.jpg' }) }));
|
||||
const metadata = await generateMetadata({ params: Promise.resolve({ slug: 'ear-care' }) });
|
||||
expect((metadata.openGraph as any).images[0]).toEqual({ url: '/ear-800x450.jpg', alt: 'Ear care' });
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { expect, it } from 'vitest';
|
||||
import { resolveBlogAuthorIdentity } from './blogAuthor';
|
||||
|
||||
it('models the specialty team account as Organization without inventing a person', () => {
|
||||
expect(resolveBlogAuthorIdentity({ author: { firstName: 'کارشناس رفتار و نگهداری', lastName: 'تیم کنینا' }, authorTeam: 'پوست، مو و آلرژی' })).toEqual({
|
||||
type: 'Organization', name: 'کارشناس رفتار و نگهداری تیم کنینا', teamName: 'پوست، مو و آلرژی',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps a named individual a Person even when affiliated with an editorial team', () => {
|
||||
expect(resolveBlogAuthorIdentity({ author: { firstName: 'سارا', lastName: 'احمدی' }, authorTeam: 'تیم کنینا' }).type).toBe('Person');
|
||||
});
|
||||
@@ -32,7 +32,10 @@ export function resolveBlogAuthorIdentity(blog: BlogAuthorInput): ResolvedBlogAu
|
||||
const teamName = blog.authorTeam?.trim() || BLOG_TEAM_FALLBACK;
|
||||
|
||||
if (personName) {
|
||||
return { type: 'Person', name: personName, teamName };
|
||||
// Specialty accounts identify themselves as a team, not a named individual.
|
||||
// An individual's authorTeam affiliation alone does not change their type.
|
||||
const isTeamAccount = /(?:^|\s)تیم(?:\s|$)/u.test(personName);
|
||||
return { type: isTeamAccount ? 'Organization' : 'Person', name: personName, teamName };
|
||||
}
|
||||
|
||||
return { type: 'Organization', name: BLOG_AUTHOR_FALLBACK, teamName };
|
||||
|
||||
Reference in new issue
Block a user