fix(seo): provide explicit noindex and self-canonical for login and cart pages
This commit is contained in:
1 parent
e34156b2d3
commit
af32ec14e1
6 files changed
+153
-25
No files matched your search
@@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import CartDrawer from "../../components/CartDrawer";
|
||||
|
||||
export default function CartClient() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<main className="min-h-screen bg-medical-gray-50" dir="rtl">
|
||||
<h1 className="sr-only">سبد خرید</h1>
|
||||
<CartDrawer
|
||||
isOpen
|
||||
onClose={() => router.push("/")}
|
||||
onCheckout={() => router.push("/checkout")}
|
||||
onShopNavigate={() => router.push("/shop")}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { generateMetadata } from './page';
|
||||
|
||||
vi.mock('../../lib/seo', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../lib/seo')>();
|
||||
return {
|
||||
...actual,
|
||||
getSeoConfig: vi.fn().mockResolvedValue({
|
||||
texts: {},
|
||||
brandNameFa: 'کنینا ایران',
|
||||
titleSeparator: '|',
|
||||
titlePosition: 'suffix',
|
||||
canonicalBaseUrl: 'https://canina.ir',
|
||||
ogImageUrl: 'https://canina.ir/assets/og.jpg',
|
||||
defaultMetaTitle: 'کنینا ایران',
|
||||
defaultMetaDescription: 'فروشگاه رسمی کنینا',
|
||||
keywords: ['canina'],
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('/cart metadata', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubEnv('NEXT_PUBLIC_APP_ENV', 'production');
|
||||
vi.stubEnv('NODE_ENV', 'production');
|
||||
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://canina.ir');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('provides explicit noindex and self-canonical without pointing canonical to home', async () => {
|
||||
const meta = await generateMetadata();
|
||||
|
||||
// Must be noindex
|
||||
expect(meta.robots).toMatchObject({
|
||||
index: false,
|
||||
follow: false,
|
||||
});
|
||||
|
||||
// Canonical must be self-referential /cart, NOT home '/'
|
||||
expect(meta.alternates?.canonical).toBe('https://canina.ir/cart');
|
||||
expect(meta.alternates?.canonical).not.toBe('https://canina.ir/');
|
||||
expect(meta.alternates?.canonical).not.toBe('https://canina.ir');
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,16 @@
|
||||
"use client";
|
||||
import type { Metadata } from 'next';
|
||||
import { getPageMetadata } from '../../lib/seo';
|
||||
import CartClient from './CartClient';
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import CartDrawer from "../../components/CartDrawer";
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return getPageMetadata('cart', {
|
||||
canonicalPath: '/cart',
|
||||
fallbackTitle: 'سبد خرید',
|
||||
fallbackDesc: 'مشاهده و مدیریت اقلام انتخابی سبد خرید، محاسبه تخفیف و ادامه فرآیند سفارش.',
|
||||
noIndex: true,
|
||||
});
|
||||
}
|
||||
|
||||
export default function CartPage() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<main className="min-h-screen bg-medical-gray-50" dir="rtl">
|
||||
<h1 className="sr-only">سبد خرید</h1>
|
||||
<CartDrawer
|
||||
isOpen
|
||||
onClose={() => router.push("/")}
|
||||
onCheckout={() => router.push("/checkout")}
|
||||
onShopNavigate={() => router.push("/shop")}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
return <CartClient />;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import AuthModal from "../../components/AuthModal";
|
||||
|
||||
export default function LoginClient() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<main className="min-h-screen bg-medical-gray-50 px-4 py-12" dir="rtl">
|
||||
<h1 className="sr-only">ورود یا ثبتنام</h1>
|
||||
<AuthModal isOpen onClose={() => router.push("/")} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { generateMetadata } from './page';
|
||||
|
||||
vi.mock('../../lib/seo', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../lib/seo')>();
|
||||
return {
|
||||
...actual,
|
||||
getSeoConfig: vi.fn().mockResolvedValue({
|
||||
texts: {},
|
||||
brandNameFa: 'کنینا ایران',
|
||||
titleSeparator: '|',
|
||||
titlePosition: 'suffix',
|
||||
canonicalBaseUrl: 'https://canina.ir',
|
||||
ogImageUrl: 'https://canina.ir/assets/og.jpg',
|
||||
defaultMetaTitle: 'کنینا ایران',
|
||||
defaultMetaDescription: 'فروشگاه رسمی کنینا',
|
||||
keywords: ['canina'],
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('/login metadata', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubEnv('NEXT_PUBLIC_APP_ENV', 'production');
|
||||
vi.stubEnv('NODE_ENV', 'production');
|
||||
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://canina.ir');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('provides explicit noindex and self-canonical without pointing canonical to home', async () => {
|
||||
const meta = await generateMetadata();
|
||||
|
||||
// Must be noindex
|
||||
expect(meta.robots).toMatchObject({
|
||||
index: false,
|
||||
follow: false,
|
||||
});
|
||||
|
||||
// Canonical must be self-referential /login, NOT home '/'
|
||||
expect(meta.alternates?.canonical).toBe('https://canina.ir/login');
|
||||
expect(meta.alternates?.canonical).not.toBe('https://canina.ir/');
|
||||
expect(meta.alternates?.canonical).not.toBe('https://canina.ir');
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,16 @@
|
||||
"use client";
|
||||
import type { Metadata } from 'next';
|
||||
import { getPageMetadata } from '../../lib/seo';
|
||||
import LoginClient from './LoginClient';
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import AuthModal from "../../components/AuthModal";
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return getPageMetadata('login', {
|
||||
canonicalPath: '/login',
|
||||
fallbackTitle: 'ورود یا ثبتنام',
|
||||
fallbackDesc: 'ورود به حساب کاربری، ثبتنام و مدیریت سفارشات مکملهای دارویی کنینا آلمان.',
|
||||
noIndex: true,
|
||||
});
|
||||
}
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<main className="min-h-screen bg-medical-gray-50 px-4 py-12" dir="rtl">
|
||||
<h1 className="sr-only">ورود یا ثبتنام</h1>
|
||||
<AuthModal isOpen onClose={() => router.push("/")} />
|
||||
</main>
|
||||
);
|
||||
return <LoginClient />;
|
||||
}
|
||||
Reference in new issue
Block a user