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

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/README.md +8 -13
  2. package/build/@types/global.d.js +1 -0
  3. package/build/adapter-nextjs/api-handlers/fetchGalleries.js +26 -18
  4. package/build/adapter-nextjs/api-handlers/fetchStories.js +36 -20
  5. package/build/adapter-nextjs/api-handlers/index.js +2 -3
  6. package/build/adapter-nextjs/getNewsroomServerSideProps.js +15 -10
  7. package/build/adapter-nextjs/getNewsroomStaticProps.js +14 -10
  8. package/build/adapter-nextjs/index.js +6 -7
  9. package/build/adapter-nextjs/page-props/category.js +115 -91
  10. package/build/adapter-nextjs/page-props/gallery.js +85 -61
  11. package/build/adapter-nextjs/page-props/galleryAlbum.js +61 -44
  12. package/build/adapter-nextjs/page-props/home.js +81 -62
  13. package/build/adapter-nextjs/page-props/index.js +8 -9
  14. package/build/adapter-nextjs/page-props/lib/types.js +1 -2
  15. package/build/adapter-nextjs/page-props/search.js +23 -24
  16. package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +28 -45
  17. package/build/adapter-nextjs/page-props/sitemap/createPaths.js +12 -14
  18. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +32 -30
  19. package/build/adapter-nextjs/page-props/sitemap/index.js +4 -5
  20. package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
  21. package/build/adapter-nextjs/page-props/story.js +74 -55
  22. package/build/adapter-nextjs/page-props/storyPreview.js +26 -21
  23. package/build/adapter-nextjs/processRequest.js +33 -20
  24. package/build/adapter-nextjs/processStaticRequest.js +18 -11
  25. package/build/components-nextjs/PageSeo/PageSeo.js +81 -71
  26. package/build/components-nextjs/PageSeo/index.js +2 -3
  27. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +4 -5
  28. package/build/components-nextjs/PageSeo/lib/types.js +1 -2
  29. package/build/components-nextjs/StorySeo/StorySeo.js +67 -41
  30. package/build/components-nextjs/StorySeo/index.js +1 -2
  31. package/build/components-nextjs/document.js +29 -19
  32. package/build/components-nextjs/index.js +3 -4
  33. package/build/data-fetching/api/PrezlyApi.js +205 -185
  34. package/build/data-fetching/api/getPrezlyApi.js +20 -16
  35. package/build/data-fetching/api/index.js +1 -2
  36. package/build/data-fetching/api/queries.js +71 -34
  37. package/build/data-fetching/index.js +3 -4
  38. package/build/data-fetching/lib/getAlgoliaSettings.js +21 -17
  39. package/build/data-fetching/lib/getEnvVariables.js +33 -29
  40. package/build/data-fetching/lib/index.js +4 -5
  41. package/build/data-fetching/lib/isSdkError.js +2 -3
  42. package/build/data-fetching/lib/isUuid.js +2 -3
  43. package/build/data-fetching/types.js +1 -2
  44. package/build/index.js +9 -10
  45. package/build/infinite-loading/index.js +4 -5
  46. package/build/infinite-loading/types.js +1 -2
  47. package/build/infinite-loading/useInfiniteGalleriesLoading.js +41 -32
  48. package/build/infinite-loading/useInfiniteLoading.js +48 -37
  49. package/build/infinite-loading/useInfiniteStoriesLoading.js +54 -44
  50. package/build/intl/index.d.ts +1 -1
  51. package/build/intl/index.js +4 -5
  52. package/build/intl/index.js.map +1 -1
  53. package/build/intl/languages.js +135 -97
  54. package/build/intl/languages.js.map +1 -1
  55. package/build/intl/locale.d.ts +0 -1
  56. package/build/intl/locale.js +47 -97
  57. package/build/intl/locale.js.map +1 -1
  58. package/build/intl/localeConfig.d.ts +3 -1
  59. package/build/intl/localeConfig.js +20 -13
  60. package/build/intl/localeConfig.js.map +1 -1
  61. package/build/intl/localeList.js +1 -108
  62. package/build/intl/localeObject.js +79 -74
  63. package/build/intl/localeObject.js.map +1 -1
  64. package/build/newsroom-context/context.js +34 -20
  65. package/build/newsroom-context/hooks/index.js +11 -12
  66. package/build/newsroom-context/hooks/useAlgoliaSettings.js +4 -5
  67. package/build/newsroom-context/hooks/useCategories.js +4 -5
  68. package/build/newsroom-context/hooks/useCompanyInformation.js +4 -5
  69. package/build/newsroom-context/hooks/useCurrentCategory.js +4 -5
  70. package/build/newsroom-context/hooks/useCurrentLocale.js +4 -5
  71. package/build/newsroom-context/hooks/useCurrentStory.js +4 -5
  72. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +15 -15
  73. package/build/newsroom-context/hooks/useGetTranslationUrl.js +48 -44
  74. package/build/newsroom-context/hooks/useLanguages.js +4 -5
  75. package/build/newsroom-context/hooks/useNewsroom.js +4 -5
  76. package/build/newsroom-context/hooks/useNewsroomContext.js +9 -10
  77. package/build/newsroom-context/index.js +2 -3
  78. package/build/sentry/client.js +3 -4
  79. package/build/sentry/common.js +25 -24
  80. package/build/sentry/index.js +2 -3
  81. package/build/sentry/server.js +3 -4
  82. package/build/types.js +1 -2
  83. package/build/utils/boilerplate.js +4 -13
  84. package/build/utils/constants.js +1 -2
  85. package/build/utils/getAssetsUrl.js +3 -4
  86. package/build/utils/getDataRequestLink.js +5 -7
  87. package/build/utils/getLocalizedCategoryData.js +30 -24
  88. package/build/utils/getNewsroomLogoUrl.js +12 -13
  89. package/build/utils/getPrivacyPortalUrl.js +10 -8
  90. package/build/utils/getStoryPublicationDate.js +8 -9
  91. package/build/utils/getUploadcareGroupUrl.js +4 -5
  92. package/build/utils/index.js +10 -11
  93. package/build/utils/isEmbargoStory.js +2 -3
  94. package/package.json +17 -2
  95. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,37 +1,41 @@
