@prezly/theme-kit-nextjs 2.0.0-0 → 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.
Files changed (86) hide show
  1. package/build/@types/global.d.js +1 -0
  2. package/build/adapter-nextjs/api-handlers/fetchGalleries.js +26 -18
  3. package/build/adapter-nextjs/api-handlers/fetchStories.js +36 -20
  4. package/build/adapter-nextjs/api-handlers/index.js +2 -3
  5. package/build/adapter-nextjs/getNewsroomServerSideProps.js +15 -10
  6. package/build/adapter-nextjs/getNewsroomStaticProps.js +14 -10
  7. package/build/adapter-nextjs/index.js +6 -7
  8. package/build/adapter-nextjs/page-props/category.js +115 -91
  9. package/build/adapter-nextjs/page-props/gallery.js +85 -61
  10. package/build/adapter-nextjs/page-props/galleryAlbum.js +61 -44
  11. package/build/adapter-nextjs/page-props/home.js +81 -62
  12. package/build/adapter-nextjs/page-props/index.js +8 -9
  13. package/build/adapter-nextjs/page-props/lib/types.js +1 -2
  14. package/build/adapter-nextjs/page-props/search.js +23 -24
  15. package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +28 -45
  16. package/build/adapter-nextjs/page-props/sitemap/createPaths.js +12 -14
  17. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +32 -30
  18. package/build/adapter-nextjs/page-props/sitemap/index.js +4 -5
  19. package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
  20. package/build/adapter-nextjs/page-props/story.js +74 -55
  21. package/build/adapter-nextjs/page-props/storyPreview.js +26 -21
  22. package/build/adapter-nextjs/processRequest.js +33 -20
  23. package/build/adapter-nextjs/processStaticRequest.js +18 -11
  24. package/build/components-nextjs/PageSeo/PageSeo.js +81 -71
  25. package/build/components-nextjs/PageSeo/index.js +2 -3
  26. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +4 -5
  27. package/build/components-nextjs/PageSeo/lib/types.js +1 -2
  28. package/build/components-nextjs/StorySeo/StorySeo.js +67 -41
  29. package/build/components-nextjs/StorySeo/index.js +1 -2
  30. package/build/components-nextjs/document.js +29 -19
  31. package/build/components-nextjs/index.js +3 -4
  32. package/build/data-fetching/api/PrezlyApi.js +205 -185
  33. package/build/data-fetching/api/getPrezlyApi.js +20 -16
  34. package/build/data-fetching/api/index.js +1 -2
  35. package/build/data-fetching/api/queries.js +71 -34
  36. package/build/data-fetching/index.js +3 -4
  37. package/build/data-fetching/lib/getAlgoliaSettings.js +21 -17
  38. package/build/data-fetching/lib/getEnvVariables.js +33 -29
  39. package/build/data-fetching/lib/index.js +4 -5
  40. package/build/data-fetching/lib/isSdkError.js +2 -3
  41. package/build/data-fetching/lib/isUuid.js +2 -3
  42. package/build/data-fetching/types.js +1 -2
  43. package/build/index.js +9 -10
  44. package/build/infinite-loading/index.js +4 -5
  45. package/build/infinite-loading/types.js +1 -2
  46. package/build/infinite-loading/useInfiniteGalleriesLoading.js +41 -32
  47. package/build/infinite-loading/useInfiniteLoading.js +48 -37
  48. package/build/infinite-loading/useInfiniteStoriesLoading.js +54 -44
  49. package/build/intl/index.js +4 -5
  50. package/build/intl/languages.js +135 -97
  51. package/build/intl/locale.js +46 -95
  52. package/build/intl/localeConfig.js +7 -13
  53. package/build/intl/localeList.js +1 -108
  54. package/build/intl/localeObject.js +79 -74
  55. package/build/newsroom-context/context.js +34 -20
  56. package/build/newsroom-context/hooks/index.js +11 -12
  57. package/build/newsroom-context/hooks/useAlgoliaSettings.js +4 -5
  58. package/build/newsroom-context/hooks/useCategories.js +4 -5
  59. package/build/newsroom-context/hooks/useCompanyInformation.js +4 -5
  60. package/build/newsroom-context/hooks/useCurrentCategory.js +4 -5
  61. package/build/newsroom-context/hooks/useCurrentLocale.js +4 -5
  62. package/build/newsroom-context/hooks/useCurrentStory.js +4 -5
  63. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +15 -15
  64. package/build/newsroom-context/hooks/useGetTranslationUrl.js +48 -44
  65. package/build/newsroom-context/hooks/useLanguages.js +4 -5
  66. package/build/newsroom-context/hooks/useNewsroom.js +4 -5
  67. package/build/newsroom-context/hooks/useNewsroomContext.js +9 -10
  68. package/build/newsroom-context/index.js +2 -3
  69. package/build/sentry/client.js +3 -4
  70. package/build/sentry/common.js +25 -24
  71. package/build/sentry/index.js +2 -3
  72. package/build/sentry/server.js +3 -4
  73. package/build/types.js +1 -2
  74. package/build/utils/boilerplate.js +4 -13
  75. package/build/utils/constants.js +1 -2
  76. package/build/utils/getAssetsUrl.js +3 -4
  77. package/build/utils/getDataRequestLink.js +5 -7
  78. package/build/utils/getLocalizedCategoryData.js +30 -24
  79. package/build/utils/getNewsroomLogoUrl.js +12 -13
  80. package/build/utils/getPrivacyPortalUrl.js +10 -8
  81. package/build/utils/getStoryPublicationDate.js +8 -9
  82. package/build/utils/getUploadcareGroupUrl.js +4 -5
  83. package/build/utils/index.js +10 -11
  84. package/build/utils/isEmbargoStory.js +2 -3
  85. package/package.json +10 -2
  86. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,49 +1,66 @@
