@prezly/theme-kit-nextjs 4.2.0-alpha.2 → 4.2.0-alpha.4

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.
Files changed (95) hide show
  1. package/build/cjs/client.d.ts +7 -0
  2. package/build/cjs/client.js +24 -0
  3. package/build/cjs/client.js.map +1 -0
  4. package/build/cjs/components-nextjs/PageSeo/PageSeo.js +1 -0
  5. package/build/cjs/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  6. package/build/cjs/components-nextjs/StorySeo/StorySeo.js +1 -0
  7. package/build/cjs/components-nextjs/StorySeo/StorySeo.js.map +1 -1
  8. package/build/cjs/components-nextjs/document.js +1 -0
  9. package/build/cjs/components-nextjs/document.js.map +1 -1
  10. package/build/cjs/newsroom-context/context.js +1 -0
  11. package/build/cjs/newsroom-context/context.js.map +1 -1
  12. package/build/cjs/server.d.ts +7 -0
  13. package/build/cjs/server.js +24 -0
  14. package/build/cjs/server.js.map +1 -0
  15. package/build/esm/client.js +8 -0
  16. package/build/esm/client.js.map +1 -0
  17. package/build/esm/components-nextjs/PageSeo/PageSeo.js +1 -0
  18. package/build/esm/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  19. package/build/esm/components-nextjs/StorySeo/StorySeo.js +1 -0
  20. package/build/esm/components-nextjs/StorySeo/StorySeo.js.map +1 -1
  21. package/build/esm/components-nextjs/document.js +1 -0
  22. package/build/esm/components-nextjs/document.js.map +1 -1
  23. package/build/esm/newsroom-context/context.js +1 -0
  24. package/build/esm/newsroom-context/context.js.map +1 -1
  25. package/build/esm/server.js +8 -0
  26. package/build/esm/server.js.map +1 -0
  27. package/build/tsconfig.cjs.tsbuildinfo +1 -1
  28. package/build/tsconfig.esm.tsbuildinfo +1 -1
  29. package/build/types/client.d.ts +7 -0
  30. package/build/types/server.d.ts +7 -0
  31. package/package.json +18 -6
  32. package/src/__mocks__/languages.ts +0 -479
  33. package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
  34. package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -43
  35. package/src/adapter-nextjs/api-handlers/index.ts +0 -2
  36. package/src/adapter-nextjs/getNewsroomServerSideProps.ts +0 -29
  37. package/src/adapter-nextjs/getNewsroomStaticProps.ts +0 -29
  38. package/src/adapter-nextjs/index.ts +0 -6
  39. package/src/adapter-nextjs/page-props/category.ts +0 -156
  40. package/src/adapter-nextjs/page-props/gallery.ts +0 -114
  41. package/src/adapter-nextjs/page-props/galleryAlbum.ts +0 -89
  42. package/src/adapter-nextjs/page-props/home.ts +0 -131
  43. package/src/adapter-nextjs/page-props/index.ts +0 -26
  44. package/src/adapter-nextjs/page-props/lib/types.ts +0 -8
  45. package/src/adapter-nextjs/page-props/search.ts +0 -53
  46. package/src/adapter-nextjs/page-props/sitemap/SitemapBuilder.ts +0 -56
  47. package/src/adapter-nextjs/page-props/sitemap/createPaths.ts +0 -21
  48. package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +0 -45
  49. package/src/adapter-nextjs/page-props/sitemap/index.ts +0 -5
  50. package/src/adapter-nextjs/page-props/sitemap/types.ts +0 -5
  51. package/src/adapter-nextjs/page-props/story.ts +0 -96
  52. package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
  53. package/src/adapter-nextjs/processRequest.ts +0 -50
  54. package/src/adapter-nextjs/processStaticRequest.ts +0 -32
  55. package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -132
  56. package/src/components-nextjs/PageSeo/index.ts +0 -1
  57. package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
  58. package/src/components-nextjs/PageSeo/lib/index.ts +0 -1
  59. package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -87
  60. package/src/components-nextjs/StorySeo/index.ts +0 -1
  61. package/src/components-nextjs/document.tsx +0 -37
  62. package/src/components-nextjs/index.ts +0 -3
  63. package/src/data-fetching/NextPrezlyApi.ts +0 -57
  64. package/src/data-fetching/getNextPrezlyApi.ts +0 -23
  65. package/src/data-fetching/index.ts +0 -1
  66. package/src/index.ts +0 -8
  67. package/src/infinite-loading/index.ts +0 -4
  68. package/src/infinite-loading/types.ts +0 -9
  69. package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -54
  70. package/src/infinite-loading/useInfiniteLoading.ts +0 -67
  71. package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -94
  72. package/src/intl/index.ts +0 -2
  73. package/src/intl/languages.test.ts +0 -37
  74. package/src/intl/languages.ts +0 -40
  75. package/src/intl/locale.test.ts +0 -42
  76. package/src/intl/locale.ts +0 -39
  77. package/src/newsroom-context/context.tsx +0 -114
  78. package/src/newsroom-context/hooks/index.ts +0 -11
  79. package/src/newsroom-context/hooks/useAlgoliaSettings.ts +0 -7
  80. package/src/newsroom-context/hooks/useCategories.ts +0 -7
  81. package/src/newsroom-context/hooks/useCompanyInformation.ts +0 -7
  82. package/src/newsroom-context/hooks/useCurrentCategory.ts +0 -7
  83. package/src/newsroom-context/hooks/useCurrentLocale.ts +0 -7
  84. package/src/newsroom-context/hooks/useCurrentStory.ts +0 -7
  85. package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +0 -36
  86. package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -99
  87. package/src/newsroom-context/hooks/useLanguages.ts +0 -7
  88. package/src/newsroom-context/hooks/useNewsroom.ts +0 -7
  89. package/src/newsroom-context/hooks/useNewsroomContext.ts +0 -15
  90. package/src/newsroom-context/index.ts +0 -2
  91. package/src/sentry/client.ts +0 -10
  92. package/src/sentry/common.ts +0 -82
  93. package/src/sentry/index.ts +0 -2
  94. package/src/sentry/server.ts +0 -10
  95. package/src/types.ts +0 -16
