Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assign an undefined document title #251

Merged
merged 1 commit into from
Dec 5, 2024
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
9 changes: 7 additions & 2 deletions apps/addon-catalog/app/(home)/tag/[...name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ export const generateMetadata: GenerateMetaData = async ({ params }) => {
const data = (await fetchTagDetailsData(tagName)) || {};

if ('error' in data) return {};
const { displayName } = data;

const title = data.displayName ?? data.name;

return {
title: displayName ? `${displayName} tag | Storybook integrations` : undefined,
...(title
? {
title: `${title} tag | Storybook integrations`,
}
: undefined),
};
};

Expand Down
10 changes: 7 additions & 3 deletions apps/addon-catalog/app/[...addonName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export const generateMetadata: GenerateMetaData = async ({ params }) => {
const name = (await params).addonName;
const addon = await getAddonFromName(name);

const title = addon?.displayName ?? addon?.name;

return {
title: addon?.displayName
? `${addon.displayName} | Storybook integrations`
: undefined,
...(title
? {
title: `${title} | Storybook integrations`,
}
: undefined),
};
};

Expand Down
2 changes: 1 addition & 1 deletion apps/frontpage/app/docs/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const generateMetadata: GenerateMetaData = async ({ params }) => {
);

return {
title: page?.title ? `${page.title} | Storybook docs` : undefined,
title: page?.title ? `${page.title} | Storybook docs` : 'Storybook docs',
alternates: {
canonical: findPage?.canonical,
},
Expand Down
2 changes: 1 addition & 1 deletion apps/frontpage/app/docs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function generateMetadata(): Promise<Metadata> {
const page = await getPageData([latestVersion.id], latestVersion);

return {
title: page?.title ? `${page.title} | Storybook docs` : undefined,
title: page?.title ? `${page.title} | Storybook docs` : 'Storybook docs',
alternates: {
canonical: '/docs',
},
Expand Down
10 changes: 4 additions & 6 deletions apps/frontpage/app/recipes/[...name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ interface RecipeDetailsProps {
params: Params;
}

async function getRecipeFromName(
addonName: string[],
): Promise<
async function getRecipeFromName(addonName: string[]): Promise<
// TODO: More precise typing to avoid these omits
| Omit<
RecipeWithTagLinks,
Expand All @@ -55,10 +53,10 @@ export const generateMetadata: GenerateMetaData = async ({ params }) => {
const name = (await params).name;
const recipe = await getRecipeFromName(name);

const title = recipe?.displayName ?? recipe?.name;

return {
title: recipe?.displayName
? `${recipe.displayName} | Storybook recipes`
: undefined,
title: title ? `${title} | Storybook recipes` : 'Storybook recipes',
};
};

Expand Down
Loading