1
1
  import parseDataUrl from 'parse-data-url';
2
2
  function decodeJson(json) {
3
- try {
4
- const decoded = JSON.parse(json);
5
- if (decoded && typeof decoded === 'object') {
6
- return decoded;
7
- }
3
+ try {
4
+ const decoded = JSON.parse(json);
5
+ if (decoded && typeof decoded === 'object') {
6
+ return decoded;
8
7
  }
9
- catch {
10
- // passthru
11
- }
12
- return {};
8
+ } catch {
9
+ // passthru
10
+ }
11
+ return {};
13
12
  }
14
13
  function decodeHttpEnv(header) {
15
- if (header.startsWith('data:')) {
16
- const parsed = parseDataUrl(header);
17
- if (parsed && parsed.contentType === 'application/json') {
18
- const data = parsed.toBuffer().toString('utf-8');
19
- return decodeJson(data);
20
- }
21
- return {}; // unsupported data-uri
14
+ if (header.startsWith('data:')) {
15
+ const parsed = parseDataUrl(header);
16
+ if (parsed && parsed.contentType === 'application/json') {
17
+ const data = parsed.toBuffer().toString('utf-8');
18
+ return decodeJson(data);
22
19
  }
23
- return decodeJson(header);
20
+ return {}; // unsupported data-uri
21
+ }
22
+
23
+ return decodeJson(header);
24
24
  }
25
25
  export function getEnvVariables(req) {
26
- if (typeof window !== 'undefined') {
27
- throw new Error('"getEnvVariables" should only be used on back-end side.');
28
- }
29
- const headerName = (process.env.HTTP_ENV_HEADER || '').toLowerCase();
30
- if (headerName && req) {
31
- const header = req.headers[headerName];
32
- const httpEnv = decodeHttpEnv(header || '');
33
- return { ...process.env, ...httpEnv };
34
- }
35
- return { ...process.env };
36
- }
37
- //# sourceMappingURL=getEnvVariables.js.map
26
+ if (typeof window !== 'undefined') {
27
+ throw new Error('"getEnvVariables" should only be used on back-end side.');
28
+ }
29
+ const headerName = (process.env.HTTP_ENV_HEADER || '').toLowerCase();
30
+ if (headerName && req) {
31
+ const header = req.headers[headerName];
32
+ const httpEnv = decodeHttpEnv(header || '');
33
+ return {
34
+ ...process.env,
35
+ ...httpEnv
36
+ };
37
+ }
38
+ return {
39
+ ...process.env
40
+ };
41
+ }
@@ -1,5 +1,4 @@
1
- export { getAlgoliaSettings } from './getAlgoliaSettings';
2
- export { getEnvVariables } from './getEnvVariables';
3
- export { isSdkError } from './isSdkError';
4
- export { isUuid } from './isUuid';
5
- //# sourceMappingURL=index.js.map
1
+ export { getAlgoliaSettings } from "./getAlgoliaSettings.js";
2
+ export { getEnvVariables } from "./getEnvVariables.js";
3
+ export { isSdkError } from "./isSdkError.js";
4
+ export { isUuid } from "./isUuid.js";
@@ -1,4 +1,3 @@
1
1
  export function isSdkError(error) {
2
- return 'payload' in error;
3
- }
4
- //# sourceMappingURL=isSdkError.js.map
2
+ return 'payload' in error;
3
+ }
@@ -1,5 +1,4 @@
1
1
  const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