1
- import { getPrezlyApi } from '../../data-fetching';
2
- import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
3
- import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
4
- import { processRequest } from '../processRequest';
5
- import { processStaticRequest } from '../processStaticRequest';
1
+ import { getPrezlyApi } from "../../data-fetching/index.js";
2
+ import { getNewsroomServerSideProps } from "../getNewsroomServerSideProps.js";
3
+ import { getNewsroomStaticProps } from "../getNewsroomStaticProps.js";
4
+ import { processRequest } from "../processRequest.js";
5
+ import { processStaticRequest } from "../processStaticRequest.js";
6
6
  export function getGalleryAlbumPageServerSideProps(customProps) {
7
- return async function getServerSideProps(context) {
8
- const { api, serverSideProps } = await getNewsroomServerSideProps(context);
9
- const { uuid } = context.params;
10
- const gallery = await api.getGallery(uuid);
11
- if (!gallery || !gallery.images_number) {
12
- return { notFound: true };
13
- }
14
- return processRequest(context, {
15
- ...serverSideProps,
16
- gallery,
17
- ...(typeof customProps === 'function'
18
- ? await customProps(context, serverSideProps)
19
- : customProps),
20
- }, `/media/album/${uuid}`);
21
- };
7
+ return async function getServerSideProps(context) {
8
+ const {
9
+ api,
10
+ serverSideProps
11
+ } = await getNewsroomServerSideProps(context);
12
+ const {
13
+ uuid
14
+ } = context.params;
15
+ const gallery = await api.getGallery(uuid);
16
+ if (!gallery || !gallery.images_number) {
17
+ return {
18
+ notFound: true
19
+ };
20
+ }
21
+ return processRequest(context, {
22
+ ...serverSideProps,
23
+ gallery,
24
+ ...(typeof customProps === 'function' ? await customProps(context, serverSideProps) : customProps)
25
+ }, `/media/album/${uuid}`);
26
+ };
22
27
  }
23
28
  export function getGalleryAlbumPageStaticProps(customProps) {
24
- return async function getStaticProps(context) {
25
- const { api, staticProps } = await getNewsroomStaticProps(context);
26
- const { uuid } = context.params;
27
- const gallery = await api.getGallery(uuid);
28
- if (!gallery || !gallery.images_number) {
29
- return { notFound: true };
30
- }
31
- return processStaticRequest(context, {
32
- ...staticProps,
33
- gallery,
34
- ...(typeof customProps === 'function'
35
- ? await customProps(context, staticProps)
36
- : customProps),
37
- });
38
- };
29
+ return async function getStaticProps(context) {
30
+ const {
31
+ api,
32
+ staticProps
33
+ } = await getNewsroomStaticProps(context);
34
+ const {
35
+ uuid
36
+ } = context.params;
37
+ const gallery = await api.getGallery(uuid);
38
+ if (!gallery || !gallery.images_number) {
39
+ return {
40
+ notFound: true
41
+ };
42
+ }
43
+ return processStaticRequest(context, {
44
+ ...staticProps,
45
+ gallery,
46
+ ...(typeof customProps === 'function' ? await customProps(context, staticProps) : customProps)
47
+ });
48
+ };
39
49
  }
