@se-studio/core-ui 1.0.90 → 1.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +44 -0
- package/dist/cmsRegistration.d.ts +41 -4
- package/dist/cmsRegistration.d.ts.map +1 -1
- package/dist/cmsRegistration.js.map +1 -1
- package/dist/components/CmsRoutesLayout.d.ts +16 -0
- package/dist/components/CmsRoutesLayout.d.ts.map +1 -0
- package/dist/components/CmsRoutesLayout.js +17 -0
- package/dist/components/CmsRoutesLayout.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/route-handlers.d.ts +72 -0
- package/dist/server/route-handlers.d.ts.map +1 -0
- package/dist/server/route-handlers.js +697 -0
- package/dist/server/route-handlers.js.map +1 -0
- package/dist/server/route-types.d.ts +38 -0
- package/dist/server/route-types.d.ts.map +1 -0
- package/dist/server/route-types.js +4 -0
- package/dist/server/route-types.js.map +1 -0
- package/dist/showcase/components/AllViewPanel.d.ts.map +1 -1
- package/dist/showcase/components/AllViewPanel.js +20 -3
- package/dist/showcase/components/AllViewPanel.js.map +1 -1
- package/dist/showcase/components/IframeHeightReporter.d.ts +10 -0
- package/dist/showcase/components/IframeHeightReporter.d.ts.map +1 -0
- package/dist/showcase/components/IframeHeightReporter.js +24 -0
- package/dist/showcase/components/IframeHeightReporter.js.map +1 -0
- package/dist/showcase/components/PreviewPanel.d.ts.map +1 -1
- package/dist/showcase/components/PreviewPanel.js +3 -4
- package/dist/showcase/components/PreviewPanel.js.map +1 -1
- package/dist/showcase/components/ScaledIframe.d.ts +3 -2
- package/dist/showcase/components/ScaledIframe.d.ts.map +1 -1
- package/dist/showcase/components/ScaledIframe.js +22 -4
- package/dist/showcase/components/ScaledIframe.js.map +1 -1
- package/dist/showcase/components/ShowcaseAllRenderPage.d.ts +1 -1
- package/dist/showcase/components/ShowcaseAllRenderPage.d.ts.map +1 -1
- package/dist/showcase/components/ShowcaseAllRenderPage.js +26 -25
- package/dist/showcase/components/ShowcaseAllRenderPage.js.map +1 -1
- package/dist/showcase/components/ShowcasePage.d.ts +4 -1
- package/dist/showcase/components/ShowcasePage.d.ts.map +1 -1
- package/dist/showcase/components/ShowcasePage.js +28 -2
- package/dist/showcase/components/ShowcasePage.js.map +1 -1
- package/dist/showcase/components/ShowcaseRenderPage.d.ts +1 -1
- package/dist/showcase/components/ShowcaseRenderPage.d.ts.map +1 -1
- package/dist/showcase/components/ShowcaseRenderPage.js +15 -8
- package/dist/showcase/components/ShowcaseRenderPage.js.map +1 -1
- package/dist/showcase/index.d.ts +1 -0
- package/dist/showcase/index.d.ts.map +1 -1
- package/dist/showcase/index.js +1 -0
- package/dist/showcase/index.js.map +1 -1
- package/dist/showcase/mergeShowcaseMocks.d.ts +34 -0
- package/dist/showcase/mergeShowcaseMocks.d.ts.map +1 -0
- package/dist/showcase/mergeShowcaseMocks.js +31 -0
- package/dist/showcase/mergeShowcaseMocks.js.map +1 -0
- package/dist/showcase/mockFactory.d.ts +9 -5
- package/dist/showcase/mockFactory.d.ts.map +1 -1
- package/dist/showcase/mockFactory.js +207 -33
- package/dist/showcase/mockFactory.js.map +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { notFound } from 'next/navigation';
|
|
3
|
+
import { CmsContent } from '../components/CmsContent';
|
|
4
|
+
import { buildPageMetadata, calculateTitleAndDescription, getLocalizedPath, } from '../utils/buildPageMetadata';
|
|
5
|
+
import { handleCmsError } from '../utils/errorHandling';
|
|
6
|
+
import { toBreadcrumbOptions } from './route-types';
|
|
7
|
+
/**
|
|
8
|
+
* Creates all generate*Page and generate*Metadata functions for CMS route handlers.
|
|
9
|
+
* This factory centralises the logic from the per-app `appShared/` directory, accepting
|
|
10
|
+
* app-specific config (layout, fetch helpers, constants) via dependency injection.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // src/lib/route-handlers.ts
|
|
15
|
+
* import { createRouteHandlers } from '@se-studio/core-ui/server';
|
|
16
|
+
* export const { generatePage, generatePageMetadata, ... } = createRouteHandlers({ ... });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function createRouteHandlers(config) {
|
|
20
|
+
const { rendererConfig, buildOptions, buildInformation, getBannersWithErrors, getPageWithErrors, getArticleWithErrors, getArticleTypeWithErrors, getTagWithErrors, getPersonWithErrors, getCustomTypeWithErrors, LayoutComponent, constants, } = config;
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Locale helpers
|
|
23
|
+
// ============================================================================
|
|
24
|
+
/** Build hreflang alternates for a path and locale. */
|
|
25
|
+
function buildLocaleAlternates(path, locale) {
|
|
26
|
+
const localeConfig = buildInformation.localeConfig;
|
|
27
|
+
if (!localeConfig) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const prefix = `/${locale}`;
|
|
31
|
+
const basePath = locale !== localeConfig.defaultLocale && path.startsWith(prefix)
|
|
32
|
+
? path.slice(prefix.length) || '/'
|
|
33
|
+
: path;
|
|
34
|
+
return Object.fromEntries(localeConfig.locales.map((loc) => [loc, getLocalizedPath(basePath, loc, localeConfig)]));
|
|
35
|
+
}
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Page
|
|
38
|
+
// ============================================================================
|
|
39
|
+
async function getPageData(slug, locale) {
|
|
40
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
41
|
+
const [pageResponse, bannersResponse] = await Promise.all([
|
|
42
|
+
getPageWithErrors(slug, options),
|
|
43
|
+
getBannersWithErrors(options),
|
|
44
|
+
]);
|
|
45
|
+
return {
|
|
46
|
+
page: pageResponse.data,
|
|
47
|
+
banners: bannersResponse.data,
|
|
48
|
+
errors: [...pageResponse.errors, ...bannersResponse.errors],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function generatePageMetadata(slug, path, routeConfig, parent, locale) {
|
|
52
|
+
const errorContext = { type: 'metadata', slug, path };
|
|
53
|
+
try {
|
|
54
|
+
const { page } = await getPageData(slug, locale);
|
|
55
|
+
if (!page) {
|
|
56
|
+
if (routeConfig.throwOnNotFound)
|
|
57
|
+
return notFound();
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
61
|
+
return buildPageMetadata(page, path, buildInformation, parent, true, localeAlternates);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (routeConfig.throwOnNotFound)
|
|
65
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function generatePage(slug, path, routeConfig, locale) {
|
|
70
|
+
const errorContext = { type: 'page', slug, path };
|
|
71
|
+
try {
|
|
72
|
+
const { page, banners, errors } = await getPageData(slug, locale);
|
|
73
|
+
if (!page?.contents?.length) {
|
|
74
|
+
if (routeConfig.throwOnNotFound)
|
|
75
|
+
return notFound();
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const analyticsContext = {
|
|
79
|
+
slug,
|
|
80
|
+
title: page.title || '',
|
|
81
|
+
type: page.type,
|
|
82
|
+
};
|
|
83
|
+
const breadcrumbOptions = toBreadcrumbOptions(routeConfig);
|
|
84
|
+
return (_jsx(LayoutComponent, { model: page, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: breadcrumbOptions, children: _jsx(CmsContent, { contents: page.contents, rendererConfig: rendererConfig, pageContext: { page }, analyticsContext: analyticsContext }) }));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (routeConfig.throwOnNotFound)
|
|
88
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Article
|
|
94
|
+
// ============================================================================
|
|
95
|
+
async function getArticleData(articleTypeSlug, slug, locale) {
|
|
96
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
97
|
+
const [articleResponse, bannersResponse] = await Promise.all([
|
|
98
|
+
getArticleWithErrors(articleTypeSlug, slug, options),
|
|
99
|
+
getBannersWithErrors(options),
|
|
100
|
+
]);
|
|
101
|
+
return {
|
|
102
|
+
article: articleResponse.data,
|
|
103
|
+
banners: bannersResponse.data,
|
|
104
|
+
errors: [...articleResponse.errors, ...bannersResponse.errors],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function generateArticleMetadata(articleTypeSlug, articleSlug, path, routeConfig, parent, locale) {
|
|
108
|
+
const errorContext = { type: 'metadata', articleTypeSlug, articleSlug, path };
|
|
109
|
+
try {
|
|
110
|
+
const { article } = await getArticleData(articleTypeSlug, articleSlug, locale);
|
|
111
|
+
if (!article) {
|
|
112
|
+
if (routeConfig.throwOnNotFound)
|
|
113
|
+
return notFound();
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
117
|
+
return buildPageMetadata(article, path, buildInformation, parent, true, localeAlternates);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (routeConfig.throwOnNotFound)
|
|
121
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function generateArticlePage(articleTypeSlug, articleSlug, path, routeConfig, locale) {
|
|
126
|
+
const errorContext = { type: 'article', articleTypeSlug, articleSlug, path };
|
|
127
|
+
try {
|
|
128
|
+
const { article, banners, errors } = await getArticleData(articleTypeSlug, articleSlug, locale);
|
|
129
|
+
if (!article || article.contentCount === 0 || !article.contents?.length) {
|
|
130
|
+
if (routeConfig.throwOnNotFound)
|
|
131
|
+
return notFound();
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
const analyticsContext = {
|
|
135
|
+
slug: path,
|
|
136
|
+
title: article.title || '',
|
|
137
|
+
type: article.type,
|
|
138
|
+
};
|
|
139
|
+
return (_jsx(LayoutComponent, { model: article, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: article.contents, rendererConfig: rendererConfig, pageContext: { article }, analyticsContext: analyticsContext }) }));
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (routeConfig.throwOnNotFound)
|
|
143
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Article Type
|
|
149
|
+
// ============================================================================
|
|
150
|
+
async function getArticleTypeData(articleTypeSlug, locale) {
|
|
151
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
152
|
+
const [articleTypeResponse, customTypeResponse, bannersResponse] = await Promise.all([
|
|
153
|
+
getArticleTypeWithErrors(articleTypeSlug, {
|
|
154
|
+
...options,
|
|
155
|
+
customType: constants.requireCustomTypeForArticleTypes
|
|
156
|
+
? constants.ARTICLES_SLUG
|
|
157
|
+
: undefined,
|
|
158
|
+
}),
|
|
159
|
+
constants.requireCustomTypeForArticleTypes
|
|
160
|
+
? getCustomTypeWithErrors(constants.ARTICLES_SLUG, options)
|
|
161
|
+
: Promise.resolve({ data: undefined, errors: [] }),
|
|
162
|
+
getBannersWithErrors(options),
|
|
163
|
+
]);
|
|
164
|
+
return {
|
|
165
|
+
articleType: articleTypeResponse.data,
|
|
166
|
+
customType: customTypeResponse.data,
|
|
167
|
+
banners: bannersResponse.data,
|
|
168
|
+
errors: [
|
|
169
|
+
...articleTypeResponse.errors,
|
|
170
|
+
...customTypeResponse.errors,
|
|
171
|
+
...bannersResponse.errors,
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function generateArticleTypeMetadata(articleTypeSlug, path, routeConfig, parent, locale) {
|
|
176
|
+
const errorContext = { type: 'metadata', articleTypeSlug, path };
|
|
177
|
+
try {
|
|
178
|
+
const { articleType, customType } = await getArticleTypeData(articleTypeSlug, locale);
|
|
179
|
+
if (!(articleType && (customType || !constants.requireCustomTypeForArticleTypes))) {
|
|
180
|
+
if (routeConfig.throwOnNotFound)
|
|
181
|
+
return notFound();
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
const { title, description } = calculateTitleAndDescription({
|
|
185
|
+
articleType: articleType,
|
|
186
|
+
customType: customType,
|
|
187
|
+
});
|
|
188
|
+
const model = {
|
|
189
|
+
indexed: articleType.indexed && (customType?.indexed ?? true),
|
|
190
|
+
featuredImage: articleType.featuredImage ?? customType?.featuredImage ?? undefined,
|
|
191
|
+
title,
|
|
192
|
+
description,
|
|
193
|
+
};
|
|
194
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
195
|
+
return buildPageMetadata(model, path, buildInformation, parent, true, localeAlternates);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (routeConfig.throwOnNotFound)
|
|
199
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function generateArticleTypePage(articleTypeSlug, path, routeConfig, locale) {
|
|
204
|
+
const errorContext = { type: 'article-type', articleTypeSlug, path };
|
|
205
|
+
try {
|
|
206
|
+
const { articleType, customType, banners, errors } = await getArticleTypeData(articleTypeSlug, locale);
|
|
207
|
+
if (!(articleType &&
|
|
208
|
+
(customType || !constants.requireCustomTypeForArticleTypes) &&
|
|
209
|
+
articleType.contents?.length)) {
|
|
210
|
+
if (routeConfig.throwOnNotFound)
|
|
211
|
+
return notFound();
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
const analyticsContext = {
|
|
215
|
+
slug: path,
|
|
216
|
+
title: articleType.title,
|
|
217
|
+
type: 'article-type-index',
|
|
218
|
+
};
|
|
219
|
+
return (_jsx(LayoutComponent, { model: articleType, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: articleType.contents, rendererConfig: rendererConfig, pageContext: { articleType, customType }, analyticsContext: analyticsContext }) }));
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (routeConfig.throwOnNotFound)
|
|
223
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// ============================================================================
|
|
228
|
+
// Article Type Tag
|
|
229
|
+
// ============================================================================
|
|
230
|
+
async function getArticleTypeTagData(articleTypeSlug, tagSlug, locale) {
|
|
231
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
232
|
+
const [articleTypeResponse, tagResponse, articleCustomTypeResponse, tagCustomTypeResponse, bannersResponse,] = await Promise.all([
|
|
233
|
+
getArticleTypeWithErrors(articleTypeSlug, {
|
|
234
|
+
...options,
|
|
235
|
+
customType: constants.articlesCustomTypeSlug,
|
|
236
|
+
}),
|
|
237
|
+
getTagWithErrors(tagSlug, { ...options, customType: constants.TAGS_SLUG }),
|
|
238
|
+
constants.articlesCustomTypeSlug
|
|
239
|
+
? getCustomTypeWithErrors(constants.articlesCustomTypeSlug, options)
|
|
240
|
+
: Promise.resolve({ data: undefined, errors: [] }),
|
|
241
|
+
getCustomTypeWithErrors(constants.TAGS_SLUG, options),
|
|
242
|
+
getBannersWithErrors(options),
|
|
243
|
+
]);
|
|
244
|
+
return {
|
|
245
|
+
articleType: articleTypeResponse.data,
|
|
246
|
+
tag: tagResponse.data,
|
|
247
|
+
articleCustomType: articleCustomTypeResponse.data,
|
|
248
|
+
tagCustomType: tagCustomTypeResponse.data,
|
|
249
|
+
banners: bannersResponse.data,
|
|
250
|
+
errors: [
|
|
251
|
+
...articleTypeResponse.errors,
|
|
252
|
+
...tagResponse.errors,
|
|
253
|
+
...articleCustomTypeResponse.errors,
|
|
254
|
+
...tagCustomTypeResponse.errors,
|
|
255
|
+
...bannersResponse.errors,
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
async function generateArticleTypeTagMetadata(articleTypeSlug, tagSlug, path, routeConfig, parent, locale) {
|
|
260
|
+
const errorContext = { type: 'metadata', articleTypeSlug, tagSlug, path };
|
|
261
|
+
try {
|
|
262
|
+
const { articleType, tag, articleCustomType, tagCustomType } = await getArticleTypeTagData(articleTypeSlug, tagSlug, locale);
|
|
263
|
+
const hasArticleCustomType = constants.articlesCustomTypeSlug ? !!articleCustomType : true;
|
|
264
|
+
if (!(articleType && tag && hasArticleCustomType && tagCustomType)) {
|
|
265
|
+
if (routeConfig.throwOnNotFound)
|
|
266
|
+
return notFound();
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
const { title, description } = calculateTitleAndDescription({
|
|
270
|
+
articleType: articleType,
|
|
271
|
+
tag: tag,
|
|
272
|
+
customType: (articleCustomType ?? tagCustomType),
|
|
273
|
+
});
|
|
274
|
+
const model = {
|
|
275
|
+
indexed: tag.indexed &&
|
|
276
|
+
articleType.indexed &&
|
|
277
|
+
(articleCustomType?.indexed ?? true) &&
|
|
278
|
+
tagCustomType.indexed,
|
|
279
|
+
featuredImage: tag.featuredImage ??
|
|
280
|
+
articleType.featuredImage ??
|
|
281
|
+
tagCustomType.featuredImage ??
|
|
282
|
+
articleCustomType?.featuredImage,
|
|
283
|
+
title,
|
|
284
|
+
description,
|
|
285
|
+
};
|
|
286
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
287
|
+
return buildPageMetadata(model, path, buildInformation, parent, undefined, localeAlternates);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
if (routeConfig.throwOnNotFound)
|
|
291
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
292
|
+
return {};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async function generateArticleTypeTagPage(articleTypeSlug, tagSlug, path, routeConfig, locale) {
|
|
296
|
+
const errorContext = { type: 'article-type-tag', articleTypeSlug, tagSlug, path };
|
|
297
|
+
try {
|
|
298
|
+
const { articleType, tag, articleCustomType, tagCustomType, banners, errors } = await getArticleTypeTagData(articleTypeSlug, tagSlug, locale);
|
|
299
|
+
const hasArticleCustomType = constants.articlesCustomTypeSlug ? !!articleCustomType : true;
|
|
300
|
+
if (!(articleType &&
|
|
301
|
+
tag &&
|
|
302
|
+
hasArticleCustomType &&
|
|
303
|
+
tagCustomType &&
|
|
304
|
+
articleType.contents?.length)) {
|
|
305
|
+
if (routeConfig.throwOnNotFound)
|
|
306
|
+
return notFound();
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
const analyticsContext = {
|
|
310
|
+
slug: path,
|
|
311
|
+
title: `${tag.title} ${articleType.title}`,
|
|
312
|
+
type: 'article-type-tag-index',
|
|
313
|
+
};
|
|
314
|
+
return (_jsx(LayoutComponent, { model: articleType, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: articleType.contents ??
|
|
315
|
+
tag.contents ??
|
|
316
|
+
articleCustomType?.contents ??
|
|
317
|
+
tagCustomType.contents, rendererConfig: rendererConfig, pageContext: { articleType, tag, customType: articleCustomType ?? tagCustomType }, analyticsContext: analyticsContext }) }));
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (routeConfig.throwOnNotFound)
|
|
321
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// ============================================================================
|
|
326
|
+
// Article Types Index (uses ARTICLES_SLUG custom type)
|
|
327
|
+
// ============================================================================
|
|
328
|
+
async function getArticleTypesIndexData(locale) {
|
|
329
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
330
|
+
const response = await getCustomTypeWithErrors(constants.ARTICLES_SLUG, options);
|
|
331
|
+
return { customType: response.data, errors: response.errors };
|
|
332
|
+
}
|
|
333
|
+
async function generateArticleTypesIndexMetadata(path, routeConfig, parent, locale) {
|
|
334
|
+
const errorContext = { type: 'metadata', path };
|
|
335
|
+
try {
|
|
336
|
+
const { customType } = await getArticleTypesIndexData(locale);
|
|
337
|
+
if (!customType) {
|
|
338
|
+
if (routeConfig.throwOnNotFound)
|
|
339
|
+
return notFound();
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
const localeAlternates = locale ? buildLocaleAlternates(`${path}/`, locale) : undefined;
|
|
343
|
+
return buildPageMetadata(customType, `${path}/`, buildInformation, parent, undefined, localeAlternates);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
if (routeConfig.throwOnNotFound)
|
|
347
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
348
|
+
return {};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function generateArticleTypesIndexPage(path, routeConfig, locale) {
|
|
352
|
+
const errorContext = { type: 'customType', path };
|
|
353
|
+
try {
|
|
354
|
+
const { customType, errors } = await getArticleTypesIndexData(locale);
|
|
355
|
+
if (!customType?.contents?.length) {
|
|
356
|
+
if (routeConfig.throwOnNotFound)
|
|
357
|
+
return notFound();
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
const { title, description } = calculateTitleAndDescription({
|
|
361
|
+
customType: customType,
|
|
362
|
+
});
|
|
363
|
+
const analyticsContext = {
|
|
364
|
+
slug: constants.ARTICLES_SLUG,
|
|
365
|
+
title: customType.title,
|
|
366
|
+
type: 'article-types-index',
|
|
367
|
+
};
|
|
368
|
+
const model = { ...customType, title, description };
|
|
369
|
+
return (_jsx(LayoutComponent, { model: model, analyticsContext: analyticsContext, errors: errors, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: customType.contents, rendererConfig: rendererConfig, pageContext: { customType }, analyticsContext: analyticsContext }) }));
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
if (routeConfig.throwOnNotFound)
|
|
373
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// ============================================================================
|
|
378
|
+
// Tag
|
|
379
|
+
// ============================================================================
|
|
380
|
+
async function getTagData(topic, locale) {
|
|
381
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
382
|
+
const [tagResponse, customTypeResponse, bannersResponse] = await Promise.all([
|
|
383
|
+
getTagWithErrors(topic, { ...options, customType: constants.TAGS_SLUG }),
|
|
384
|
+
getCustomTypeWithErrors(constants.TAGS_SLUG, options),
|
|
385
|
+
getBannersWithErrors(options),
|
|
386
|
+
]);
|
|
387
|
+
return {
|
|
388
|
+
tag: tagResponse.data,
|
|
389
|
+
customType: customTypeResponse.data,
|
|
390
|
+
banners: bannersResponse.data,
|
|
391
|
+
errors: [...tagResponse.errors, ...customTypeResponse.errors, ...bannersResponse.errors],
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
async function generateTagMetadata(tagSlug, path, routeConfig, parent, locale) {
|
|
395
|
+
if (!constants.enableTag)
|
|
396
|
+
return {};
|
|
397
|
+
const errorContext = { type: 'metadata', tag: tagSlug, path };
|
|
398
|
+
try {
|
|
399
|
+
const { tag, customType } = await getTagData(tagSlug, locale);
|
|
400
|
+
if (!(tag && customType)) {
|
|
401
|
+
if (routeConfig.throwOnNotFound)
|
|
402
|
+
return notFound();
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
const { title, description } = calculateTitleAndDescription({
|
|
406
|
+
tag: tag,
|
|
407
|
+
customType: customType,
|
|
408
|
+
});
|
|
409
|
+
const model = {
|
|
410
|
+
indexed: tag.indexed && customType.indexed,
|
|
411
|
+
featuredImage: tag.featuredImage ?? customType.featuredImage,
|
|
412
|
+
title,
|
|
413
|
+
description,
|
|
414
|
+
};
|
|
415
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
416
|
+
return buildPageMetadata(model, path, buildInformation, parent, undefined, localeAlternates);
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
if (routeConfig.throwOnNotFound)
|
|
420
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
421
|
+
return {};
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async function generateTagPage(tagSlug, path, routeConfig, locale) {
|
|
425
|
+
if (!constants.enableTag)
|
|
426
|
+
return notFound();
|
|
427
|
+
const errorContext = { type: 'tag', tag: tagSlug, path };
|
|
428
|
+
try {
|
|
429
|
+
const { tag, customType, banners, errors } = await getTagData(tagSlug, locale);
|
|
430
|
+
if (!(tag && customType && tag.contents?.length)) {
|
|
431
|
+
if (routeConfig.throwOnNotFound)
|
|
432
|
+
return notFound();
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
const analyticsContext = {
|
|
436
|
+
slug: path,
|
|
437
|
+
title: tag.title,
|
|
438
|
+
type: 'tag-index',
|
|
439
|
+
};
|
|
440
|
+
return (_jsx(LayoutComponent, { model: tag, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: tag.contents, rendererConfig: rendererConfig, pageContext: { tag, customType }, analyticsContext: analyticsContext }) }));
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
if (routeConfig.throwOnNotFound)
|
|
444
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
// ============================================================================
|
|
449
|
+
// Tags Index (uses TAGS_SLUG custom type)
|
|
450
|
+
// ============================================================================
|
|
451
|
+
async function getTagsIndexData(locale) {
|
|
452
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
453
|
+
const response = await getCustomTypeWithErrors(constants.TAGS_SLUG, options);
|
|
454
|
+
return { customType: response.data, errors: response.errors };
|
|
455
|
+
}
|
|
456
|
+
async function generateTagsIndexMetadata(path, routeConfig, parent, locale) {
|
|
457
|
+
if (!constants.enableTagsIndex)
|
|
458
|
+
return {};
|
|
459
|
+
const errorContext = { type: 'metadata', path };
|
|
460
|
+
try {
|
|
461
|
+
const { customType } = await getTagsIndexData(locale);
|
|
462
|
+
if (!customType) {
|
|
463
|
+
if (routeConfig.throwOnNotFound)
|
|
464
|
+
return notFound();
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
const localeAlternates = locale ? buildLocaleAlternates(`${path}/`, locale) : undefined;
|
|
468
|
+
return buildPageMetadata(customType, `${path}/`, buildInformation, parent, undefined, localeAlternates);
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
if (routeConfig.throwOnNotFound)
|
|
472
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
473
|
+
return {};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async function generateTagsIndexPage(path, routeConfig, locale) {
|
|
477
|
+
if (!constants.enableTagsIndex)
|
|
478
|
+
return notFound();
|
|
479
|
+
const errorContext = { type: 'customType', path };
|
|
480
|
+
try {
|
|
481
|
+
const { customType, errors } = await getTagsIndexData(locale);
|
|
482
|
+
if (!customType?.contents?.length) {
|
|
483
|
+
if (routeConfig.throwOnNotFound)
|
|
484
|
+
return notFound();
|
|
485
|
+
return undefined;
|
|
486
|
+
}
|
|
487
|
+
const analyticsContext = {
|
|
488
|
+
slug: constants.TAGS_SLUG,
|
|
489
|
+
title: customType.title,
|
|
490
|
+
type: 'tags-index',
|
|
491
|
+
};
|
|
492
|
+
const model = { ...customType };
|
|
493
|
+
return (_jsx(LayoutComponent, { model: model, analyticsContext: analyticsContext, errors: errors, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: customType.contents, rendererConfig: rendererConfig, pageContext: { customType }, analyticsContext: analyticsContext }) }));
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
if (routeConfig.throwOnNotFound)
|
|
497
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// ============================================================================
|
|
502
|
+
// Person
|
|
503
|
+
// ============================================================================
|
|
504
|
+
async function getPersonData(slug, locale) {
|
|
505
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
506
|
+
const [personResponse, customTypeResponse, bannersResponse] = await Promise.all([
|
|
507
|
+
getPersonWithErrors(slug, { ...options, customType: constants.PEOPLE_SLUG }),
|
|
508
|
+
getCustomTypeWithErrors(constants.PEOPLE_SLUG, options),
|
|
509
|
+
getBannersWithErrors(options),
|
|
510
|
+
]);
|
|
511
|
+
return {
|
|
512
|
+
person: personResponse.data,
|
|
513
|
+
customType: customTypeResponse.data,
|
|
514
|
+
banners: bannersResponse.data,
|
|
515
|
+
errors: [...personResponse.errors, ...customTypeResponse.errors, ...bannersResponse.errors],
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
async function generatePersonMetadata(personSlug, path, routeConfig, parent, locale) {
|
|
519
|
+
const errorContext = { type: 'metadata', person: personSlug, path };
|
|
520
|
+
try {
|
|
521
|
+
const { person, customType } = await getPersonData(personSlug, locale);
|
|
522
|
+
if (!(person && customType)) {
|
|
523
|
+
if (routeConfig.throwOnNotFound)
|
|
524
|
+
return notFound();
|
|
525
|
+
return undefined;
|
|
526
|
+
}
|
|
527
|
+
const { title, description } = calculateTitleAndDescription({
|
|
528
|
+
person: person,
|
|
529
|
+
customType: customType,
|
|
530
|
+
});
|
|
531
|
+
const model = {
|
|
532
|
+
indexed: person.indexed && customType.indexed,
|
|
533
|
+
featuredImage: person.featuredImage ?? customType.featuredImage,
|
|
534
|
+
title,
|
|
535
|
+
description,
|
|
536
|
+
};
|
|
537
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
538
|
+
return buildPageMetadata(model, path, buildInformation, parent, constants.enablePerson, localeAlternates);
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
if (routeConfig.throwOnNotFound)
|
|
542
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
543
|
+
return {};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
async function generatePersonPage(personSlug, path, routeConfig, locale) {
|
|
547
|
+
const errorContext = { type: 'person', person: personSlug, path };
|
|
548
|
+
try {
|
|
549
|
+
const { person, customType, banners, errors } = await getPersonData(personSlug, locale);
|
|
550
|
+
if (!(person && customType)) {
|
|
551
|
+
if (routeConfig.throwOnNotFound)
|
|
552
|
+
return notFound();
|
|
553
|
+
return undefined;
|
|
554
|
+
}
|
|
555
|
+
const analyticsContext = {
|
|
556
|
+
slug: path,
|
|
557
|
+
title: person.title,
|
|
558
|
+
type: 'person',
|
|
559
|
+
};
|
|
560
|
+
return (_jsx(LayoutComponent, { model: person, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: person.contents, rendererConfig: rendererConfig, pageContext: { person, customType }, analyticsContext: analyticsContext }) }));
|
|
561
|
+
}
|
|
562
|
+
catch (error) {
|
|
563
|
+
if (routeConfig.throwOnNotFound)
|
|
564
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
// ============================================================================
|
|
569
|
+
// Team Index (uses PEOPLE_SLUG custom type)
|
|
570
|
+
// ============================================================================
|
|
571
|
+
async function getTeamIndexData(locale) {
|
|
572
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
573
|
+
const response = await getCustomTypeWithErrors(constants.PEOPLE_SLUG, options);
|
|
574
|
+
return { customType: response.data, errors: response.errors };
|
|
575
|
+
}
|
|
576
|
+
async function generateTeamIndexMetadata(path, routeConfig, parent, locale) {
|
|
577
|
+
const errorContext = { type: 'metadata', path };
|
|
578
|
+
try {
|
|
579
|
+
const { customType } = await getTeamIndexData(locale);
|
|
580
|
+
if (!customType) {
|
|
581
|
+
if (routeConfig.throwOnNotFound)
|
|
582
|
+
return notFound();
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
const localeAlternates = locale ? buildLocaleAlternates(`${path}/`, locale) : undefined;
|
|
586
|
+
return buildPageMetadata(customType, `${path}/`, buildInformation, parent, undefined, localeAlternates);
|
|
587
|
+
}
|
|
588
|
+
catch (error) {
|
|
589
|
+
if (routeConfig.throwOnNotFound)
|
|
590
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
591
|
+
return {};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
async function generateTeamIndexPage(path, routeConfig, locale) {
|
|
595
|
+
const errorContext = { type: 'customType', path };
|
|
596
|
+
try {
|
|
597
|
+
const { customType, errors } = await getTeamIndexData(locale);
|
|
598
|
+
if (!customType?.contents?.length) {
|
|
599
|
+
if (routeConfig.throwOnNotFound)
|
|
600
|
+
return notFound();
|
|
601
|
+
return undefined;
|
|
602
|
+
}
|
|
603
|
+
const analyticsContext = {
|
|
604
|
+
slug: constants.PEOPLE_SLUG,
|
|
605
|
+
title: customType.title,
|
|
606
|
+
type: 'team-index',
|
|
607
|
+
};
|
|
608
|
+
const model = { ...customType };
|
|
609
|
+
return (_jsx(LayoutComponent, { model: model, analyticsContext: analyticsContext, errors: errors, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: customType.contents, rendererConfig: rendererConfig, pageContext: { customType }, analyticsContext: analyticsContext }) }));
|
|
610
|
+
}
|
|
611
|
+
catch (error) {
|
|
612
|
+
if (routeConfig.throwOnNotFound)
|
|
613
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
614
|
+
return undefined;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// ============================================================================
|
|
618
|
+
// Custom Type (generic page backed by a custom type slug)
|
|
619
|
+
// ============================================================================
|
|
620
|
+
async function getCustomTypePageData(customTypeSlug, locale) {
|
|
621
|
+
const options = buildOptions(locale ? { locale } : undefined);
|
|
622
|
+
const [customTypeResponse, bannersResponse] = await Promise.all([
|
|
623
|
+
getCustomTypeWithErrors(customTypeSlug, options),
|
|
624
|
+
getBannersWithErrors(options),
|
|
625
|
+
]);
|
|
626
|
+
return {
|
|
627
|
+
customType: customTypeResponse.data,
|
|
628
|
+
banners: bannersResponse.data,
|
|
629
|
+
errors: [...customTypeResponse.errors, ...bannersResponse.errors],
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
async function generateCustomTypeMetadata(customTypeSlug, path, routeConfig, parent, locale) {
|
|
633
|
+
const errorContext = { type: 'metadata', customTypeSlug, path };
|
|
634
|
+
try {
|
|
635
|
+
const { customType } = await getCustomTypePageData(customTypeSlug, locale);
|
|
636
|
+
if (!customType) {
|
|
637
|
+
if (routeConfig.throwOnNotFound)
|
|
638
|
+
return notFound();
|
|
639
|
+
return undefined;
|
|
640
|
+
}
|
|
641
|
+
const localeAlternates = locale ? buildLocaleAlternates(path, locale) : undefined;
|
|
642
|
+
return buildPageMetadata(customType, path, buildInformation, parent, undefined, localeAlternates);
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
if (routeConfig.throwOnNotFound)
|
|
646
|
+
handleCmsError(error, errorContext, buildInformation);
|
|
647
|
+
return {};
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
async function generateCustomTypePage(customTypeSlug, path, routeConfig, locale) {
|
|
651
|
+
const errorContext = { type: 'customType', customTypeSlug, path };
|
|
652
|
+
try {
|
|
653
|
+
const { customType, banners, errors } = await getCustomTypePageData(customTypeSlug, locale);
|
|
654
|
+
if (!customType) {
|
|
655
|
+
if (routeConfig.throwOnNotFound)
|
|
656
|
+
return notFound();
|
|
657
|
+
return undefined;
|
|
658
|
+
}
|
|
659
|
+
const analyticsContext = {
|
|
660
|
+
slug: path,
|
|
661
|
+
title: customType.title,
|
|
662
|
+
type: 'custom-type-index',
|
|
663
|
+
};
|
|
664
|
+
return (_jsx(LayoutComponent, { model: customType, analyticsContext: analyticsContext, errors: errors, banners: banners, previewHelpers: rendererConfig.previewHelpers, breadcrumbOptions: toBreadcrumbOptions(routeConfig), children: _jsx(CmsContent, { contents: customType.contents, rendererConfig: rendererConfig, pageContext: { customType }, analyticsContext: analyticsContext }) }));
|
|
665
|
+
}
|
|
666
|
+
catch (error) {
|
|
667
|
+
if (routeConfig.throwOnNotFound)
|
|
668
|
+
return handleCmsError(error, errorContext, buildInformation);
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
// ============================================================================
|
|
673
|
+
return {
|
|
674
|
+
buildLocaleAlternates,
|
|
675
|
+
generatePage,
|
|
676
|
+
generatePageMetadata,
|
|
677
|
+
generateArticlePage,
|
|
678
|
+
generateArticleMetadata,
|
|
679
|
+
generateArticleTypePage,
|
|
680
|
+
generateArticleTypeMetadata,
|
|
681
|
+
generateArticleTypeTagPage,
|
|
682
|
+
generateArticleTypeTagMetadata,
|
|
683
|
+
generateArticleTypesIndexPage,
|
|
684
|
+
generateArticleTypesIndexMetadata,
|
|
685
|
+
generateTagPage,
|
|
686
|
+
generateTagMetadata,
|
|
687
|
+
generateTagsIndexPage,
|
|
688
|
+
generateTagsIndexMetadata,
|
|
689
|
+
generatePersonPage,
|
|
690
|
+
generatePersonMetadata,
|
|
691
|
+
generateTeamIndexPage,
|
|
692
|
+
generateTeamIndexMetadata,
|
|
693
|
+
generateCustomTypePage,
|
|
694
|
+
generateCustomTypeMetadata,
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
//# sourceMappingURL=route-handlers.js.map
|