@@ -1,29 +0,0 @@
1
- import type { Story } from '@prezly/sdk';
2
- import type { GetStaticPropsContext } from 'next';
3
-
4
- import { getNextPrezlyApi } from '../data-fetching';
5
-
6
- interface Options {
7
- loadHomepageContacts?: boolean;
8
- story?: Story;
9
- }
10
-
11
- /**
12
- * Use this function in your `getNewsroomStaticProps` page methods to retrieve the data necessary for the NewsroomContextProvider and `processRequest` function.
13
- * See README for usage examples.
14
- */
15
- export async function getNewsroomStaticProps(
16
- context: GetStaticPropsContext,
17
- options: Options = {},
18
- ) {
19
- const { locale } = context;
20
-
21
- const api = getNextPrezlyApi();
22
- const staticProps = await api.getNewsroomServerSideProps(undefined, locale, options.story);
23
-
24
- if (options.loadHomepageContacts) {
25
- staticProps.newsroomContextProps.contacts = await api.getNewsroomContacts();
26
- }
27
-
28
- return { api, staticProps };
29
- }
@@ -1,6 +0,0 @@
1
- export * from './api-handlers';
2
- export * from './getNewsroomServerSideProps';
3
- export * from './getNewsroomStaticProps';
4
- export * from './page-props';
5
- export * from './processRequest';
6
- export * from './processStaticRequest';
@@ -1,156 +0,0 @@
1
- import type { Story } from '@prezly/sdk';
2
- import { DEFAULT_PAGE_SIZE, getLocalizedCategoryData, LocaleObject } from '@prezly/theme-kit-core';
3
- import type {
4
- GetServerSidePropsContext,
5
- GetServerSidePropsResult,
6
- GetStaticPathsResult,
7
- GetStaticPropsContext,
8
- GetStaticPropsResult,
9
- } from 'next';
10
-
11
- import { getNextPrezlyApi } from '../../data-fetching';
12
- import type { PaginationProps } from '../../infinite-loading/types';
13
- import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
14
- import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
15
- import { processRequest } from '../processRequest';
16
- import { processStaticRequest } from '../processStaticRequest';
17
-
18
- import type { PropsFunction } from './lib/types';
19
-
20
- export interface CategoryPageProps<StoryType extends Story = Story> {
21
- stories: StoryType[];
22
- pagination: PaginationProps;
23
- }
24
-
25
- interface Options {
26
- extraStoryFields?: (keyof Story.ExtraFields)[];
27
- pageSize?: number;
28
- }
29
-
30
- export function getCategoryPageServerSideProps<
31
- CustomProps extends Record<string, any>,
32
- StoryType extends Story = Story,
33
- >(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
34
- const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
35
-
36
- return async function getServerSideProps(
37
- context: GetServerSidePropsContext,
38
- ): Promise<GetServerSidePropsResult<CategoryPageProps<StoryType> & CustomProps>> {
39
- const { api, serverSideProps } = await getNewsroomServerSideProps(context);
40
-
41
- const { slug } = context.params as { slug: string };
42
- const category = await api.getCategoryBySlug(slug);
43
-
44
- if (!category) {
45
- return {
46
- notFound: true,
47
- };
48
- }
49
-
50
- const { query } = context;
51
- const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
52
-
53
- const { localeCode } = serverSideProps.newsroomContextProps;
54
-
55
- const { stories, storiesTotal } = await api.getStoriesFromCategory(category, {
56
- page,
57
- pageSize,
58
- include: extraStoryFields,
59
- localeCode,
60
- });
61
-
62
- serverSideProps.newsroomContextProps.currentCategory = category;
63
-
64
- return processRequest(
65
- context,
66
- {
67
- ...serverSideProps,
68
- // TODO: This is temporary until return types from API are figured out
69
- stories: stories as StoryType[],
70
- pagination: {
71
- itemsTotal: storiesTotal,
72
- currentPage: page ?? 1,
73
- pageSize,
74
- },
75
- ...(typeof customProps === 'function'
76
- ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
77
- : customProps),
78
- },
79
- `/category/${slug}`,
80
- );
81
- };
82
- }
83
-
84
- export function getCategoryPageStaticProps<
85
- CustomProps extends Record<string, any>,
86
- StoryType extends Story = Story,
87
- >(customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>, options?: Options) {
88
- const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
89
-
90
- return async function getStaticProps(
91
- context: GetStaticPropsContext,
92
- ): Promise<GetStaticPropsResult<CategoryPageProps<StoryType> & CustomProps>> {
93
- const { api, staticProps } = await getNewsroomStaticProps(context);
94
-
95
- const { slug } = context.params as { slug: string };
96
- const category = await api.getCategoryBySlug(slug);
97
-
98
- if (!category) {
99
- return {
100
- notFound: true,
101
- };
102
- }
103
-
104
- const { localeCode } = staticProps.newsroomContextProps;
105
-
106
- const { stories, storiesTotal } = await api.getStoriesFromCategory(category, {
107
- pageSize,
108
- include: extraStoryFields,
109
- localeCode,
110
- });
111
-
112
- staticProps.newsroomContextProps.currentCategory = category;
113
-
114
- return processStaticRequest(context, {
115
- ...staticProps,
116
- // TODO: This is temporary until return types from API are figured out
117
- stories: stories as StoryType[],
118
- pagination: {
119
- itemsTotal: storiesTotal,
120
- currentPage: 1,
121
- pageSize,
122
- },
123
- ...(typeof customProps === 'function'
124
- ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
125
- context,
126
- staticProps,
127
- )
128
- : customProps),
129
- });
130
- };
131
- }
132
-
133
- export async function getCategoryPageStaticPaths(): Promise<GetStaticPathsResult> {
134
- const api = getNextPrezlyApi();
135
- const [categories, defaultLanguage] = await Promise.all([
136
- api.getCategories(),
137
- api.getNewsroomDefaultLanguage(),
138
- ]);
139
- const locale = LocaleObject.fromAnyCode(defaultLanguage.code);
140
-
141
- const paths = categories
142
- .map((category) => {
143
- const { slug } = getLocalizedCategoryData(category, locale);
144
- if (!slug) {
145
- return undefined;
146
- }
147
-
148
- return { params: { slug } };
149
- })
150
- .filter<{ params: { slug: string } }>(Boolean as any);
151
-
152
- return {
153
- paths,
154
- fallback: 'blocking',
155
- };
156
- }
@@ -1,114 +0,0 @@
1
- import type { NewsroomGallery } from '@prezly/sdk';
2
- import { DEFAULT_GALLERY_PAGE_SIZE } from '@prezly/theme-kit-core';
3
- import type {
4
- GetServerSidePropsContext,
5
- GetServerSidePropsResult,
6
- GetStaticPropsContext,
7
- GetStaticPropsResult,
8
- } from 'next';
9
-
10
- import type { PaginationProps } from '../../infinite-loading/types';
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 { getNextPrezlyApi } 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 = getNextPrezlyApi();
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,131 +0,0 @@
1
- import type { Story } from '@prezly/sdk';
2
- import { DEFAULT_PAGE_SIZE } from '@prezly/theme-kit-core';
3
- import type {
4
- GetServerSidePropsContext,
5
- GetServerSidePropsResult,
6
- GetStaticPropsContext,
7
- GetStaticPropsResult,
8
- } from 'next';
9
-
10
- import type { PaginationProps } from '../../infinite-loading/types';
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 Story.ExtraFields)[];
25
- /**
26
- * When set to `true`, the initial `stories` array will include one extra story to place as highlighted story.
27
- * This will offset each subsequent page by 1 story to account for that.
28
- */
29
- withHighlightedStory?: boolean;
30
- pageSize?: number;
31
- pinning?: boolean;
32
- filterQuery?: Object;
33
- }
34
-
35
- export function getHomepageServerSideProps<
36
- CustomProps extends Record<string, any>,
37
- StoryType extends Story = Story,
38
- >(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
39
- const {
40
- pageSize = DEFAULT_PAGE_SIZE,
41
- extraStoryFields,
42
- pinning = false,
43
- withHighlightedStory = false,
44
- filterQuery,
45
- } = options || {};
46
-
47
- return async function getServerSideProps(
48
- context: GetServerSidePropsContext,
49
- ): Promise<GetServerSidePropsResult<HomePageProps<StoryType> & CustomProps>> {
50
- const { api, serverSideProps } = await getNewsroomServerSideProps(context, {
51
- loadHomepageContacts: true,
52
- });
53
-
54
- const { query } = context;
55
- const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
56
-
57
- const { localeCode } = serverSideProps.newsroomContextProps;
58
-
59
- const storiesPaginated = await api.getStories({
60
- page,
61
- pageSize,
62
- pinning,
63
- include: extraStoryFields,
64
- localeCode,
65
- withHighlightedStory,
66
- filterQuery,
67
- });
68
- const { stories, storiesTotal } = storiesPaginated;
69
-
70
- return processRequest(
71
- context,
72
- {
73
- ...serverSideProps,
74
- // TODO: This is temporary until return types from API are figured out
75
- stories: stories as StoryType[],
76
- pagination: {
77
- itemsTotal: storiesTotal,
78
- currentPage: page ?? 1,
79
- pageSize,
80
- withHighlightedStory,
81
- },
82
- ...(typeof customProps === 'function'
83
- ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
84
- : customProps),
85
- },
86
- '/',
87
- );
88
- };
89
- }
90
-
91
- export function getHomepageStaticProps<
92
- CustomProps extends Record<string, any>,
93
- StoryType extends Story = Story,
94
- >(customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>, options?: Options) {
95
- const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields, pinning = false } = options || {};
96
-
97
- return async function getStaticProps(
98
- context: GetStaticPropsContext,
99
- ): Promise<GetStaticPropsResult<HomePageProps<StoryType> & CustomProps>> {
100
- const { api, staticProps } = await getNewsroomStaticProps(context, {
101
- loadHomepageContacts: true,
102
- });
103
-
104
- const { localeCode } = staticProps.newsroomContextProps;
105
-
106
- const storiesPaginated = await api.getStories({
107
- pageSize,
108
- pinning,
109
- include: extraStoryFields,
110
- localeCode,
111
- });
112
- const { stories, storiesTotal } = storiesPaginated;
113
-
114
- return processStaticRequest(context, {
115
- ...staticProps,
116
- // TODO: This is temporary until return types from API are figured out
117
- stories: stories as StoryType[],
118
- pagination: {
119
- itemsTotal: storiesTotal,
120
- currentPage: 1,
121
- pageSize,
122
- },
123
- ...(typeof customProps === 'function'
124
- ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
125
- context,
126
- staticProps,
127
- )
128
- : customProps),
129
- });
130
- };
131
- }
@@ -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
- }