40
50
  export async function getGalleryAlbumPageStaticPaths() {
41
- const api = getPrezlyApi();
42
- const { galleries } = await api.getGalleries({});
43
- const paths = galleries.map(({ uuid }) => ({ params: { uuid } }));
44
- return {
45
- paths,
46
- fallback: 'blocking',
47
- };
48
- }
49
- //# sourceMappingURL=galleryAlbum.js.map
51
+ const api = getPrezlyApi();
52
+ const {
53
+ galleries
54
+ } = await api.getGalleries({});
55
+ const paths = galleries.map(({
56
+ uuid
57
+ }) => ({
58
+ params: {
59
+ uuid
60
+ }
61
+ }));
62
+ return {
63
+ paths,
64
+ fallback: 'blocking'
65
+ };
66
+ }
@@ -1,65 +1,84 @@
1
- import { DEFAULT_PAGE_SIZE } from '../../utils';
2
- import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
3
- import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
4
- import { processRequest } from '../processRequest';
5
- import { processStaticRequest } from '../processStaticRequest';
1
+ import { DEFAULT_PAGE_SIZE } from "../../utils/index.js";
2
+ import { getNewsroomServerSideProps } from "../getNewsroomServerSideProps.js";
3
+ import { getNewsroomStaticProps } from "../getNewsroomStaticProps.js";
4
+ import { processRequest } from "../processRequest.js";
5
+ import { processStaticRequest } from "../processStaticRequest.js";
6
6
  export function getHomepageServerSideProps(customProps, options) {
7
- const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
8
- return async function getServerSideProps(context) {
9
- const { api, serverSideProps } = await getNewsroomServerSideProps(context, {
10
- loadHomepageContacts: true,
11
- });
12
- const { query } = context;
13
- const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
14
- const { localeCode } = serverSideProps.newsroomContextProps;
15
- const storiesPaginated = await api.getStories({
16
- page,
17
- pageSize,
18
- include: extraStoryFields,
19
- localeCode,
20
- });
21
- const { stories, storiesTotal } = storiesPaginated;
22
- return processRequest(context, {
23
- ...serverSideProps,
24
- // TODO: This is temporary until return types from API are figured out
25
- stories: stories,
26
- pagination: {
27
- itemsTotal: storiesTotal,
28
- currentPage: page ?? 1,
29
- pageSize,
30
- },
31
- ...(typeof customProps === 'function'
32
- ? await customProps(context, serverSideProps)
33
- : customProps),
34
- }, '/');
35
- };
7
+ const {
8
+ pageSize = DEFAULT_PAGE_SIZE,
9
+ extraStoryFields
10
+ } = options || {};
11
+ return async function getServerSideProps(context) {
12
+ const {
13
+ api,
14
+ serverSideProps
15
+ } = await getNewsroomServerSideProps(context, {
16
+ loadHomepageContacts: true
17
+ });
18
+ const {
19
+ query
20
+ } = context;
21
+ const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
22
+ const {
23
+ localeCode
24
+ } = serverSideProps.newsroomContextProps;
25
+ const storiesPaginated = await api.getStories({
26
+ page,
27
+ pageSize,
28
+ include: extraStoryFields,
29
+ localeCode
30
+ });
31
+ const {
32
+ stories,
33
+ storiesTotal
34
+ } = storiesPaginated;
35
+ return processRequest(context, {
36
+ ...serverSideProps,
37
+ // TODO: This is temporary until return types from API are figured out
38
+ stories: stories,
39
+ pagination: {
40
+ itemsTotal: storiesTotal,
41
+ currentPage: page ?? 1,
42
+ pageSize
43
+ },
44
+ ...(typeof customProps === 'function' ? await customProps(context, serverSideProps) : customProps)
45
+ }, '/');
46
+ };
36
47
  }