2
2
  export function isUuid(input) {
3
- return UUID_REGEX.test(input);
4
- }
5
- //# sourceMappingURL=isUuid.js.map
3
+ return UUID_REGEX.test(input);
4
+ }
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export {};
package/build/index.js CHANGED
@@ -1,10 +1,9 @@
1
- export * from './adapter-nextjs';
2
- export * from './components-nextjs';
3
- export * from './data-fetching';
4
- export * from './infinite-loading';
5
- export * from './intl';
6
- export * from './newsroom-context';
7
- export * from './sentry';
8
- export * from './types';
9
- export * from './utils';
10
- //# sourceMappingURL=index.js.map
1
+ export * from "./adapter-nextjs/index.js";
2
+ export * from "./components-nextjs/index.js";
3
+ export * from "./data-fetching/index.js";
4
+ export * from "./infinite-loading/index.js";
5
+ export * from "./intl/index.js";
6
+ export * from "./newsroom-context/index.js";
7
+ export * from "./sentry/index.js";
8
+ export * from "./types.js";
9
+ export * from "./utils/index.js";
@@ -1,5 +1,4 @@
1
- export { useInfiniteLoading } from './useInfiniteLoading';
2
- export { useInfiniteStoriesLoading } from './useInfiniteStoriesLoading';
3
- export { useInfiniteGalleriesLoading } from './useInfiniteGalleriesLoading';
4
- export * from './types';
5
- //# sourceMappingURL=index.js.map
1
+ export { useInfiniteLoading } from "./useInfiniteLoading.js";
2
+ export { useInfiniteStoriesLoading } from "./useInfiniteStoriesLoading.js";
3
+ export { useInfiniteGalleriesLoading } from "./useInfiniteGalleriesLoading.js";
4
+ export * from "./types.js";
@@ -1,2 +1 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ export {};
@@ -1,40 +1,49 @@
1
- import { useInfiniteLoading } from './useInfiniteLoading';
1
+ import { useInfiniteLoading } from "./useInfiniteLoading.js";
2
2
  async function fetchGalleries(page, pageSize) {
3
- const result = await fetch('/api/fetch-galleries', {
4
- method: 'POST',
5
- headers: {
6
- 'Content-Type': 'application/json',
7
- },
8
- body: JSON.stringify({
9
- page,
10
- pageSize,
11
- }),
12
- });
13
- if (!result.ok) {
14
- const { message } = await result.json();
15
- throw new Error(message);
16
- }
17
- return result.json();
3
+ const result = await fetch('/api/fetch-galleries', {
4
+ method: 'POST',
5
+ headers: {
6
+ 'Content-Type': 'application/json'
7
+ },
8
+ body: JSON.stringify({
9
+ page,
10
+ pageSize
11
+ })
12
+ });
13
+ if (!result.ok) {
14
+ const {
15
+ message
16
+ } = await result.json();
17
+ throw new Error(message);
18
+ }
19
+ return result.json();
18
20
  }
21
+
19
22
  /**
20
23
  * NOTE: This hook depends on the presence of a Next API route (/api/fetch-galleries)!
21
24
  * The handler for this route is exported from `apiHandlers/fetchGalleries.ts` file.
22
25
  * See https://github.com/prezly/theme-nextjs-bea/blob/d381e9878187ca98815d240d3ffdf10a75993c14/pages/media/index.tsx#L23 for usage example
23
26
  */
