Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d57700d322 |
@@ -14,20 +14,6 @@ interface PageProps {
|
|||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
|
||||||
const locales = ['en', 'de'];
|
|
||||||
const params = [];
|
|
||||||
|
|
||||||
for (const locale of locales) {
|
|
||||||
const pages = await getAllPages(locale);
|
|
||||||
for (const page of pages) {
|
|
||||||
params.push({ locale, slug: page.slug });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
const pageData = await getPageBySlug(slug, locale);
|
const pageData = await getPageBySlug(slug, locale);
|
||||||
|
|||||||
10
lib/blog.ts
10
lib/blog.ts
@@ -57,6 +57,7 @@ export function isPostVisible(post: { frontmatter: { date: string; public?: bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
|
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
|
|
||||||
const { docs } = await payload.find({
|
const { docs } = await payload.find({
|
||||||
@@ -97,9 +98,14 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostM
|
|||||||
} as PostFrontmatter,
|
} as PostFrontmatter,
|
||||||
content: doc.content as any, // Native Lexical Editor State
|
content: doc.content as any, // Native Lexical Editor State
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getPostBySlug failed for ${slug}:`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
// Query only published posts (access checks applied automatically by Payload!)
|
// Query only published posts (access checks applied automatically by Payload!)
|
||||||
const { docs } = await payload.find({
|
const { docs } = await payload.find({
|
||||||
@@ -140,6 +146,10 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
|||||||
content: doc.content as any,
|
content: doc.content as any,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getAllPosts failed for ${locale}:`, error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPostsMetadata(locale: string): Promise<Partial<PostMdx>[]> {
|
export async function getAllPostsMetadata(locale: string): Promise<Partial<PostMdx>[]> {
|
||||||
|
|||||||
23
lib/mdx.ts
23
lib/mdx.ts
@@ -79,6 +79,7 @@ export async function getProductMetadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getProductBySlug(slug: string, locale: string): Promise<ProductMdx | null> {
|
export async function getProductBySlug(slug: string, locale: string): Promise<ProductMdx | null> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
||||||
|
|
||||||
@@ -124,7 +125,9 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
|||||||
title: doc.title,
|
title: doc.title,
|
||||||
sku: doc.sku,
|
sku: doc.sku,
|
||||||
description: doc.description,
|
description: doc.description,
|
||||||
categories: Array.isArray(doc.categories) ? doc.categories.map((c: any) => c.category) : [],
|
categories: Array.isArray(doc.categories)
|
||||||
|
? doc.categories.map((c: any) => c.category)
|
||||||
|
: [],
|
||||||
images: resolvedImages,
|
images: resolvedImages,
|
||||||
locale: doc.locale,
|
locale: doc.locale,
|
||||||
isFallback,
|
isFallback,
|
||||||
@@ -134,9 +137,14 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getProductBySlug failed for ${slug}:`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
collection: 'products',
|
collection: 'products',
|
||||||
@@ -149,9 +157,14 @@ export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return result.docs.map((doc) => doc.slug);
|
return result.docs.map((doc) => doc.slug);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getAllProductSlugs failed for ${locale}:`, error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
|
|
||||||
const selectFields = {
|
const selectFields = {
|
||||||
@@ -186,7 +199,9 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
|||||||
title: doc.title,
|
title: doc.title,
|
||||||
sku: doc.sku || '',
|
sku: doc.sku || '',
|
||||||
description: doc.description || '',
|
description: doc.description || '',
|
||||||
categories: Array.isArray(doc.categories) ? doc.categories.map((c: any) => c.category) : [],
|
categories: Array.isArray(doc.categories)
|
||||||
|
? doc.categories.map((c: any) => c.category)
|
||||||
|
: [],
|
||||||
images: ((doc.images as any[]) || [])
|
images: ((doc.images as any[]) || [])
|
||||||
.map((img) => (typeof img === 'string' ? img : img.url))
|
.map((img) => (typeof img === 'string' ? img : img.url))
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
@@ -236,6 +251,10 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return products;
|
return products;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getAllProducts failed for ${locale}:`, error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllProductsMetadata(locale: string): Promise<Partial<ProductMdx>[]> {
|
export async function getAllProductsMetadata(locale: string): Promise<Partial<ProductMdx>[]> {
|
||||||
|
|||||||
15
lib/pages.ts
15
lib/pages.ts
@@ -16,6 +16,7 @@ export interface PageMdx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getPageBySlug(slug: string, locale: string): Promise<PageMdx | null> {
|
export async function getPageBySlug(slug: string, locale: string): Promise<PageMdx | null> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
|
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
@@ -46,9 +47,14 @@ export async function getPageBySlug(slug: string, locale: string): Promise<PageM
|
|||||||
} as PageFrontmatter,
|
} as PageFrontmatter,
|
||||||
content: doc.content as any, // Native Lexical Editor State
|
content: doc.content as any, // Native Lexical Editor State
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getPageBySlug failed for ${slug}:`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPages(locale: string): Promise<PageMdx[]> {
|
export async function getAllPages(locale: string): Promise<PageMdx[]> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
|
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
@@ -78,9 +84,14 @@ export async function getAllPages(locale: string): Promise<PageMdx[]> {
|
|||||||
content: doc.content as any,
|
content: doc.content as any,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getAllPages failed for ${locale}:`, error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPagesMetadata(locale: string): Promise<Partial<PageMdx>[]> {
|
export async function getAllPagesMetadata(locale: string): Promise<Partial<PageMdx>[]> {
|
||||||
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
|
|
||||||
const result = await payload.find({
|
const result = await payload.find({
|
||||||
@@ -109,4 +120,8 @@ export async function getAllPagesMetadata(locale: string): Promise<Partial<PageM
|
|||||||
} as PageFrontmatter,
|
} as PageFrontmatter,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[Payload] getAllPagesMetadata failed for ${locale}:`, error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -1,6 +1,6 @@
|
|||||||
/// <reference types="next" />
|
/// <reference types="next" />
|
||||||
/// <reference types="next/image-types/global" />
|
/// <reference types="next/image-types/global" />
|
||||||
import "./.next/dev/types/routes.d.ts";
|
import "./.next/types/routes.d.ts";
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
// NOTE: This file should not be edited
|
||||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
|
|||||||
@@ -136,7 +136,7 @@
|
|||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"preinstall": "npx only-allow pnpm"
|
"preinstall": "npx only-allow pnpm"
|
||||||
},
|
},
|
||||||
"version": "2.0.0",
|
"version": "2.0.1",
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"onlyBuiltDependencies": [
|
"onlyBuiltDependencies": [
|
||||||
"@parcel/watcher",
|
"@parcel/watcher",
|
||||||
|
|||||||
Reference in New Issue
Block a user