37
48
  export function getHomepageStaticProps(customProps, options) {
38
- const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
39
- return async function getStaticProps(context) {
40
- const { api, staticProps } = await getNewsroomStaticProps(context, {
41
- loadHomepageContacts: true,
42
- });
43
- const { localeCode } = staticProps.newsroomContextProps;
44
- const storiesPaginated = await api.getStories({
45
- pageSize,
46
- include: extraStoryFields,
47
- localeCode,
48
- });
49
- const { stories, storiesTotal } = storiesPaginated;
50
- return processStaticRequest(context, {
51
- ...staticProps,
52
- // TODO: This is temporary until return types from API are figured out
53
- stories: stories,
54
- pagination: {
55
- itemsTotal: storiesTotal,
56
- currentPage: 1,
57
- pageSize,
58
- },
59
- ...(typeof customProps === 'function'
60
- ? await customProps(context, staticProps)
61
- : customProps),
62
- });
63
- };
64
- }
65
- //# sourceMappingURL=home.js.map
49
+ const {
50
+ pageSize = DEFAULT_PAGE_SIZE,
51
+ extraStoryFields
52
+ } = options || {};
53
+ return async function getStaticProps(context) {
54
+ const {
55
+ api,
56
+ staticProps
57
+ } = await getNewsroomStaticProps(context, {
58
+ loadHomepageContacts: true
59
+ });
60
+ const {
61
+ localeCode
62
+ } = staticProps.newsroomContextProps;
63
+ const storiesPaginated = await api.getStories({
64
+ pageSize,
65
+ include: extraStoryFields,
66
+ localeCode
67
+ });
68
+ const {
69
+ stories,
70
+ storiesTotal
71
+ } = storiesPaginated;
72
+ return processStaticRequest(context, {
73
+ ...staticProps,
74
+ // TODO: This is temporary until return types from API are figured out
75
+ stories: stories,
76
+ pagination: {
77
+ itemsTotal: storiesTotal,
78
+ currentPage: 1,
79
+ pageSize
80
+ },
81
+ ...(typeof customProps === 'function' ? await customProps(context, staticProps) : customProps)
82
+ });
83
+ };
84
+ }
@@ -1,9 +1,8 @@
1
- export { getCategoryPageServerSideProps, getCategoryPageStaticPaths, getCategoryPageStaticProps, } from './category';
2
- export { getGalleryPageServerSideProps, getGalleryPageStaticProps, } from './gallery';
3
- export { getGalleryAlbumPageServerSideProps, getGalleryAlbumPageStaticPaths, getGalleryAlbumPageStaticProps, } from './galleryAlbum';
4
- export { getHomepageServerSideProps, getHomepageStaticProps } from './home';
5
- export { getSearchPageServerSideProps, getSearchPageStaticProps } from './search';
6
- export * from './sitemap';
7
- export { getStoryPageServerSideProps, getStoryPageStaticPaths, getStoryPageStaticProps, } from './story';
8
- export { getStoryPreviewPageServerSideProps } from './storyPreview';
9
- //# sourceMappingURL=index.js.map
1
+ export { getCategoryPageServerSideProps, getCategoryPageStaticPaths, getCategoryPageStaticProps } from "./category.js";
2
+ export { getGalleryPageServerSideProps, getGalleryPageStaticProps } from "./gallery.js";
3
+ export { getGalleryAlbumPageServerSideProps, getGalleryAlbumPageStaticPaths, getGalleryAlbumPageStaticProps } from "./galleryAlbum.js";
4
+ export { getHomepageServerSideProps, getHomepageStaticProps } from "./home.js";
5
+ export { getSearchPageServerSideProps, getSearchPageStaticProps } from "./search.js";
6
+ export * from "./sitemap/index.js";
7
+ export { getStoryPageServerSideProps, getStoryPageStaticPaths, getStoryPageStaticProps } from "./story.js";
8
+ export { getStoryPreviewPageServerSideProps } from "./storyPreview.js";
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export {};
@@ -1,27 +1,26 @@
1
- import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
2
- import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
3
- import { processRequest } from '../processRequest';
4
- import { processStaticRequest } from '../processStaticRequest';
1
+ import { getNewsroomServerSideProps } from "../getNewsroomServerSideProps.js";
2
+ import { getNewsroomStaticProps } from "../getNewsroomStaticProps.js";
3
+ import { processRequest } from "../processRequest.js";
4
+ import { processStaticRequest } from "../processStaticRequest.js";
5
5
  export function getSearchPageServerSideProps(customProps) {
6
- return async function getServerSideProps(context) {
7
- const { serverSideProps } = await getNewsroomServerSideProps(context);
8
- return processRequest(context, {
9
- ...serverSideProps,
10
- ...(typeof customProps === 'function'
11
- ? await customProps(context, serverSideProps)
12
- : customProps),
13
- }, '/search');
14
- };
6
+ return async function getServerSideProps(context) {
7
+ const {
8
+ serverSideProps
9
+ } = await getNewsroomServerSideProps(context);
10
+ return processRequest(context, {
11
+ ...serverSideProps,
12
+ ...(typeof customProps === 'function' ? await customProps(context, serverSideProps) : customProps)
13
+ }, '/search');
14
+ };
15
15
  }