24
27
  export function useInfiniteGalleriesLoading(initialGalleries, pagination) {
25
- const { canLoadMore, data, isLoading, loadMore } = useInfiniteLoading({
26
- fetchingFn: async (nextPage, pageSize) => {
27
- const { galleries } = await fetchGalleries(nextPage, pageSize);
28
- return galleries;
29
- },
30
- initialData: initialGalleries,
31
- pagination,
32
- });
33
- return {
34
- canLoadMore,
35
- galleries: data,
36
- isLoading,
37
- loadMoreGalleries: loadMore,
38
- };
39
- }
40
- //# sourceMappingURL=useInfiniteGalleriesLoading.js.map
28
+ const {
29
+ canLoadMore,
30
+ data,
31
+ isLoading,
32
+ loadMore
33
+ } = useInfiniteLoading({
34
+ fetchingFn: async (nextPage, pageSize) => {
35
+ const {
36
+ galleries
37
+ } = await fetchGalleries(nextPage, pageSize);
38
+ return galleries;
39
+ },
40
+ initialData: initialGalleries,
41
+ pagination
42
+ });
43
+ return {
44
+ canLoadMore,
45
+ galleries: data,
46
+ isLoading,
47
+ loadMoreGalleries: loadMore
48
+ };
49
+ }
@@ -1,39 +1,50 @@
1
1
  import { useAsync } from '@react-hookz/web';
2
2
  import { useCallback, useEffect, useState } from 'react';
3
- export function useInfiniteLoading({ fetchingFn, initialData, pagination, }) {
4
- const [data, setData] = useState(initialData);
5
- const [currentPage, setCurrentPage] = useState(pagination.currentPage);
6
- const { itemsTotal, pageSize } = pagination;
7
- const pagesTotal = Math.ceil(itemsTotal / pageSize);
8
- const canLoadMore = currentPage < pagesTotal;
9
- const [{ error, status }, { execute: loadMoreFn }] = useAsync(async () => {
10
- const nextPage = currentPage + 1;
11
- const newData = await fetchingFn(nextPage, pageSize);
12
- setCurrentPage(nextPage);
13
- setData((currentData) => [...currentData, ...newData]);
14
- });
15
- const loadMore = useCallback(() => {
16
- if (canLoadMore) {
17
- loadMoreFn();
18
- }
19
- }, [canLoadMore, loadMoreFn]);
20
- const resetData = useCallback(() => {
21
- setData(initialData);
22
- setCurrentPage(pagination.currentPage);
23
- }, [pagination.currentPage, initialData]);
24
- useEffect(() => {
25
- if (error) {
26
- // eslint-disable-next-line no-console
27
- console.error(error);
28
- }
29
- }, [error]);
30
- return {
31
- canLoadMore,
32
- currentPage,
33
- data,
34
- isLoading: status === 'loading',
35
- loadMore,
36
- resetData,
37
- };
38
- }
39
- //# sourceMappingURL=useInfiniteLoading.js.map
3
+ export function useInfiniteLoading({
4
+ fetchingFn,
5
+ initialData,
6
+ pagination
7
+ }) {
8
+ const [data, setData] = useState(initialData);
9
+ const [currentPage, setCurrentPage] = useState(pagination.currentPage);
10
+ const {
11
+ itemsTotal,
12
+ pageSize
13
+ } = pagination;
14
+ const pagesTotal = Math.ceil(itemsTotal / pageSize);
15
+ const canLoadMore = currentPage < pagesTotal;
16
+ const [{
17
+ error,
18
+ status
19
+ }, {
20
+ execute: loadMoreFn
21
+ }] = useAsync(async () => {
22
+ const nextPage = currentPage + 1;
23
+ const newData = await fetchingFn(nextPage, pageSize);
24
+ setCurrentPage(nextPage);
25
+ setData(currentData => [...currentData, ...newData]);
26
+ });
27
+ const loadMore = useCallback(() => {
28
+ if (canLoadMore) {
29
+ loadMoreFn();
30
+ }
31
+ }, [canLoadMore, loadMoreFn]);
32
+ const resetData = useCallback(() => {
33
+ setData(initialData);
34
+ setCurrentPage(pagination.currentPage);
35
+ }, [pagination.currentPage, initialData]);
36
+ useEffect(() => {
37
+ if (error) {
38
+ // eslint-disable-next-line no-console
39
+ console.error(error);
40
+ }
41
+ }, [error]);
42
+ return {
43
+ canLoadMore,
44
+ currentPage,
45
+ data,
46
+ isLoading: status === 'loading',
47
+ loadMore,
48
+ resetData
49
+ };
50
+ }
@@ -1,53 +1,63 @@
1
1
  import { useEffect } from 'react';
