@prezly/theme-kit-nextjs 1.18.1 → 2.0.0-0

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 (261) hide show
  1. package/build/adapter-nextjs/api-handlers/fetchGalleries.js +3 -7
  2. package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
  3. package/build/adapter-nextjs/api-handlers/fetchStories.js +3 -7
  4. package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
  5. package/build/adapter-nextjs/api-handlers/index.js +2 -7
  6. package/build/adapter-nextjs/api-handlers/index.js.map +1 -1
  7. package/build/adapter-nextjs/getNewsroomServerSideProps.js +3 -7
  8. package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
  9. package/build/adapter-nextjs/getNewsroomStaticProps.js +3 -7
  10. package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
  11. package/build/adapter-nextjs/index.js +6 -22
  12. package/build/adapter-nextjs/index.js.map +1 -1
  13. package/build/adapter-nextjs/page-props/category.d.ts +2 -2
  14. package/build/adapter-nextjs/page-props/category.js +19 -25
  15. package/build/adapter-nextjs/page-props/category.js.map +1 -1
  16. package/build/adapter-nextjs/page-props/gallery.js +13 -18
  17. package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
  18. package/build/adapter-nextjs/page-props/galleryAlbum.js +13 -19
  19. package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
  20. package/build/adapter-nextjs/page-props/home.d.ts +2 -2
  21. package/build/adapter-nextjs/page-props/home.js +13 -18
  22. package/build/adapter-nextjs/page-props/home.js.map +1 -1
  23. package/build/adapter-nextjs/page-props/index.js +8 -41
  24. package/build/adapter-nextjs/page-props/index.js.map +1 -1
  25. package/build/adapter-nextjs/page-props/lib/types.js +1 -2
  26. package/build/adapter-nextjs/page-props/search.js +10 -15
  27. package/build/adapter-nextjs/page-props/search.js.map +1 -1
  28. package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +1 -5
  29. package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js.map +1 -1
  30. package/build/adapter-nextjs/page-props/sitemap/createPaths.js +1 -5
  31. package/build/adapter-nextjs/page-props/sitemap/createPaths.js.map +1 -1
  32. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +7 -11
  33. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
  34. package/build/adapter-nextjs/page-props/sitemap/index.js +4 -24
  35. package/build/adapter-nextjs/page-props/sitemap/index.js.map +1 -1
  36. package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
  37. package/build/adapter-nextjs/page-props/story.js +17 -23
  38. package/build/adapter-nextjs/page-props/story.js.map +1 -1
  39. package/build/adapter-nextjs/page-props/storyPreview.js +7 -11
  40. package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
  41. package/build/adapter-nextjs/processRequest.js +5 -9
  42. package/build/adapter-nextjs/processRequest.js.map +1 -1
  43. package/build/adapter-nextjs/processStaticRequest.js +1 -5
  44. package/build/adapter-nextjs/processStaticRequest.js.map +1 -1
  45. package/build/components-nextjs/PageSeo/PageSeo.js +25 -29
  46. package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  47. package/build/components-nextjs/PageSeo/index.js +2 -20
  48. package/build/components-nextjs/PageSeo/index.js.map +1 -1
  49. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +1 -5
  50. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
  51. package/build/components-nextjs/PageSeo/lib/types.js +1 -2
  52. package/build/components-nextjs/StorySeo/StorySeo.js +8 -12
  53. package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
  54. package/build/components-nextjs/StorySeo/index.js +1 -5
  55. package/build/components-nextjs/StorySeo/index.js.map +1 -1
  56. package/build/components-nextjs/document.js +8 -35
  57. package/build/components-nextjs/document.js.map +1 -1
  58. package/build/components-nextjs/index.js +3 -9
  59. package/build/components-nextjs/index.js.map +1 -1
  60. package/build/data-fetching/api/PrezlyApi.d.ts +4 -5
  61. package/build/data-fetching/api/PrezlyApi.js +39 -44
  62. package/build/data-fetching/api/PrezlyApi.js.map +1 -1
  63. package/build/data-fetching/api/getPrezlyApi.js +5 -9
  64. package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
  65. package/build/data-fetching/api/index.js +1 -17
  66. package/build/data-fetching/api/index.js.map +1 -1
  67. package/build/data-fetching/api/queries.js +5 -13
  68. package/build/data-fetching/api/queries.js.map +1 -1
  69. package/build/data-fetching/index.js +3 -19
  70. package/build/data-fetching/index.js.map +1 -1
  71. package/build/data-fetching/lib/getAlgoliaSettings.js +3 -7
  72. package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
  73. package/build/data-fetching/lib/getEnvVariables.js +3 -10
  74. package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
  75. package/build/data-fetching/lib/index.js +4 -11
  76. package/build/data-fetching/lib/index.js.map +1 -1
  77. package/build/data-fetching/lib/isSdkError.js +1 -5
  78. package/build/data-fetching/lib/isSdkError.js.map +1 -1
  79. package/build/data-fetching/lib/isUuid.js +1 -5
  80. package/build/data-fetching/lib/isUuid.js.map +1 -1
  81. package/build/data-fetching/types.js +1 -2
  82. package/build/index.js +9 -25
  83. package/build/index.js.map +1 -1
  84. package/build/infinite-loading/index.js +4 -24
  85. package/build/infinite-loading/index.js.map +1 -1
  86. package/build/infinite-loading/types.js +1 -2
  87. package/build/infinite-loading/useInfiniteGalleriesLoading.js +3 -7
  88. package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
  89. package/build/infinite-loading/useInfiniteLoading.js +9 -13
  90. package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
  91. package/build/infinite-loading/useInfiniteStoriesLoading.d.ts +2 -2
  92. package/build/infinite-loading/useInfiniteStoriesLoading.js +7 -11
  93. package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
  94. package/build/intl/index.d.ts +1 -1
  95. package/build/intl/index.js +4 -25
  96. package/build/intl/index.js.map +1 -1
  97. package/build/intl/languages.d.ts +1 -1
  98. package/build/intl/languages.js +23 -37
  99. package/build/intl/languages.js.map +1 -1
  100. package/build/intl/locale.js +11 -17
  101. package/build/intl/locale.js.map +1 -1
  102. package/build/intl/localeConfig.d.ts +1 -2
  103. package/build/intl/localeConfig.js +3 -4
  104. package/build/intl/localeConfig.js.map +1 -1
  105. package/build/intl/localeList.d.ts +4 -2
  106. package/build/intl/localeList.js +1 -2
  107. package/build/intl/localeList.js.map +1 -1
  108. package/build/intl/localeObject.js +3 -10
  109. package/build/intl/localeObject.js.map +1 -1
  110. package/build/newsroom-context/context.js +7 -11
  111. package/build/newsroom-context/context.js.map +1 -1
  112. package/build/newsroom-context/hooks/index.js +11 -27
  113. package/build/newsroom-context/hooks/index.js.map +1 -1
  114. package/build/newsroom-context/hooks/useAlgoliaSettings.js +3 -7
  115. package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
  116. package/build/newsroom-context/hooks/useCategories.js +3 -7
  117. package/build/newsroom-context/hooks/useCategories.js.map +1 -1
  118. package/build/newsroom-context/hooks/useCompanyInformation.js +3 -7
  119. package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
  120. package/build/newsroom-context/hooks/useCurrentCategory.js +3 -7
  121. package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
  122. package/build/newsroom-context/hooks/useCurrentLocale.js +3 -7
  123. package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
  124. package/build/newsroom-context/hooks/useCurrentStory.js +3 -7
  125. package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
  126. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +10 -14
  127. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
  128. package/build/newsroom-context/hooks/useGetTranslationUrl.js +24 -31
  129. package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
  130. package/build/newsroom-context/hooks/useLanguages.js +3 -7
  131. package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
  132. package/build/newsroom-context/hooks/useNewsroom.js +3 -7
  133. package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
  134. package/build/newsroom-context/hooks/useNewsroomContext.js +4 -8
  135. package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
  136. package/build/newsroom-context/index.js +2 -21
  137. package/build/newsroom-context/index.js.map +1 -1
  138. package/build/sentry/client.js +3 -7
  139. package/build/sentry/client.js.map +1 -1
  140. package/build/sentry/common.js +1 -5
  141. package/build/sentry/common.js.map +1 -1
  142. package/build/sentry/index.js +2 -7
  143. package/build/sentry/index.js.map +1 -1
  144. package/build/sentry/server.js +3 -7
  145. package/build/sentry/server.js.map +1 -1
  146. package/build/tsconfig.tsbuildinfo +1 -1
  147. package/build/types.d.ts +2 -2
  148. package/build/types.js +1 -2
  149. package/build/utils/boilerplate.js +3 -9
  150. package/build/utils/boilerplate.js.map +1 -1
  151. package/build/utils/constants.js +3 -6
  152. package/build/utils/constants.js.map +1 -1
  153. package/build/utils/getAssetsUrl.js +3 -7
  154. package/build/utils/getAssetsUrl.js.map +1 -1
  155. package/build/utils/getDataRequestLink.js +3 -7
  156. package/build/utils/getDataRequestLink.js.map +1 -1
  157. package/build/utils/getLocalizedCategoryData.js +3 -9
  158. package/build/utils/getLocalizedCategoryData.js.map +1 -1
  159. package/build/utils/getNewsroomLogoUrl.js +5 -10
  160. package/build/utils/getNewsroomLogoUrl.js.map +1 -1
  161. package/build/utils/getPrivacyPortalUrl.js +1 -5
  162. package/build/utils/getPrivacyPortalUrl.js.map +1 -1
  163. package/build/utils/getStoryPublicationDate.js +1 -5
  164. package/build/utils/getStoryPublicationDate.js.map +1 -1
  165. package/build/utils/getUploadcareGroupUrl.js +3 -7
  166. package/build/utils/getUploadcareGroupUrl.js.map +1 -1
  167. package/build/utils/index.js +10 -26
  168. package/build/utils/index.js.map +1 -1
  169. package/build/utils/isEmbargoStory.js +1 -5
  170. package/build/utils/isEmbargoStory.js.map +1 -1
  171. package/package.json +17 -17
  172. package/src/@types/global.d.ts +0 -7
  173. package/src/__mocks__/languages.ts +0 -417
  174. package/src/__mocks__/story.ts +0 -351
  175. package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
  176. package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -26
  177. package/src/adapter-nextjs/api-handlers/index.ts +0 -2
  178. package/src/adapter-nextjs/getNewsroomServerSideProps.ts +0 -29
  179. package/src/adapter-nextjs/getNewsroomStaticProps.ts +0 -29
  180. package/src/adapter-nextjs/index.ts +0 -6
  181. package/src/adapter-nextjs/page-props/category.ts +0 -157
  182. package/src/adapter-nextjs/page-props/gallery.ts +0 -114
  183. package/src/adapter-nextjs/page-props/galleryAlbum.ts +0 -89
  184. package/src/adapter-nextjs/page-props/home.ts +0 -113
  185. package/src/adapter-nextjs/page-props/index.ts +0 -26
  186. package/src/adapter-nextjs/page-props/lib/types.ts +0 -8
  187. package/src/adapter-nextjs/page-props/search.ts +0 -53
  188. package/src/adapter-nextjs/page-props/sitemap/SitemapBuilder.ts +0 -56
  189. package/src/adapter-nextjs/page-props/sitemap/createPaths.ts +0 -21
  190. package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +0 -43
  191. package/src/adapter-nextjs/page-props/sitemap/index.ts +0 -5
  192. package/src/adapter-nextjs/page-props/sitemap/types.ts +0 -5
  193. package/src/adapter-nextjs/page-props/story.ts +0 -94
  194. package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
  195. package/src/adapter-nextjs/processRequest.ts +0 -49
  196. package/src/adapter-nextjs/processStaticRequest.ts +0 -32
  197. package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -131
  198. package/src/components-nextjs/PageSeo/index.ts +0 -2
  199. package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
  200. package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
  201. package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -80
  202. package/src/components-nextjs/StorySeo/index.ts +0 -1
  203. package/src/components-nextjs/document.tsx +0 -38
  204. package/src/components-nextjs/index.ts +0 -3
  205. package/src/data-fetching/api/PrezlyApi.ts +0 -302
  206. package/src/data-fetching/api/getPrezlyApi.ts +0 -24
  207. package/src/data-fetching/api/index.ts +0 -1
  208. package/src/data-fetching/api/queries.ts +0 -51
  209. package/src/data-fetching/index.ts +0 -3
  210. package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
  211. package/src/data-fetching/lib/getEnvVariables.ts +0 -46
  212. package/src/data-fetching/lib/index.ts +0 -4
  213. package/src/data-fetching/lib/isSdkError.ts +0 -5
  214. package/src/data-fetching/lib/isUuid.ts +0 -5
  215. package/src/data-fetching/types.ts +0 -14
  216. package/src/index.ts +0 -9
  217. package/src/infinite-loading/index.ts +0 -4
  218. package/src/infinite-loading/types.ts +0 -5
  219. package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -53
  220. package/src/infinite-loading/useInfiniteLoading.ts +0 -66
  221. package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -81
  222. package/src/intl/index.ts +0 -4
  223. package/src/intl/languages.test.ts +0 -232
  224. package/src/intl/languages.ts +0 -233
  225. package/src/intl/locale.test.ts +0 -94
  226. package/src/intl/locale.ts +0 -140
  227. package/src/intl/localeConfig.js +0 -23
  228. package/src/intl/localeList.js +0 -110
  229. package/src/intl/localeObject.test.ts +0 -81
  230. package/src/intl/localeObject.ts +0 -99
  231. package/src/newsroom-context/context.tsx +0 -115
  232. package/src/newsroom-context/hooks/index.ts +0 -11
  233. package/src/newsroom-context/hooks/useAlgoliaSettings.ts +0 -7
  234. package/src/newsroom-context/hooks/useCategories.ts +0 -7
  235. package/src/newsroom-context/hooks/useCompanyInformation.ts +0 -7
  236. package/src/newsroom-context/hooks/useCurrentCategory.ts +0 -7
  237. package/src/newsroom-context/hooks/useCurrentLocale.ts +0 -7
  238. package/src/newsroom-context/hooks/useCurrentStory.ts +0 -7
  239. package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +0 -37
  240. package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -96
  241. package/src/newsroom-context/hooks/useLanguages.ts +0 -7
  242. package/src/newsroom-context/hooks/useNewsroom.ts +0 -7
  243. package/src/newsroom-context/hooks/useNewsroomContext.ts +0 -15
  244. package/src/newsroom-context/index.ts +0 -2
  245. package/src/sentry/client.ts +0 -7
  246. package/src/sentry/common.ts +0 -27
  247. package/src/sentry/index.ts +0 -2
  248. package/src/sentry/server.ts +0 -7
  249. package/src/types.ts +0 -51
  250. package/src/utils/boilerplate.ts +0 -27
  251. package/src/utils/constants.ts +0 -3
  252. package/src/utils/getAssetsUrl.test.ts +0 -9
  253. package/src/utils/getAssetsUrl.ts +0 -9
  254. package/src/utils/getDataRequestLink.ts +0 -14
  255. package/src/utils/getLocalizedCategoryData.ts +0 -47
  256. package/src/utils/getNewsroomLogoUrl.ts +0 -22
  257. package/src/utils/getPrivacyPortalUrl.ts +0 -25
  258. package/src/utils/getStoryPublicationDate.tsx +0 -15
  259. package/src/utils/getUploadcareGroupUrl.ts +0 -13
  260. package/src/utils/index.ts +0 -10
  261. 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,5 +0,0 @@
1
- export { getSitemapServerSideProps } from './getServerSideProps';
2
-
3
- export { SitemapBuilder } from './SitemapBuilder';
4
- export { createPaths } from './createPaths';
5
- export * from './types';
@@ -1,5 +0,0 @@
1
- export type SitemapUrl = {
2
- location: string;
3
- changeFrequency?: string;
4
- priority?: string;
5
- };
@@ -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
- }