|
1 | | -import { PageAsset } from "@/components/page-asset"; |
2 | | -import { ErrorPage } from "@/components/error"; |
3 | | -import { getDotCMSPage } from "@/util/getDotCMSPage"; |
4 | | -import { getNavSections } from "@/services/docs/getNavSections"; |
5 | | -import { getSideNav } from "@/services/docs/getSideNav"; |
6 | | -import { BlockPageAsset } from "@/components/page-asset-with-content-block"; |
7 | | -/** |
8 | | - * Generate metadata |
9 | | - * |
10 | | - * @export |
11 | | - * @param {*} { params, searchParams } |
12 | | - * @return {*} |
13 | | - */ |
14 | | -export async function generateMetadata({ params }) { |
15 | | - const finalParams = await params; |
16 | | - const path = finalParams?.slug?.join("/") || "/"; |
17 | | - |
18 | | - try { |
19 | | - const pageContent = await getDotCMSPage(path); |
20 | | - if (!pageContent) { |
21 | | - return { |
22 | | - title: "not found", |
23 | | - }; |
24 | | - } |
25 | | - |
26 | | - const { pageAsset } = pageContent; |
27 | | - const page = pageAsset.page; |
28 | | - |
29 | | - const title = page?.friendlyName || page?.title; |
30 | | - |
31 | | - const description = page?.description || page?.teaser || page?.seoDescription || "dotCMS Dev Site, Documentation and Resources. Learn how to build with dotCMS"; |
32 | | - const hostname = "https://dev.dotcms.com"; |
33 | | - const keywords = page?.tags ? page?.tags.join(", ") : "dotcms, dotcms documentation, learn dotcms, dotcms api, dotcms dev, dotcms developer, dotcms developer documentation, dotcms developer api, dotcms developer documentation, dotcms developer api"; |
34 | | - |
35 | | - return { |
36 | | - title: title, |
37 | | - description: description, |
38 | | - url: `${hostname}${path}`, |
39 | | - siteName: 'dotCMS Docs', |
40 | | - keywords: keywords, |
41 | | - alternates: { |
42 | | - canonical: `${hostname}${path}`, |
43 | | - }, |
44 | | - metadataBase: new URL(hostname), |
45 | | - images: [{ |
46 | | - url: `${hostname}/dA/4b13a794db115b14ce79d30850712188/1024maxw/80q/}`, |
47 | | - width: 1200, |
48 | | - height: 630, |
49 | | - alt: description || title, |
50 | | - }], |
51 | | - locale: 'en_US', |
52 | | - type: 'article', |
53 | | - }; |
54 | | - } catch (e) { |
55 | | - console.error('Error generating metadata:', e?.message || e); |
56 | | - return { |
57 | | - title: "not found", |
58 | | - }; |
59 | | - } |
60 | | -} |
61 | | - |
62 | | -export default async function Page({ params }) { |
63 | | - const finalParams = await params; |
64 | | - |
65 | | - const path = finalParams?.slug?.join("/") || "/"; |
66 | | - const pageContent = await getDotCMSPage(path); |
67 | | - |
68 | | - |
69 | | - if (!pageContent) { |
70 | | - return <ErrorPage error={{ message: "Page not found", status: 404 }} />; |
71 | | - } |
72 | | - |
73 | | - const { pageAsset } = pageContent; |
74 | | - const isBlockPage = pageAsset?.page?.contentType === "BlockPage" |
75 | | - |
76 | | - if (isBlockPage) { |
77 | | - // Fetch navigation data (reuse cached nav sections instead of separate API call) |
78 | | - const [searchData, navSections] = await Promise.all([ |
79 | | - getSideNav(), |
80 | | - getNavSections({ path: '/docs/nav', depth: 4, languageId: 1, ttlSeconds: 600 }) |
81 | | - ]); |
82 | | - |
83 | | - // Extract the first segment of the URL to find the matching nav section |
84 | | - const pathParts = pageAsset?.page?.url.split("/").filter(part => part.length > 0); |
85 | | - const firstSegment = pathParts.length > 0 ? pathParts[0] : ""; |
86 | | - |
87 | | - // Find the nav section that matches the current page's top-level folder |
88 | | - // e.g., for "/getting-started/back-end/setup", find the "Getting Started" section |
89 | | - const matchingSection = navSections?.find(section => { |
90 | | - // Normalize section title to match URL segment |
91 | | - // e.g., "Getting Started" -> "getting-started" |
92 | | - const normalizedTitle = section.title.toLowerCase().replace(/\s+/g, '-'); |
93 | | - return normalizedTitle === firstSegment; |
94 | | - }); |
95 | | - |
96 | | - // If no matching section found, fall back to empty array |
97 | | - const navItems = matchingSection?.items || []; |
98 | | - |
99 | | - return ( |
100 | | - <BlockPageAsset |
101 | | - pageContent={pageContent} |
102 | | - nav={navItems} |
103 | | - searchItems={searchData[0]?.dotcmsdocumentationchildren || []} |
104 | | - navSections={navSections} |
105 | | - /> |
106 | | - ); |
107 | | - } |
108 | | - |
109 | | - return ( |
110 | | - <PageAsset |
111 | | - pageContent={pageContent} |
112 | | - /> |
113 | | - ); |
114 | | -} |
| 1 | +import { PageAsset } from "@/components/page-asset"; |
| 2 | +import { ErrorPage } from "@/components/error"; |
| 3 | +import { getDotCMSPage } from "@/util/getDotCMSPage"; |
| 4 | +import { getNavSections } from "@/services/docs/getNavSections"; |
| 5 | +import { getSideNav } from "@/services/docs/getSideNav"; |
| 6 | +import { BlockPageAsset } from "@/components/page-asset-with-content-block"; |
| 7 | +/** |
| 8 | + * Generate metadata |
| 9 | + * |
| 10 | + * @export |
| 11 | + * @param {*} { params, searchParams } |
| 12 | + * @return {*} |
| 13 | + */ |
| 14 | +export async function generateMetadata({ params }) { |
| 15 | + const finalParams = await params; |
| 16 | + const path = finalParams?.slug?.join("/") || "/"; |
| 17 | + |
| 18 | + try { |
| 19 | + const pageContent = await getDotCMSPage(path); |
| 20 | + if (!pageContent) { |
| 21 | + return { |
| 22 | + title: "not found", |
| 23 | + }; |
| 24 | + } |
| 25 | + |
| 26 | + const { pageAsset } = pageContent; |
| 27 | + const page = pageAsset.page; |
| 28 | + |
| 29 | + const title = page?.friendlyName || page?.title; |
| 30 | + |
| 31 | + const description = page?.description || page?.teaser || page?.seoDescription || "dotCMS Dev Site, Documentation and Resources. Learn how to build with dotCMS"; |
| 32 | + const hostname = "https://dev.dotcms.com"; |
| 33 | + const keywords = page?.tags ? page?.tags.join(", ") : "dotcms, dotcms documentation, learn dotcms, dotcms api, dotcms dev, dotcms developer, dotcms developer documentation, dotcms developer api, dotcms developer documentation, dotcms developer api"; |
| 34 | + |
| 35 | + return { |
| 36 | + title: title, |
| 37 | + description: description, |
| 38 | + url: `${hostname}${path}`, |
| 39 | + siteName: 'dotCMS Docs', |
| 40 | + keywords: keywords, |
| 41 | + alternates: { |
| 42 | + canonical: `${hostname}${path}`, |
| 43 | + }, |
| 44 | + metadataBase: new URL(hostname), |
| 45 | + images: [{ |
| 46 | + url: `${hostname}/dA/4b13a794db115b14ce79d30850712188/1024maxw/80q/}`, |
| 47 | + width: 1200, |
| 48 | + height: 630, |
| 49 | + alt: description || title, |
| 50 | + }], |
| 51 | + locale: 'en_US', |
| 52 | + type: 'article', |
| 53 | + }; |
| 54 | + } catch (e) { |
| 55 | + console.error('Error generating metadata:', e?.message || e); |
| 56 | + return { |
| 57 | + title: "not found", |
| 58 | + }; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +export default async function Page({ params }) { |
| 63 | + const finalParams = await params; |
| 64 | + |
| 65 | + const path = finalParams?.slug?.join("/") || "/"; |
| 66 | + const pageContent = await getDotCMSPage(path); |
| 67 | + |
| 68 | + |
| 69 | + if (!pageContent) { |
| 70 | + return <ErrorPage error={{ message: "Page not found", status: 404 }} />; |
| 71 | + } |
| 72 | + |
| 73 | + const { pageAsset } = pageContent; |
| 74 | + const isBlockPage = pageAsset?.page?.contentType === "BlockPage" |
| 75 | + |
| 76 | + if (isBlockPage) { |
| 77 | + // Fetch navigation data (reuse cached nav sections instead of separate API call) |
| 78 | + const [searchData, navSections] = await Promise.all([ |
| 79 | + getSideNav(), |
| 80 | + getNavSections({ path: '/docs/nav', depth: 4, languageId: 1, ttlSeconds: 600 }) |
| 81 | + ]); |
| 82 | + |
| 83 | + // Extract the first segment of the URL to find the matching nav section |
| 84 | + const pathParts = pageAsset?.page?.url.split("/").filter(part => part.length > 0); |
| 85 | + const firstSegment = pathParts.length > 0 ? pathParts[0] : ""; |
| 86 | + |
| 87 | + // Find the nav section that matches the current page's top-level folder |
| 88 | + // e.g., for "/getting-started/back-end/setup", find the "Getting Started" section |
| 89 | + const matchingSection = navSections?.find(section => { |
| 90 | + // Normalize section title to match URL segment |
| 91 | + // e.g., "Getting Started" -> "getting-started" |
| 92 | + const normalizedTitle = section.title.toLowerCase().replace(/\s+/g, '-'); |
| 93 | + return normalizedTitle === firstSegment; |
| 94 | + }); |
| 95 | + |
| 96 | + // If no matching section found, fall back to empty array |
| 97 | + const navItems = matchingSection?.items || []; |
| 98 | + |
| 99 | + return ( |
| 100 | + <BlockPageAsset |
| 101 | + pageContent={pageContent} |
| 102 | + nav={navItems} |
| 103 | + searchItems={searchData[0]?.dotcmsdocumentationchildren || []} |
| 104 | + navSections={navSections} |
| 105 | + /> |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + return ( |
| 110 | + <PageAsset |
| 111 | + pageContent={pageContent} |
| 112 | + /> |
| 113 | + ); |
| 114 | +} |
0 commit comments