Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat(seo): per-route i18n canonicals, hreflang, noindex and sitemap x-default

CristianOlivera1641bfca8c53a
diff --git a/app/[locale]/(auth)/login/layout.tsx b/app/[locale]/(auth)/login/layout.tsx
new file mode 100644
index 0000000..38c0da6
--- /dev/null
+++ b/app/[locale]/(auth)/login/layout.tsx
@@ -0,0 +1,12 @@
+import type { Metadata } from "next";
+
+export const metadata: Metadata = {
+ robots: {
+ index: false,
+ follow: false,
+ },
+};
+
+export default function LoginRouteLayout({ children }: { children: React.ReactNode }) {
+ return <>{children}</>;
+}
\ No newline at end of file
diff --git a/app/[locale]/(editor)/editor/layout.tsx b/app/[locale]/(editor)/editor/layout.tsx
new file mode 100644
index 0000000..3435fe2
--- /dev/null
+++ b/app/[locale]/(editor)/editor/layout.tsx
@@ -0,0 +1,12 @@
+import type { Metadata } from "next";
+
+export const metadata: Metadata = {
+ robots: {
+ index: false,
+ follow: false,
+ },
+};
+
+export default function EditorRouteLayout({ children }: { children: React.ReactNode }) {
+ return <>{children}</>;
+}
\ No newline at end of file
diff --git a/app/[locale]/(home)/donate/page.tsx b/app/[locale]/(home)/donate/page.tsx
index 95bc4e3..db938ed 100644
--- a/app/[locale]/(home)/donate/page.tsx
+++ b/app/[locale]/(home)/donate/page.tsx
@@ -1,6 +1,39 @@
import { headers } from "next/headers";
import { getTranslations } from "next-intl/server";
+import type { Metadata } from "next";
import DonateClient from "./DonateClient";
+import { getRouteAlternates, SEO_BASE_URL } from "@/lib/seo";
+
+type Props = {
+ params: Promise<{ locale: string }>;
+};
+
+export async function generateMetadata({ params }: Props): Promise<Metadata> {
+ const { locale } = await params;
+ const t = await getTranslations("donation.page");
+ const title = t("title");
+ const description = t("description");
+ const url = getRouteAlternates(locale, "/donate");
+
+ return {
+ title,
+ description,
+ alternates: url,
+ openGraph: {
+ title,
+ description,
+ url: url.canonical,
+ images: [
+ {
+ url: `${SEO_BASE_URL}/images/metadata/preview-openvid.jpg`,
+ width: 1200,
+ height: 630,
+ alt: "OpenVid - Support the project",
+ },
+ ],
+ },
+ };
+}
export interface DonationMethod {
id: "yape" | "visa" | "paypal";
diff --git a/app/[locale]/(legal)/privacy/page.tsx b/app/[locale]/(legal)/privacy/page.tsx
index 8f3d072..d6ad623 100644
--- a/app/[locale]/(legal)/privacy/page.tsx
+++ b/app/[locale]/(legal)/privacy/page.tsx
@@ -1,15 +1,46 @@
-"use client";
-
+import type { Metadata } from "next";
import { Icon } from "@iconify/react";
-import Link from "next/link";
-import { useLocale, useTranslations } from "next-intl";
-
-export default function PrivacyPage() {
- const t = useTranslations("privacy");
-
- const locale = useLocale();
-
- const lastUpdatedDate = new Date().toLocaleDateString(locale, {
+import { getLocale, getTranslations, setRequestLocale } from "next-intl/server";
+import { Link } from "@/navigation";
+import { getRouteAlternates, SEO_BASE_URL } from "@/lib/seo";
+
+type Props = {
+ params: Promise<{ locale: string }>;
+};
+
+export async function generateMetadata({ params }: Props): Promise<Metadata> {
+ const { locale } = await params;
+ const t = await getTranslations("privacy");
+ const description = t.raw("intro.content") as string;
+ const url = getRouteAlternates(locale, "/privacy");
+
+ return {
+ title: t("title"),
+ description,
+ alternates: url,
+ openGraph: {
+ title: t("title"),
+ description,
+ url: url.canonical,
+ images: [
+ {
+ url: `${SEO_BASE_URL}/images/metadata/preview-openvid.jpg`,
+ width: 1200,
+ height: 630,
+ alt: "OpenVid - Privacy Policy",
+ },
+ ],
+ },
+ };
+}
+
+export default async function PrivacyPage({ params }: Props) {
+ const { locale } = await params;
+ setRequestLocale(locale);
+ const t = await getTranslations("privacy");
+ const currentLocale = await getLocale();
+
+ const lastUpdatedDate = new Date().toLocaleDateString(currentLocale, {
day: "numeric",
month: "long",
year: "numeric",
diff --git a/app/[locale]/(legal)/terms/page.tsx b/app/[locale]/(legal)/terms/page.tsx
index e24a7bd..30ac724 100644
--- a/app/[locale]/(legal)/terms/page.tsx
+++ b/app/[locale]/(legal)/terms/page.tsx
@@ -1,14 +1,46 @@
-"use client";
-
+import type { Metadata } from "next";
import { Icon } from "@iconify/react";
-import Link from "next/link";
-import { useLocale, useTranslations } from "next-intl";
+import { getLocale, getTranslations, setRequestLocale } from "next-intl/server";
+import { Link } from "@/navigation";
+import { getRouteAlternates, SEO_BASE_URL } from "@/lib/seo";
+
+type Props = {
+ params: Promise<{ locale: string }>;
+};
+
+export async function generateMetadata({ params }: Props): Promise<Metadata> {
+ const { locale } = await params;
+ const t = await getTranslations("terms");
+ const description = t.raw("description.content") as string;
+ const url = getRouteAlternates(locale, "/terms");
+
+ return {
+ title: t("title"),
+ description,
+ alternates: url,
+ openGraph: {
+ title: t("title"),
+ description,
+ url: url.canonical,
+ images: [
+ {
+ url: `${SEO_BASE_URL}/images/metadata/preview-openvid.jpg`,
+ width: 1200,
+ height: 630,
+ alt: "OpenVid - Terms of Service",
+ },
+ ],
+ },
+ };
+}
-export default function TermsPage() {
- const t = useTranslations("terms");
- const locale = useLocale();
+export default async function TermsPage({ params }: Props) {
+ const { locale } = await params;
+ setRequestLocale(locale);
+ const t = await getTranslations("terms");
+ const currentLocale = await getLocale();
- const lastUpdatedDate = new Date().toLocaleDateString(locale, {
+ const lastUpdatedDate = new Date().toLocaleDateString(currentLocale, {
day: "numeric",
month: "long",
year: "numeric",
diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx
index 33c26b9..653d5ec 100644
--- a/app/[locale]/layout.tsx
+++ b/app/[locale]/layout.tsx
@@ -32,11 +32,6 @@ type Props = {
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { locale } = await params;
const baseUrl = 'https://openvid.dev';
-
- const languages: Record<string, string> = {};
- locales.forEach((loc) => {
- languages[loc] = `${baseUrl}/${loc}`;
- });
const ogLocaleMap: Record<string, string> = {
en: 'en_US',
@@ -97,10 +92,6 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
"msapplication-TileColor": "#000000",
"format-detection": "telephone=no",
},
- alternates: {
- canonical: `${baseUrl}/${locale}`,
- languages,
- },
openGraph: {
type: "website",
siteName: "OpenVid",
@@ -149,6 +140,7 @@ export default async function LocaleLayout({
antialiased dark
`}
>
+ <meta httpEquiv="content-language" content={locale} />
<NextIntlClientProvider key={locale} messages={messages} locale={locale}>
<TooltipProvider delayDuration={200}>
{children}
diff --git a/app/components/seo/StructuredData.tsx b/app/components/seo/StructuredData.tsx
index 589ada6..236149c 100644
--- a/app/components/seo/StructuredData.tsx
+++ b/app/components/seo/StructuredData.tsx
@@ -150,6 +150,9 @@ export function generateOrganizationSchema(): OrganizationSchema {
logo: 'https://openvid.dev/images/metadata/favicon.svg',
sameAs: [
'https://x.com/openvid',
+ 'https://www.tiktok.com/@openvid',
+ 'https://www.instagram.com/openvidink',
+ 'https://www.youtube.com/@openvidink',
'https://github.com/CristianOlivera1/openvid',
],
contactPoint: {
diff --git a/app/not-found.tsx b/app/not-found.tsx
index 2bef4be..69c7bfe 100644
--- a/app/not-found.tsx
+++ b/app/not-found.tsx
@@ -1,5 +1,6 @@
import { redirect } from 'next/navigation';
+import { defaultLocale } from '@/i18n';
export default function NotFound() {
- redirect('/es');
+ redirect(`/${defaultLocale}`);
}
diff --git a/app/robots.ts b/app/robots.ts
index a37db8f..8e767a7 100644
--- a/app/robots.ts
+++ b/app/robots.ts
@@ -11,6 +11,11 @@ export default function robots(): MetadataRoute.Robots {
disallow: [
'/api/',
'/auth/callback',
+ '/*/auth/callback',
+ '/editor',
+ '/*/editor',
+ '/login',
+ '/*/login',
],
},
],
diff --git a/app/sitemap.ts b/app/sitemap.ts
deleted file mode 100644
index 75e01e5..0000000
--- a/app/sitemap.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import type { MetadataRoute } from 'next';
-import { locales } from '@/i18n';
-
-export default function sitemap(): MetadataRoute.Sitemap {
- const baseUrl = 'https://openvid.dev';
-
- const routes = [
- {
- path: '',
- priority: 1.0,
- changeFrequency: 'weekly' as const,
- },
- {
- path: '/donate',
- priority: 0.7,
- changeFrequency: 'monthly' as const,
- },
- {
- path: '/privacy',
- priority: 0.5,
- changeFrequency: 'yearly' as const,
- },
- {
- path: '/terms',
- priority: 0.5,
- changeFrequency: 'yearly' as const,
- },
- ];
-
- const sitemap: MetadataRoute.Sitemap = [];
-
- routes.forEach(({ path, priority, changeFrequency }) => {
- locales.forEach((locale) => {
- const url = path
- ? `${baseUrl}/${locale}${path}`
- : `${baseUrl}/${locale}`;
-
- sitemap.push({
- url,
- lastModified: new Date(),
- changeFrequency,
- priority,
- alternates: {
- languages: Object.fromEntries(
- locales.map((loc) => [
- loc,
- path ? `${baseUrl}/${loc}${path}` : `${baseUrl}/${loc}`,
- ])
- ),
- },
- });
- });
- });
-
- return sitemap;
-}
diff --git a/app/sitemap.xml/route.ts b/app/sitemap.xml/route.ts
new file mode 100644
index 0000000..ec57767
--- /dev/null
+++ b/app/sitemap.xml/route.ts
@@ -0,0 +1,60 @@
+import { locales, defaultLocale } from '@/i18n';
+
+const BASE_URL = 'https://openvid.dev';
+
+const routes = [
+ { path: '', priority: 1.0, changeFrequency: 'weekly' },
+ { path: '/donate', priority: 0.7, changeFrequency: 'monthly' },
+ { path: '/privacy', priority: 0.5, changeFrequency: 'yearly' },
+ { path: '/terms', priority: 0.5, changeFrequency: 'yearly' },
+];
+
+const LAST_MOD = '2026-08-03T00:00:00+00:00';
+
+function escapeXml(value: string): string {
+ return value
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&apos;');
+}
+
+export function GET() {
+ const urls = routes.flatMap(({ path, priority, changeFrequency }) =>
+ locales.map((locale) => {
+ const selfHref = `${BASE_URL}/${locale}${path}`;
+ const xDefault = `${BASE_URL}/${defaultLocale}${path}`;
+
+ const alternates = locales
+ .map(
+ (loc) =>
+ ` <xhtml:link rel="alternate" hreflang="${loc}" href="${escapeXml(
+ `${BASE_URL}/${loc}${path}`
+ )}" />`
+ )
+ .join('\n');
+
+ return ` <url>
+ <loc>${escapeXml(selfHref)}</loc>
+ <lastmod>${LAST_MOD}</lastmod>
+ <changefreq>${changeFrequency}</changefreq>
+ <priority>${priority}</priority>
+${alternates}
+ <xhtml:link rel="alternate" hreflang="x-default" href="${escapeXml(xDefault)}" />
+ </url>`;
+ })
+ );
+
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+${urls.join('\n')}
+</urlset>`;
+
+ return new Response(xml, {
+ headers: {
+ 'Content-Type': 'application/xml; charset=utf-8',
+ 'Cache-Control': 'public, max-age=3600, s-maxage=86400',
+ },
+ });
+}
\ No newline at end of file
diff --git a/lib/seo.ts b/lib/seo.ts
new file mode 100644
index 0000000..769497d
--- /dev/null
+++ b/lib/seo.ts
@@ -0,0 +1,15 @@
+import { locales } from '@/i18n';
+
+export const SEO_BASE_URL = 'https://openvid.dev';
+
+export function getRouteAlternates(locale: string, path: string = '') {
+ const languages: Record<string, string> = {};
+ locales.forEach((loc) => {
+ languages[loc] = `${SEO_BASE_URL}/${loc}${path}`;
+ });
+
+ return {
+ canonical: `${SEO_BASE_URL}/${locale}${path}`,
+ languages,
+ };
+}
\ No newline at end of file