Skip to content

Commit 6797f18

Browse files
fix(blog): apply proper route to metadata call (#8224)
* fix(blog): apply proper route to metadata call * fixup! * use nextjs types * use other types * use other types --------- Co-authored-by: avivkeller <me@aviv.sh>
1 parent 843297a commit 6797f18

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

apps/site/app/[locale]/blog/[...path]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const generateViewport = basePage.generateViewport;
1515

1616
// This generates each page's HTML Metadata
1717
// @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
18-
export const generateMetadata = basePage.generateMetadata;
18+
export const generateMetadata = ({ params }: PageParams) =>
19+
basePage.generateMetadata({ params, prefix: 'blog' });
1920

2021
// Generates all possible static paths based on the locales and environment configuration
2122
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)

apps/site/next.dynamic.page.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { join } from 'node:path';
2+
13
import { notFound, redirect } from 'next/navigation';
24
import { setRequestLocale } from 'next-intl/server';
35

@@ -23,15 +25,19 @@ export const generateViewport = () => ({ ...PAGE_VIEWPORT });
2325
*
2426
* @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
2527
*
26-
* @param {{ params: Promise<{ path: Array<string>; locale: string }> }} props
28+
* @param {{ params: Promise<{ path: Array<string>; locale: string }>, prefix?: string }} props
2729
* @returns {Promise<import('next').Metadata>} the metadata for the page
2830
*/
29-
export const generateMetadata = async props => {
30-
const { path = [], locale = defaultLocale.code } = await props.params;
31+
export const generateMetadata = async ({ params, prefix }) => {
32+
const { path = [], locale = defaultLocale.code } = await params;
3133

3234
const pathname = dynamicRouter.getPathname(path);
3335

34-
return dynamicRouter.getPageMetadata(locale, pathname);
36+
return dynamicRouter.getPageMetadata(
37+
locale,
38+
// If there's a prefix, `join` it with the pathname
39+
prefix ? join(prefix, pathname) : pathname
40+
);
3541
};
3642

3743
/**

0 commit comments

Comments
 (0)