16
16
  export function getSearchPageStaticProps(customProps) {
17
- return async function getStaticProps(context) {
18
- const { staticProps } = await getNewsroomStaticProps(context);
19
- return processStaticRequest(context, {
20
- ...staticProps,
21
- ...(typeof customProps === 'function'
22
- ? await customProps(context, staticProps)
23
- : customProps),
24
- });
25
- };
26
- }
27
- //# sourceMappingURL=search.js.map
17
+ return async function getStaticProps(context) {
18
+ const {
19
+ staticProps
20
+ } = await getNewsroomStaticProps(context);
21
+ return processStaticRequest(context, {
22
+ ...staticProps,
23
+ ...(typeof customProps === 'function' ? await customProps(context, staticProps) : customProps)
24
+ });
25
+ };
26
+ }
@@ -1,47 +1,30 @@
1
1
  export class SitemapBuilder {
2
- baseUrl;
3
- urls = [];
4
- constructor(baseUrl) {
5
- this.baseUrl = baseUrl;
2
+ urls = [];
3
+ constructor(baseUrl) {
4
+ this.baseUrl = baseUrl;
5
+ }
6
+ addUrl(location) {
7
+ this.urls.push({
8
+ location: this.baseUrl + location,
9
+ changeFrequency: SitemapBuilder.guessFrequency(location),
10
+ priority: SitemapBuilder.guessPriority(location)
11
+ });
12
+ }
13
+ static guessFrequency(location) {
14
+ if (location === '/') return 'daily';
15
+ return 'weekly';
16
+ }
17
+ static guessPriority(location) {
18
+ if (location === '/') return '0.9';
19
+ if (location.startsWith('/category/')) {
20
+ return '0.8';
6
21
  }
7
- addUrl(location) {
8
- this.urls.push({
9
- location: this.baseUrl + location,
10
- changeFrequency: SitemapBuilder.guessFrequency(location),
11
- priority: SitemapBuilder.guessPriority(location),
12
- });
13
- }
14
- static guessFrequency(location) {
15
- if (location === '/')
16
- return 'daily';
17
- return 'weekly';
18
- }
19
- static guessPriority(location) {
20
- if (location === '/')
21
- return '0.9';
22
- if (location.startsWith('/category/')) {
23
- return '0.8';
24
- }
25
- return '0.7';
26
- }
27
- static serializeLocation(url) {
28
- return [
29
- '<url>',
30
- url.location && `\t<loc>${url.location}</loc>`,
31
- url.changeFrequency && `\t<changefreq>${url.changeFrequency}</changefreq>`,
32
- url.priority && `\t<priority>${url.priority}</priority>`,
33
- '</url>',
34
- ]
35
- .filter(Boolean)
36
- .join('\n');
37
- }
38
- serialize() {
39
- return [
40
- '<?xml version="1.0" encoding="UTF-8" ?>',
41
- '<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">',
42
- this.urls.map(SitemapBuilder.serializeLocation).join('\n'),
43
- '</urlset>',
44
- ].join('\n');
45
- }
46
- }
47
- //# sourceMappingURL=SitemapBuilder.js.map
22
+ return '0.7';
23
+ }
24
+ static serializeLocation(url) {
25
+ return ['<url>', url.location && `\t<loc>${url.location}</loc>`, url.changeFrequency && `\t<changefreq>${url.changeFrequency}</changefreq>`, url.priority && `\t<priority>${url.priority}</priority>`, '</url>'].filter(Boolean).join('\n');
26
+ }
27
+ serialize() {
28
+ return ['<?xml version="1.0" encoding="UTF-8" ?>', '<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">', this.urls.map(SitemapBuilder.serializeLocation).join('\n'), '</urlset>'].join('\n');
29
+ }
30
+ }
@@ -1,15 +1,13 @@
1
1
  export function createPaths(stories, categories) {
2
- const storiesUrls = stories.map(({ slug }) => `/${slug}`);
3
- const categoriesUrls = categories
4
- .map((category) => {
5
- const translations = Object.values(category.i18n);
6
- const allSlugs = translations
7
- .map(({ slug }) => slug || '')
8
- .filter(Boolean)
9
- .reduce((slugs, slug) => (slugs.includes(slug) ? [...slugs] : [...slugs, slug]), []);
10
- return allSlugs.map((slug) => `/category/${slug}`);
11
- })
12
- .flat();
13
- return [...storiesUrls, ...categoriesUrls];
14
- }
15
- //# sourceMappingURL=createPaths.js.map
2
+ const storiesUrls = stories.map(({
3
+ slug
4
+ }) => `/${slug}`);
5
+ const categoriesUrls = categories.map(category => {
6
+ const translations = Object.values(category.i18n);
7
+ const allSlugs = translations.map(({
8
+ slug
9
+ }) => slug || '').filter(Boolean).reduce((slugs, slug) => slugs.includes(slug) ? [...slugs] : [...slugs, slug], []);
10
+ return allSlugs.map(slug => `/category/${slug}`);
11
+ }).flat();
12
+ return [...storiesUrls, ...categoriesUrls];
13
+ }
@@ -1,32 +1,34 @@
1
- import { getPrezlyApi } from '../../../data-fetching';
2
- import { createPaths } from './createPaths';
3
- import { SitemapBuilder } from './SitemapBuilder';
1
+ import { getPrezlyApi } from "../../../data-fetching/index.js";
2
+ import { createPaths } from "./createPaths.js";
3
+ import { SitemapBuilder } from "./SitemapBuilder.js";
4
4
  export function getSitemapServerSideProps(additionalPaths) {
5
- return async function getServerSideProps(ctx) {
6
- const { res, req } = ctx;
7
- if (!req || !res) {
8
- // client side
9
- return {
10
- props: {},
11
- };
12
- }
13
- const baseUrl = req.headers.host || '/';
14
- const api = getPrezlyApi(req);
15
- const stories = await api.getAllStories();
16
- const categories = await api.getCategories();
17
- const paths = createPaths(stories, categories);
18
- const sitemapBuilder = new SitemapBuilder(baseUrl);
19
- sitemapBuilder.addUrl('/');
20
- paths.forEach((path) => sitemapBuilder.addUrl(path));
21
- if (additionalPaths) {
22
- additionalPaths.forEach((path) => sitemapBuilder.addUrl(path));
23
- }
24
- res.setHeader('Content-Type', 'text/xml');
25
- res.write(sitemapBuilder.serialize());
26
- res.end();
27
- return {
28
- props: {},
29
- };
5
+ return async function getServerSideProps(ctx) {
6
+ const {
7
+ res,
8
+ req
9
+ } = ctx;
10
+ if (!req || !res) {
11
+ // client side
12
+ return {
13
+ props: {}
14
+ };
15
+ }
16
+ const baseUrl = req.headers.host || '/';
17
+ const api = getPrezlyApi(req);
18
+ const stories = await api.getAllStories();
19
+ const categories = await api.getCategories();
20
+ const paths = createPaths(stories, categories);
21
+ const sitemapBuilder = new SitemapBuilder(baseUrl);
22
+ sitemapBuilder.addUrl('/');
23
+ paths.forEach(path => sitemapBuilder.addUrl(path));
24
+ if (additionalPaths) {
25
+ additionalPaths.forEach(path => sitemapBuilder.addUrl(path));
26
+ }
27
+ res.setHeader('Content-Type', 'text/xml');
28
+ res.write(sitemapBuilder.serialize());
29
+ res.end();
30
+ return {
31
+ props: {}
30
32
  };
31
- }
32
- //# sourceMappingURL=getServerSideProps.js.map
33
+ };
34
+ }
@@ -1,5 +1,4 @@
1
- export { getSitemapServerSideProps } from './getServerSideProps';
2
- export { SitemapBuilder } from './SitemapBuilder';
3
- export { createPaths } from './createPaths';
4
- export * from './types';
5
- //# sourceMappingURL=index.js.map
1
+ export { getSitemapServerSideProps } from "./getServerSideProps.js";
2
+ export { SitemapBuilder } from "./SitemapBuilder.js";
3
+ export { createPaths } from "./createPaths.js";
4
+ export * from "./types.js";
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export {};