@prezly/theme-kit-nextjs 1.18.2 → 2.0.0-1
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/build/@types/global.d.js +1 -0
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js +27 -23
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +37 -25
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/index.js +2 -8
- package/build/adapter-nextjs/api-handlers/index.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +16 -15
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +15 -15
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/index.js +6 -23
- package/build/adapter-nextjs/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.d.ts +2 -2
- package/build/adapter-nextjs/page-props/category.js +118 -100
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +87 -68
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +64 -53
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.d.ts +2 -2
- package/build/adapter-nextjs/page-props/home.js +83 -69
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/index.js +8 -42
- package/build/adapter-nextjs/page-props/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/lib/types.js +1 -3
- package/build/adapter-nextjs/page-props/search.js +25 -31
- package/build/adapter-nextjs/page-props/search.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +29 -50
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js +13 -19
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +33 -35
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/index.js +4 -25
- package/build/adapter-nextjs/page-props/sitemap/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/types.js +1 -3
- package/build/adapter-nextjs/page-props/story.js +77 -64
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +27 -26
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +34 -25
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/adapter-nextjs/processStaticRequest.js +19 -16
- package/build/adapter-nextjs/processStaticRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +84 -78
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/index.js +2 -21
- package/build/components-nextjs/PageSeo/index.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +5 -10
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/types.js +1 -3
- package/build/components-nextjs/StorySeo/StorySeo.js +69 -47
- package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/components-nextjs/StorySeo/index.js +1 -6
- package/build/components-nextjs/StorySeo/index.js.map +1 -1
- package/build/components-nextjs/document.js +31 -48
- package/build/components-nextjs/document.js.map +1 -1
- package/build/components-nextjs/index.js +3 -10
- package/build/components-nextjs/index.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +4 -5
- package/build/data-fetching/api/PrezlyApi.js +207 -192
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +21 -21
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/index.js +1 -18
- package/build/data-fetching/api/index.js.map +1 -1
- package/build/data-fetching/api/queries.js +76 -47
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/index.js +3 -20
- package/build/data-fetching/index.js.map +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.js +22 -22
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +35 -38
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/data-fetching/lib/index.js +4 -12
- package/build/data-fetching/lib/index.js.map +1 -1
- package/build/data-fetching/lib/isSdkError.js +3 -8
- package/build/data-fetching/lib/isSdkError.js.map +1 -1
- package/build/data-fetching/lib/isUuid.js +3 -8
- package/build/data-fetching/lib/isUuid.js.map +1 -1
- package/build/data-fetching/types.js +1 -3
- package/build/index.js +9 -26
- package/build/index.js.map +1 -1
- package/build/infinite-loading/index.js +4 -25
- package/build/infinite-loading/index.js.map +1 -1
- package/build/infinite-loading/types.js +1 -3
- package/build/infinite-loading/useInfiniteGalleriesLoading.js +42 -37
- package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +50 -43
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.d.ts +2 -2
- package/build/infinite-loading/useInfiniteStoriesLoading.js +56 -50
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/index.d.ts +1 -1
- package/build/intl/index.js +4 -26
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.d.ts +1 -1
- package/build/intl/languages.js +146 -122
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.js +52 -107
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.d.ts +1 -2
- package/build/intl/localeConfig.js +7 -14
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeList.d.ts +4 -2
- package/build/intl/localeList.js +1 -109
- package/build/intl/localeList.js.map +1 -1
- package/build/intl/localeObject.js +80 -82
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.js +35 -25
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/index.js +11 -28
- package/build/newsroom-context/hooks/index.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +5 -10
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.js +5 -10
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +5 -10
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.js +5 -10
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +5 -10
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.js +5 -10
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +17 -21
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +52 -55
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +5 -10
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +5 -10
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.js +11 -16
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/newsroom-context/index.js +2 -22
- package/build/newsroom-context/index.js.map +1 -1
- package/build/sentry/client.js +4 -9
- package/build/sentry/client.js.map +1 -1
- package/build/sentry/common.js +26 -29
- package/build/sentry/common.js.map +1 -1
- package/build/sentry/index.js +2 -8
- package/build/sentry/index.js.map +1 -1
- package/build/sentry/server.js +4 -9
- package/build/sentry/server.js.map +1 -1
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -3
- package/build/utils/boilerplate.js +7 -22
- package/build/utils/boilerplate.js.map +1 -1
- package/build/utils/constants.js +3 -7
- package/build/utils/constants.js.map +1 -1
- package/build/utils/getAssetsUrl.js +4 -9
- package/build/utils/getAssetsUrl.js.map +1 -1
- package/build/utils/getDataRequestLink.js +6 -12
- package/build/utils/getDataRequestLink.js.map +1 -1
- package/build/utils/getLocalizedCategoryData.js +33 -33
- package/build/utils/getLocalizedCategoryData.js.map +1 -1
- package/build/utils/getNewsroomLogoUrl.js +15 -21
- package/build/utils/getNewsroomLogoUrl.js.map +1 -1
- package/build/utils/getPrivacyPortalUrl.js +11 -13
- package/build/utils/getPrivacyPortalUrl.js.map +1 -1
- package/build/utils/getStoryPublicationDate.js +9 -14
- package/build/utils/getStoryPublicationDate.js.map +1 -1
- package/build/utils/getUploadcareGroupUrl.js +5 -10
- package/build/utils/getUploadcareGroupUrl.js.map +1 -1
- package/build/utils/index.js +10 -27
- package/build/utils/index.js.map +1 -1
- package/build/utils/isEmbargoStory.js +3 -8
- package/build/utils/isEmbargoStory.js.map +1 -1
- package/package.json +26 -18
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/@types/global.d.ts +0 -7
- package/src/__mocks__/languages.ts +0 -417
- package/src/__mocks__/story.ts +0 -351
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -26
- package/src/adapter-nextjs/api-handlers/index.ts +0 -2
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +0 -29
- package/src/adapter-nextjs/getNewsroomStaticProps.ts +0 -29
- package/src/adapter-nextjs/index.ts +0 -6
- package/src/adapter-nextjs/page-props/category.ts +0 -157
- package/src/adapter-nextjs/page-props/gallery.ts +0 -114
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +0 -89
- package/src/adapter-nextjs/page-props/home.ts +0 -113
- package/src/adapter-nextjs/page-props/index.ts +0 -26
- package/src/adapter-nextjs/page-props/lib/types.ts +0 -8
- package/src/adapter-nextjs/page-props/search.ts +0 -53
- package/src/adapter-nextjs/page-props/sitemap/SitemapBuilder.ts +0 -56
- package/src/adapter-nextjs/page-props/sitemap/createPaths.ts +0 -21
- package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +0 -43
- package/src/adapter-nextjs/page-props/sitemap/index.ts +0 -5
- package/src/adapter-nextjs/page-props/sitemap/types.ts +0 -5
- package/src/adapter-nextjs/page-props/story.ts +0 -94
- package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
- package/src/adapter-nextjs/processRequest.ts +0 -49
- package/src/adapter-nextjs/processStaticRequest.ts +0 -32
- package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -131
- package/src/components-nextjs/PageSeo/index.ts +0 -2
- package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
- package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
- package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -80
- package/src/components-nextjs/StorySeo/index.ts +0 -1
- package/src/components-nextjs/document.tsx +0 -38
- package/src/components-nextjs/index.ts +0 -3
- package/src/data-fetching/api/PrezlyApi.ts +0 -302
- package/src/data-fetching/api/getPrezlyApi.ts +0 -24
- package/src/data-fetching/api/index.ts +0 -1
- package/src/data-fetching/api/queries.ts +0 -51
- package/src/data-fetching/index.ts +0 -3
- package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
- package/src/data-fetching/lib/getEnvVariables.ts +0 -46
- package/src/data-fetching/lib/index.ts +0 -4
- package/src/data-fetching/lib/isSdkError.ts +0 -5
- package/src/data-fetching/lib/isUuid.ts +0 -5
- package/src/data-fetching/types.ts +0 -14
- package/src/index.ts +0 -9
- package/src/infinite-loading/index.ts +0 -4
- package/src/infinite-loading/types.ts +0 -5
- package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -53
- package/src/infinite-loading/useInfiniteLoading.ts +0 -66
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -81
- package/src/intl/index.ts +0 -4
- package/src/intl/languages.test.ts +0 -232
- package/src/intl/languages.ts +0 -233
- package/src/intl/locale.test.ts +0 -94
- package/src/intl/locale.ts +0 -140
- package/src/intl/localeConfig.js +0 -23
- package/src/intl/localeList.js +0 -110
- package/src/intl/localeObject.test.ts +0 -81
- package/src/intl/localeObject.ts +0 -99
- package/src/newsroom-context/context.tsx +0 -115
- package/src/newsroom-context/hooks/index.ts +0 -11
- package/src/newsroom-context/hooks/useAlgoliaSettings.ts +0 -7
- package/src/newsroom-context/hooks/useCategories.ts +0 -7
- package/src/newsroom-context/hooks/useCompanyInformation.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentCategory.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentLocale.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentStory.ts +0 -7
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +0 -37
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -96
- package/src/newsroom-context/hooks/useLanguages.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroom.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroomContext.ts +0 -15
- package/src/newsroom-context/index.ts +0 -2
- package/src/sentry/client.ts +0 -7
- package/src/sentry/common.ts +0 -27
- package/src/sentry/index.ts +0 -2
- package/src/sentry/server.ts +0 -7
- package/src/types.ts +0 -51
- package/src/utils/boilerplate.ts +0 -27
- package/src/utils/constants.ts +0 -3
- package/src/utils/getAssetsUrl.test.ts +0 -9
- package/src/utils/getAssetsUrl.ts +0 -9
- package/src/utils/getDataRequestLink.ts +0 -14
- package/src/utils/getLocalizedCategoryData.ts +0 -47
- package/src/utils/getNewsroomLogoUrl.ts +0 -22
- package/src/utils/getPrivacyPortalUrl.ts +0 -25
- package/src/utils/getStoryPublicationDate.tsx +0 -15
- package/src/utils/getUploadcareGroupUrl.ts +0 -13
- package/src/utils/index.ts +0 -10
- package/src/utils/isEmbargoStory.ts +0 -10
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { NewsroomGallery } from '@prezly/sdk';
|
|
2
|
-
import type {
|
|
3
|
-
GetServerSidePropsContext,
|
|
4
|
-
GetServerSidePropsResult,
|
|
5
|
-
GetStaticPropsContext,
|
|
6
|
-
GetStaticPropsResult,
|
|
7
|
-
} from 'next';
|
|
8
|
-
|
|
9
|
-
import type { PaginationProps } from '../../infinite-loading/types';
|
|
10
|
-
import { DEFAULT_GALLERY_PAGE_SIZE } from '../../utils';
|
|
11
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
12
|
-
import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
|
|
13
|
-
import { processRequest } from '../processRequest';
|
|
14
|
-
import { processStaticRequest } from '../processStaticRequest';
|
|
15
|
-
|
|
16
|
-
import type { PropsFunction } from './lib/types';
|
|
17
|
-
|
|
18
|
-
export interface GalleryPageProps {
|
|
19
|
-
galleries: NewsroomGallery[];
|
|
20
|
-
pagination: PaginationProps;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface Options {
|
|
24
|
-
pageSize?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getGalleryPageServerSideProps<CustomProps extends Record<string, any>>(
|
|
28
|
-
customProps: CustomProps | PropsFunction<CustomProps>,
|
|
29
|
-
options?: Options,
|
|
30
|
-
) {
|
|
31
|
-
const { pageSize = DEFAULT_GALLERY_PAGE_SIZE } = options || {};
|
|
32
|
-
|
|
33
|
-
return async function getServerSideProps(
|
|
34
|
-
context: GetServerSidePropsContext,
|
|
35
|
-
): Promise<GetServerSidePropsResult<GalleryPageProps & CustomProps>> {
|
|
36
|
-
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
37
|
-
const { query } = context;
|
|
38
|
-
|
|
39
|
-
const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
|
|
40
|
-
const { galleries, pagination } = await api.getGalleries({ page, pageSize });
|
|
41
|
-
|
|
42
|
-
// If there's only one gallery, redirect to it immediately
|
|
43
|
-
if (galleries.length === 1) {
|
|
44
|
-
const { uuid } = galleries[0];
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
redirect: {
|
|
48
|
-
destination: `/media/album/${uuid}`,
|
|
49
|
-
permanent: false,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return processRequest(
|
|
55
|
-
context,
|
|
56
|
-
{
|
|
57
|
-
...serverSideProps,
|
|
58
|
-
galleries,
|
|
59
|
-
pagination: {
|
|
60
|
-
itemsTotal: pagination.matched_records_number,
|
|
61
|
-
currentPage: page ?? 1,
|
|
62
|
-
pageSize,
|
|
63
|
-
},
|
|
64
|
-
...(typeof customProps === 'function'
|
|
65
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
66
|
-
: customProps),
|
|
67
|
-
},
|
|
68
|
-
'/media',
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function getGalleryPageStaticProps<CustomProps extends Record<string, any>>(
|
|
74
|
-
customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
|
|
75
|
-
options?: Options,
|
|
76
|
-
) {
|
|
77
|
-
const { pageSize = DEFAULT_GALLERY_PAGE_SIZE } = options || {};
|
|
78
|
-
|
|
79
|
-
return async function getStaticProps(
|
|
80
|
-
context: GetStaticPropsContext,
|
|
81
|
-
): Promise<GetStaticPropsResult<GalleryPageProps & CustomProps>> {
|
|
82
|
-
const { api, staticProps } = await getNewsroomStaticProps(context);
|
|
83
|
-
|
|
84
|
-
const { galleries, pagination } = await api.getGalleries({ pageSize });
|
|
85
|
-
|
|
86
|
-
// If there's only one gallery, redirect to it immediately
|
|
87
|
-
if (galleries.length === 1) {
|
|
88
|
-
const { uuid } = galleries[0];
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
redirect: {
|
|
92
|
-
destination: `/media/album/${uuid}`,
|
|
93
|
-
permanent: false,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return processStaticRequest(context, {
|
|
99
|
-
...staticProps,
|
|
100
|
-
galleries,
|
|
101
|
-
pagination: {
|
|
102
|
-
itemsTotal: pagination.matched_records_number,
|
|
103
|
-
currentPage: 1,
|
|
104
|
-
pageSize,
|
|
105
|
-
},
|
|
106
|
-
...(typeof customProps === 'function'
|
|
107
|
-
? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
|
|
108
|
-
context,
|
|
109
|
-
staticProps,
|
|
110
|
-
)
|
|
111
|
-
: customProps),
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { NewsroomGallery } from '@prezly/sdk';
|
|
2
|
-
import type {
|
|
3
|
-
GetServerSidePropsContext,
|
|
4
|
-
GetServerSidePropsResult,
|
|
5
|
-
GetStaticPathsResult,
|
|
6
|
-
GetStaticPropsContext,
|
|
7
|
-
GetStaticPropsResult,
|
|
8
|
-
} from 'next';
|
|
9
|
-
|
|
10
|
-
import { getPrezlyApi } from '../../data-fetching';
|
|
11
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
12
|
-
import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
|
|
13
|
-
import { processRequest } from '../processRequest';
|
|
14
|
-
import { processStaticRequest } from '../processStaticRequest';
|
|
15
|
-
|
|
16
|
-
import type { PropsFunction } from './lib/types';
|
|
17
|
-
|
|
18
|
-
export interface GalleryAlbumPageProps {
|
|
19
|
-
gallery: NewsroomGallery;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getGalleryAlbumPageServerSideProps<CustomProps extends Record<string, any>>(
|
|
23
|
-
customProps: CustomProps | PropsFunction<CustomProps>,
|
|
24
|
-
) {
|
|
25
|
-
return async function getServerSideProps(
|
|
26
|
-
context: GetServerSidePropsContext,
|
|
27
|
-
): Promise<GetServerSidePropsResult<GalleryAlbumPageProps & CustomProps>> {
|
|
28
|
-
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
29
|
-
|
|
30
|
-
const { uuid } = context.params as { uuid: string };
|
|
31
|
-
const gallery = await api.getGallery(uuid);
|
|
32
|
-
|
|
33
|
-
if (!gallery || !gallery.images_number) {
|
|
34
|
-
return { notFound: true };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return processRequest(
|
|
38
|
-
context,
|
|
39
|
-
{
|
|
40
|
-
...serverSideProps,
|
|
41
|
-
gallery,
|
|
42
|
-
...(typeof customProps === 'function'
|
|
43
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
44
|
-
: customProps),
|
|
45
|
-
},
|
|
46
|
-
`/media/album/${uuid}`,
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getGalleryAlbumPageStaticProps<CustomProps extends Record<string, any>>(
|
|
52
|
-
customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
|
|
53
|
-
) {
|
|
54
|
-
return async function getStaticProps(
|
|
55
|
-
context: GetStaticPropsContext,
|
|
56
|
-
): Promise<GetStaticPropsResult<GalleryAlbumPageProps & CustomProps>> {
|
|
57
|
-
const { api, staticProps } = await getNewsroomStaticProps(context);
|
|
58
|
-
|
|
59
|
-
const { uuid } = context.params as { uuid: string };
|
|
60
|
-
const gallery = await api.getGallery(uuid);
|
|
61
|
-
|
|
62
|
-
if (!gallery || !gallery.images_number) {
|
|
63
|
-
return { notFound: true };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return processStaticRequest(context, {
|
|
67
|
-
...staticProps,
|
|
68
|
-
gallery,
|
|
69
|
-
...(typeof customProps === 'function'
|
|
70
|
-
? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
|
|
71
|
-
context,
|
|
72
|
-
staticProps,
|
|
73
|
-
)
|
|
74
|
-
: customProps),
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function getGalleryAlbumPageStaticPaths(): Promise<GetStaticPathsResult> {
|
|
80
|
-
const api = getPrezlyApi();
|
|
81
|
-
const { galleries } = await api.getGalleries({});
|
|
82
|
-
|
|
83
|
-
const paths = galleries.map(({ uuid }) => ({ params: { uuid } }));
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
paths,
|
|
87
|
-
fallback: 'blocking',
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { ExtraStoryFields, Story } from '@prezly/sdk';
|
|
2
|
-
import type {
|
|
3
|
-
GetServerSidePropsContext,
|
|
4
|
-
GetServerSidePropsResult,
|
|
5
|
-
GetStaticPropsContext,
|
|
6
|
-
GetStaticPropsResult,
|
|
7
|
-
} from 'next';
|
|
8
|
-
|
|
9
|
-
import type { PaginationProps } from '../../infinite-loading/types';
|
|
10
|
-
import { DEFAULT_PAGE_SIZE } from '../../utils';
|
|
11
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
12
|
-
import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
|
|
13
|
-
import { processRequest } from '../processRequest';
|
|
14
|
-
import { processStaticRequest } from '../processStaticRequest';
|
|
15
|
-
|
|
16
|
-
import type { PropsFunction } from './lib/types';
|
|
17
|
-
|
|
18
|
-
export interface HomePageProps<StoryType extends Story = Story> {
|
|
19
|
-
stories: StoryType[];
|
|
20
|
-
pagination: PaginationProps;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface Options {
|
|
24
|
-
extraStoryFields?: (keyof ExtraStoryFields)[];
|
|
25
|
-
pageSize?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function getHomepageServerSideProps<
|
|
29
|
-
CustomProps extends Record<string, any>,
|
|
30
|
-
StoryType extends Story = Story,
|
|
31
|
-
>(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
|
|
32
|
-
const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
|
|
33
|
-
|
|
34
|
-
return async function getServerSideProps(
|
|
35
|
-
context: GetServerSidePropsContext,
|
|
36
|
-
): Promise<GetServerSidePropsResult<HomePageProps<StoryType> & CustomProps>> {
|
|
37
|
-
const { api, serverSideProps } = await getNewsroomServerSideProps(context, {
|
|
38
|
-
loadHomepageContacts: true,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const { query } = context;
|
|
42
|
-
const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
|
|
43
|
-
|
|
44
|
-
const { localeCode } = serverSideProps.newsroomContextProps;
|
|
45
|
-
|
|
46
|
-
const storiesPaginated = await api.getStories({
|
|
47
|
-
page,
|
|
48
|
-
pageSize,
|
|
49
|
-
include: extraStoryFields,
|
|
50
|
-
localeCode,
|
|
51
|
-
});
|
|
52
|
-
const { stories, storiesTotal } = storiesPaginated;
|
|
53
|
-
|
|
54
|
-
return processRequest(
|
|
55
|
-
context,
|
|
56
|
-
{
|
|
57
|
-
...serverSideProps,
|
|
58
|
-
// TODO: This is temporary until return types from API are figured out
|
|
59
|
-
stories: stories as StoryType[],
|
|
60
|
-
pagination: {
|
|
61
|
-
itemsTotal: storiesTotal,
|
|
62
|
-
currentPage: page ?? 1,
|
|
63
|
-
pageSize,
|
|
64
|
-
},
|
|
65
|
-
...(typeof customProps === 'function'
|
|
66
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
67
|
-
: customProps),
|
|
68
|
-
},
|
|
69
|
-
'/',
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getHomepageStaticProps<
|
|
75
|
-
CustomProps extends Record<string, any>,
|
|
76
|
-
StoryType extends Story = Story,
|
|
77
|
-
>(customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>, options?: Options) {
|
|
78
|
-
const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
|
|
79
|
-
|
|
80
|
-
return async function getStaticProps(
|
|
81
|
-
context: GetStaticPropsContext,
|
|
82
|
-
): Promise<GetStaticPropsResult<HomePageProps<StoryType> & CustomProps>> {
|
|
83
|
-
const { api, staticProps } = await getNewsroomStaticProps(context, {
|
|
84
|
-
loadHomepageContacts: true,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const { localeCode } = staticProps.newsroomContextProps;
|
|
88
|
-
|
|
89
|
-
const storiesPaginated = await api.getStories({
|
|
90
|
-
pageSize,
|
|
91
|
-
include: extraStoryFields,
|
|
92
|
-
localeCode,
|
|
93
|
-
});
|
|
94
|
-
const { stories, storiesTotal } = storiesPaginated;
|
|
95
|
-
|
|
96
|
-
return processStaticRequest(context, {
|
|
97
|
-
...staticProps,
|
|
98
|
-
// TODO: This is temporary until return types from API are figured out
|
|
99
|
-
stories: stories as StoryType[],
|
|
100
|
-
pagination: {
|
|
101
|
-
itemsTotal: storiesTotal,
|
|
102
|
-
currentPage: 1,
|
|
103
|
-
pageSize,
|
|
104
|
-
},
|
|
105
|
-
...(typeof customProps === 'function'
|
|
106
|
-
? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
|
|
107
|
-
context,
|
|
108
|
-
staticProps,
|
|
109
|
-
)
|
|
110
|
-
: customProps),
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
getCategoryPageServerSideProps,
|
|
3
|
-
getCategoryPageStaticPaths,
|
|
4
|
-
getCategoryPageStaticProps,
|
|
5
|
-
type CategoryPageProps,
|
|
6
|
-
} from './category';
|
|
7
|
-
export {
|
|
8
|
-
getGalleryPageServerSideProps,
|
|
9
|
-
getGalleryPageStaticProps,
|
|
10
|
-
type GalleryPageProps,
|
|
11
|
-
} from './gallery';
|
|
12
|
-
export {
|
|
13
|
-
getGalleryAlbumPageServerSideProps,
|
|
14
|
-
getGalleryAlbumPageStaticPaths,
|
|
15
|
-
getGalleryAlbumPageStaticProps,
|
|
16
|
-
type GalleryAlbumPageProps,
|
|
17
|
-
} from './galleryAlbum';
|
|
18
|
-
export { getHomepageServerSideProps, getHomepageStaticProps, type HomePageProps } from './home';
|
|
19
|
-
export { getSearchPageServerSideProps, getSearchPageStaticProps } from './search';
|
|
20
|
-
export * from './sitemap';
|
|
21
|
-
export {
|
|
22
|
-
getStoryPageServerSideProps,
|
|
23
|
-
getStoryPageStaticPaths,
|
|
24
|
-
getStoryPageStaticProps,
|
|
25
|
-
} from './story';
|
|
26
|
-
export { getStoryPreviewPageServerSideProps } from './storyPreview';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
|
|
2
|
-
|
|
3
|
-
import type { PageProps } from '../../../types';
|
|
4
|
-
|
|
5
|
-
export type PropsFunction<
|
|
6
|
-
CustomProps,
|
|
7
|
-
Context extends GetServerSidePropsContext | GetStaticPropsContext = GetServerSidePropsContext,
|
|
8
|
-
> = (context: Context, props: PageProps) => CustomProps | Promise<CustomProps>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GetServerSidePropsContext,
|
|
3
|
-
GetServerSidePropsResult,
|
|
4
|
-
GetStaticPropsContext,
|
|
5
|
-
} from 'next';
|
|
6
|
-
|
|
7
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
8
|
-
import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
|
|
9
|
-
import { processRequest } from '../processRequest';
|
|
10
|
-
import { processStaticRequest } from '../processStaticRequest';
|
|
11
|
-
|
|
12
|
-
import type { PropsFunction } from './lib/types';
|
|
13
|
-
|
|
14
|
-
export function getSearchPageServerSideProps<CustomProps extends Record<string, any>>(
|
|
15
|
-
customProps: CustomProps | PropsFunction<CustomProps>,
|
|
16
|
-
) {
|
|
17
|
-
return async function getServerSideProps(
|
|
18
|
-
context: GetServerSidePropsContext,
|
|
19
|
-
): Promise<GetServerSidePropsResult<CustomProps>> {
|
|
20
|
-
const { serverSideProps } = await getNewsroomServerSideProps(context);
|
|
21
|
-
|
|
22
|
-
return processRequest(
|
|
23
|
-
context,
|
|
24
|
-
{
|
|
25
|
-
...serverSideProps,
|
|
26
|
-
...(typeof customProps === 'function'
|
|
27
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
28
|
-
: customProps),
|
|
29
|
-
},
|
|
30
|
-
'/search',
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function getSearchPageStaticProps<CustomProps extends Record<string, any>>(
|
|
36
|
-
customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
|
|
37
|
-
) {
|
|
38
|
-
return async function getStaticProps(
|
|
39
|
-
context: GetServerSidePropsContext,
|
|
40
|
-
): Promise<GetServerSidePropsResult<CustomProps>> {
|
|
41
|
-
const { staticProps } = await getNewsroomStaticProps(context);
|
|
42
|
-
|
|
43
|
-
return processStaticRequest(context, {
|
|
44
|
-
...staticProps,
|
|
45
|
-
...(typeof customProps === 'function'
|
|
46
|
-
? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
|
|
47
|
-
context,
|
|
48
|
-
staticProps,
|
|
49
|
-
)
|
|
50
|
-
: customProps),
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { SitemapUrl } from './types';
|
|
2
|
-
|
|
3
|
-
export class SitemapBuilder {
|
|
4
|
-
private baseUrl: string;
|
|
5
|
-
|
|
6
|
-
private urls: SitemapUrl[] = [];
|
|
7
|
-
|
|
8
|
-
constructor(baseUrl: string) {
|
|
9
|
-
this.baseUrl = baseUrl;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public addUrl(location: string) {
|
|
13
|
-
this.urls.push({
|
|
14
|
-
location: this.baseUrl + location,
|
|
15
|
-
changeFrequency: SitemapBuilder.guessFrequency(location),
|
|
16
|
-
priority: SitemapBuilder.guessPriority(location),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private static guessFrequency(location: string) {
|
|
21
|
-
if (location === '/') return 'daily';
|
|
22
|
-
|
|
23
|
-
return 'weekly';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private static guessPriority(location: string) {
|
|
27
|
-
if (location === '/') return '0.9';
|
|
28
|
-
|
|
29
|
-
if (location.startsWith('/category/')) {
|
|
30
|
-
return '0.8';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return '0.7';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static serializeLocation(url: SitemapUrl) {
|
|
37
|
-
return [
|
|
38
|
-
'<url>',
|
|
39
|
-
url.location && `\t<loc>${url.location}</loc>`,
|
|
40
|
-
url.changeFrequency && `\t<changefreq>${url.changeFrequency}</changefreq>`,
|
|
41
|
-
url.priority && `\t<priority>${url.priority}</priority>`,
|
|
42
|
-
'</url>',
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join('\n');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
serialize() {
|
|
49
|
-
return [
|
|
50
|
-
'<?xml version="1.0" encoding="UTF-8" ?>',
|
|
51
|
-
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">',
|
|
52
|
-
this.urls.map(SitemapBuilder.serializeLocation).join('\n'),
|
|
53
|
-
'</urlset>',
|
|
54
|
-
].join('\n');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Category, Story } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
export function createPaths(stories: Story[], categories: Category[]) {
|
|
4
|
-
const storiesUrls = stories.map(({ slug }) => `/${slug}`);
|
|
5
|
-
const categoriesUrls = categories
|
|
6
|
-
.map((category) => {
|
|
7
|
-
const translations = Object.values(category.i18n);
|
|
8
|
-
const allSlugs = translations
|
|
9
|
-
.map(({ slug }) => slug || '')
|
|
10
|
-
.filter(Boolean)
|
|
11
|
-
.reduce<string[]>(
|
|
12
|
-
(slugs, slug) => (slugs.includes(slug) ? [...slugs] : [...slugs, slug]),
|
|
13
|
-
[],
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
return allSlugs.map((slug) => `/category/${slug}`);
|
|
17
|
-
})
|
|
18
|
-
.flat();
|
|
19
|
-
|
|
20
|
-
return [...storiesUrls, ...categoriesUrls];
|
|
21
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { NextPageContext } from 'next';
|
|
2
|
-
|
|
3
|
-
import { getPrezlyApi } from '../../../data-fetching';
|
|
4
|
-
|
|
5
|
-
import { createPaths } from './createPaths';
|
|
6
|
-
import { SitemapBuilder } from './SitemapBuilder';
|
|
7
|
-
|
|
8
|
-
export function getSitemapServerSideProps(additionalPaths?: string[]) {
|
|
9
|
-
return async function getServerSideProps(ctx: NextPageContext) {
|
|
10
|
-
const { res, req } = ctx;
|
|
11
|
-
|
|
12
|
-
if (!req || !res) {
|
|
13
|
-
// client side
|
|
14
|
-
return {
|
|
15
|
-
props: {},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const baseUrl = req.headers.host || '/';
|
|
20
|
-
|
|
21
|
-
const api = getPrezlyApi(req);
|
|
22
|
-
const stories = await api.getAllStories();
|
|
23
|
-
const categories = await api.getCategories();
|
|
24
|
-
|
|
25
|
-
const paths = createPaths(stories, categories);
|
|
26
|
-
const sitemapBuilder = new SitemapBuilder(baseUrl);
|
|
27
|
-
|
|
28
|
-
sitemapBuilder.addUrl('/');
|
|
29
|
-
paths.forEach((path) => sitemapBuilder.addUrl(path));
|
|
30
|
-
|
|
31
|
-
if (additionalPaths) {
|
|
32
|
-
additionalPaths.forEach((path) => sitemapBuilder.addUrl(path));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
res.setHeader('Content-Type', 'text/xml');
|
|
36
|
-
res.write(sitemapBuilder.serialize());
|
|
37
|
-
res.end();
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
props: {},
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GetServerSidePropsContext,
|
|
3
|
-
GetServerSidePropsResult,
|
|
4
|
-
GetStaticPropsContext,
|
|
5
|
-
GetStaticPropsResult,
|
|
6
|
-
} from 'next';
|
|
7
|
-
|
|
8
|
-
import { getPrezlyApi } from '../../data-fetching';
|
|
9
|
-
import { DUMMY_DEFAULT_LOCALE } from '../../intl';
|
|
10
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
11
|
-
import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
|
|
12
|
-
import { processRequest } from '../processRequest';
|
|
13
|
-
import { processStaticRequest } from '../processStaticRequest';
|
|
14
|
-
|
|
15
|
-
import type { PropsFunction } from './lib/types';
|
|
16
|
-
|
|
17
|
-
export function getStoryPageServerSideProps<CustomProps extends Record<string, any>>(
|
|
18
|
-
customProps: CustomProps | PropsFunction<CustomProps>,
|
|
19
|
-
) {
|
|
20
|
-
return async function getServerSideProps(
|
|
21
|
-
context: GetServerSidePropsContext,
|
|
22
|
-
): Promise<GetServerSidePropsResult<CustomProps>> {
|
|
23
|
-
const api = getPrezlyApi(context.req);
|
|
24
|
-
|
|
25
|
-
const { slug } = context.params as { slug?: string };
|
|
26
|
-
const story = slug ? await api.getStoryBySlug(slug) : null;
|
|
27
|
-
if (!story) {
|
|
28
|
-
return { notFound: true };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { serverSideProps } = await getNewsroomServerSideProps(context, { story });
|
|
32
|
-
|
|
33
|
-
const { locale } = context;
|
|
34
|
-
if (locale && locale !== DUMMY_DEFAULT_LOCALE) {
|
|
35
|
-
return {
|
|
36
|
-
redirect: {
|
|
37
|
-
destination: `/${slug}`,
|
|
38
|
-
permanent: true,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
serverSideProps.newsroomContextProps.currentStory = story;
|
|
44
|
-
|
|
45
|
-
return processRequest(context, {
|
|
46
|
-
...serverSideProps,
|
|
47
|
-
...(typeof customProps === 'function'
|
|
48
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
49
|
-
: customProps),
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function getStoryPageStaticProps<CustomProps extends Record<string, any>>(
|
|
55
|
-
customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
|
|
56
|
-
) {
|
|
57
|
-
return async function getStaticProps(
|
|
58
|
-
context: GetStaticPropsContext,
|
|
59
|
-
): Promise<GetStaticPropsResult<CustomProps>> {
|
|
60
|
-
const api = getPrezlyApi();
|
|
61
|
-
|
|
62
|
-
const { slug } = context.params as { slug?: string };
|
|
63
|
-
const story = slug ? await api.getStoryBySlug(slug) : null;
|
|
64
|
-
if (!story) {
|
|
65
|
-
return { notFound: true };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const { staticProps } = await getNewsroomStaticProps(context, { story });
|
|
69
|
-
|
|
70
|
-
staticProps.newsroomContextProps.currentStory = story;
|
|
71
|
-
|
|
72
|
-
return processStaticRequest(context, {
|
|
73
|
-
...staticProps,
|
|
74
|
-
...(typeof customProps === 'function'
|
|
75
|
-
? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
|
|
76
|
-
context,
|
|
77
|
-
staticProps,
|
|
78
|
-
)
|
|
79
|
-
: customProps),
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function getStoryPageStaticPaths() {
|
|
85
|
-
const api = getPrezlyApi();
|
|
86
|
-
const stories = await api.getAllStories();
|
|
87
|
-
|
|
88
|
-
const paths = stories.map(({ slug }) => ({ params: { slug } }));
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
paths,
|
|
92
|
-
fallback: 'blocking',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
-
|
|
3
|
-
import { getPrezlyApi } from '../../data-fetching';
|
|
4
|
-
import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
|
|
5
|
-
import { processRequest } from '../processRequest';
|
|
6
|
-
|
|
7
|
-
import type { PropsFunction } from './lib/types';
|
|
8
|
-
|
|
9
|
-
export function getStoryPreviewPageServerSideProps<CustomProps extends Record<string, any>>(
|
|
10
|
-
customProps: CustomProps | PropsFunction<CustomProps>,
|
|
11
|
-
) {
|
|
12
|
-
return async function getServerSideProps(
|
|
13
|
-
context: GetServerSidePropsContext,
|
|
14
|
-
): Promise<GetServerSidePropsResult<CustomProps>> {
|
|
15
|
-
const api = getPrezlyApi(context.req);
|
|
16
|
-
const { uuid } = context.params as { uuid: string };
|
|
17
|
-
const story = await api.getStory(uuid);
|
|
18
|
-
if (!story) {
|
|
19
|
-
return { notFound: true };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { serverSideProps } = await getNewsroomServerSideProps(context, { story });
|
|
23
|
-
|
|
24
|
-
serverSideProps.newsroomContextProps.currentStory = story;
|
|
25
|
-
|
|
26
|
-
return processRequest(context, {
|
|
27
|
-
...serverSideProps,
|
|
28
|
-
...(typeof customProps === 'function'
|
|
29
|
-
? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
|
|
30
|
-
: customProps),
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}
|