Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app/academy/(en)/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { academySource } from "@/lib/source";
import { academyJaSource, academySource } from "@/lib/source";
import { DocsChromePage } from "@/components/DocsChromePage";
import { buildSectionMetadata } from "@/lib/mdx-page";
import { buildLocalizedAlternates } from "@/lib/localization";

type PageProps = {
params: Promise<{ slug?: string[] }>;
Expand All @@ -21,7 +22,18 @@ export async function generateMetadata({
const { slug = [] } = await params;
const page = academySource.getPage(slug);
if (!page) return { title: "Not Found" };
return buildSectionMetadata(page, "academy", "Academy", slug);
const hasJapanesePage = Boolean(academyJaSource.getPage(slug));

return buildSectionMetadata(page, "academy", "Academy", slug, {
languages: buildLocalizedAlternates({
slug,
defaultLocale: "en",
routes: {
en: "/academy",
...(hasJapanesePage ? { "ja-JP": "/academy/japan" } : {}),
},
}),
});
}

export function generateStaticParams() {
Expand Down
17 changes: 15 additions & 2 deletions app/academy/japan/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { academyJaSource } from "@/lib/source";
import { academyJaSource, academySource } from "@/lib/source";
import { DocsChromePage } from "@/components/DocsChromePage";
import { buildSectionMetadata } from "@/lib/mdx-page";
import { buildLocalizedAlternates } from "@/lib/localization";

type PageProps = {
params: Promise<{ slug?: string[] }>;
Expand All @@ -15,6 +16,7 @@ export default async function JaAcademyPage({ params }: PageProps) {
return (
<DocsChromePage
page={page}
bodyChromeProps={{ lang: "ja" }}
bottomSuffix={
<div className="mt-10 text-right text-xs italic text-fd-muted-foreground">
Translation by{" "}
Expand All @@ -38,7 +40,18 @@ export async function generateMetadata({
const { slug = [] } = await params;
const page = academyJaSource.getPage(slug);
if (!page) return { title: "Not Found" };
return buildSectionMetadata(page, "academy/japan", "Academy", slug);
const hasEnglishPage = Boolean(academySource.getPage(slug));

return buildSectionMetadata(page, "academy/japan", "Academy", slug, {
languages: buildLocalizedAlternates({
slug,
defaultLocale: "en",
routes: {
...(hasEnglishPage ? { en: "/academy" } : {}),
"ja-JP": "/academy/japan",
},
}),
});
}

export function generateStaticParams() {
Expand Down
9 changes: 5 additions & 4 deletions app/japan/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { Metadata } from "next";
import { JapanLanding } from "@/components/japan/JapanLanding";
import { buildLocalizedAlternates } from "@/lib/localization";

export const metadata: Metadata = {
title: "Langfuse Cloud Japan — 東京でホストされるLLMオブザーバビリティ",
description:
"Langfuse Cloud Japan — LLMのトレース、プロンプト管理、評価、メトリクスを、AWS ap-northeast-1(東京)とClickHouseで運用。",
alternates: {
canonical: "https://langfuse.com/japan",
languages: {
en: "https://langfuse.com/japan",
ja: "https://langfuse.com/japan",
},
languages: buildLocalizedAlternates({
defaultLocale: "ja-JP",
routes: { "ja-JP": "/japan" },
}),
},
};

Expand Down
4 changes: 3 additions & 1 deletion components/DocBodyChrome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { ReactNode } from "react";

type Props = {
children: ReactNode;
lang?: string;
/**
* When false, renders a plain flex-1 div without prose chrome.
* Used by wide/marketing sections (pricing, etc.).
Expand All @@ -33,6 +34,7 @@ type Props = {
*/
export function DocBodyChrome({
children,
lang,
withProse = true,
versionLabel,
}: Props) {
Expand All @@ -48,7 +50,7 @@ export function DocBodyChrome({
}

return (
<DocsBody className="flex-1">
<DocsBody className="flex-1" lang={lang}>
<div className="mx-auto w-full">
<div
className={
Expand Down
27 changes: 27 additions & 0 deletions lib/localization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Metadata } from "next";
import { buildPageUrl } from "@/lib/og-url";

type Languages = NonNullable<Metadata["alternates"]>["languages"];

export function buildLocalizedAlternates({
slug = [],
defaultLocale,
routes,
}: {
slug?: string[];
defaultLocale: string;
routes: Record<string, string>;
}): Languages {
const slugPath = slug.length > 0 ? `/${slug.join("/")}` : "";
const languages: Record<string, string> = {};

for (const [locale, basePath] of Object.entries(routes)) {
languages[locale] = buildPageUrl(`${basePath}${slugPath}`);
}

if (languages[defaultLocale]) {
languages["x-default"] = languages[defaultLocale];
}

return languages;
}
10 changes: 8 additions & 2 deletions lib/mdx-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export function buildSectionMetadata(
section: string,
sectionTitle: string,
slug: string[],
opts?: { canonicalFallback?: string | null },
opts?: {
canonicalFallback?: string | null;
languages?: NonNullable<Metadata["alternates"]>["languages"];
},
): Metadata {
const pageData = page.data;
const pagePath = `/${section}${slug.length > 0 ? `/${slug.join("/")}` : ""}`;
Expand All @@ -135,7 +138,10 @@ export function buildSectionMetadata(
return {
title: seoTitle,
description: page.data.description ?? undefined,
alternates: { canonical: canonicalUrl },
alternates: {
canonical: canonicalUrl,
...(opts?.languages ? { languages: opts.languages } : {}),
},
...(pageData.noindex ? { robots: { index: false, follow: true } } : {}),
openGraph: {
images: [{ url: ogImage }],
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-sitemap-excludes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function contentPathToRoute(filePath) {
changelog: "changelog",
faq: "faq",
handbook: "handbook",
academy: "academy",
security: "security",
blog: "blog",
customers: "users",
Expand Down