Skip to content

Commit

Permalink
Merge pull request #251 from storybookjs/fix-document-titles-2
Browse files Browse the repository at this point in the history
Don't assign an `undefined` document title
  • Loading branch information
kylegach authored Dec 5, 2024
2 parents 4252f21 + a7f91fe commit 291c201
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
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

0 comments on commit 291c201

Please sign in to comment.