2
- import { useCurrentLocale } from '../newsroom-context';
3
- import { useInfiniteLoading } from './useInfiniteLoading';
2
+ import { useCurrentLocale } from "../newsroom-context/index.js";
3
+ import { useInfiniteLoading } from "./useInfiniteLoading.js";
4
4
  async function fetchStories(page, pageSize, category, locale, include) {
5
- const result = await fetch('/api/fetch-stories', {
6
- method: 'POST',
7
- headers: {
8
- 'Content-Type': 'application/json',
9
- },
10
- body: JSON.stringify({
11
- page,
12
- pageSize,
13
- category,
14
- include,
15
- ...(locale && {
16
- localeCode: locale.toUnderscoreCode(),
17
- }),
18
- }),
19
- });
20
- if (!result.ok) {
21
- const { message } = await result.json();
22
- throw new Error(message);
23
- }
24
- return result.json();
5
+ const result = await fetch('/api/fetch-stories', {
6
+ method: 'POST',
7
+ headers: {
8
+ 'Content-Type': 'application/json'
9
+ },
10
+ body: JSON.stringify({
11
+ page,
12
+ pageSize,
13
+ category,
14
+ include,
15
+ ...(locale && {
16
+ localeCode: locale.toUnderscoreCode()
17
+ })
18
+ })
19
+ });
20
+ if (!result.ok) {
21
+ const {
22
+ message
23
+ } = await result.json();
24
+ throw new Error(message);
25
+ }
26
+ return result.json();
25
27
  }
28
+
26
29
  /**
27
30
  * NOTE: This hook depends on the presence of a Next API route (/api/fetch-stories)!
28
31
  * The handler for this route is exported from `apiHandlers/fetchStories.ts` file.
29
32
  * See https://github.com/prezly/theme-nextjs-bea/blob/d381e9878187ca98815d240d3ffdf10a75993c14/pages/index.tsx#L24 for usage example
30
33
  */
31
34
  export function useInfiniteStoriesLoading(initialStories, pagination, category, include) {
32
- const currentLocale = useCurrentLocale();
33
- const { canLoadMore, data, isLoading, loadMore, resetData } = useInfiniteLoading({
34
- fetchingFn: async (nextPage, pageSize) => {
35
- const { stories } = await fetchStories(nextPage, pageSize, category, currentLocale, include);
36
- return stories;
37
- },
38
- initialData: initialStories,
39
- pagination,
40
- });
41
- useEffect(() => {
42
- if (category?.id) {
43
- resetData();
44
- }
45
- }, [category?.id, resetData]);
46
- return {
47
- canLoadMore,
48
- isLoading,
49
- loadMoreStories: loadMore,
50
- stories: data,
51
- };
52
- }
53
- //# sourceMappingURL=useInfiniteStoriesLoading.js.map
35
+ const currentLocale = useCurrentLocale();
36
+ const {
37
+ canLoadMore,
38
+ data,
39
+ isLoading,
40
+ loadMore,
41
+ resetData
42
+ } = useInfiniteLoading({
43
+ fetchingFn: async (nextPage, pageSize) => {
44
+ const {
45
+ stories
46
+ } = await fetchStories(nextPage, pageSize, category, currentLocale, include);
47
+ return stories;
48
+ },
49
+ initialData: initialStories,
50
+ pagination
51
+ });
52
+ useEffect(() => {
53
+ if (category?.id) {
54
+ resetData();
55
+ }
56
+ }, [category?.id, resetData]);
57
+ return {
58
+ canLoadMore,
59
+ isLoading,
60
+ loadMoreStories: loadMore,
61
+ stories: data
62
+ };
63
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './languages';
2
2
  export * from './locale';
3
- export { localeConfig } from './localeConfig';
3
+ export * from './localeConfig';
4
4
  export * from './localeObject';
@@ -1,5 +1,4 @@
1
- export * from './languages';
2
- export * from './locale';
3
- export { localeConfig } from './localeConfig';
4
- export * from './localeObject';
5
- //# sourceMappingURL=index.js.map
1
+ export * from "./languages.js";
2
+ export * from "./locale.js";
3
+ export * from "./localeConfig.js";
4
+ export * from "./localeObject.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intl/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intl/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}