@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.
- package/README.md +8 -13
- package/build/@types/global.d.js +1 -0
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js +26 -18
- package/build/adapter-nextjs/api-handlers/fetchStories.js +36 -20
- package/build/adapter-nextjs/api-handlers/index.js +2 -3
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +15 -10
- package/build/adapter-nextjs/getNewsroomStaticProps.js +14 -10
- package/build/adapter-nextjs/index.js +6 -7
- package/build/adapter-nextjs/page-props/category.js +115 -91
- package/build/adapter-nextjs/page-props/gallery.js +85 -61
- package/build/adapter-nextjs/page-props/galleryAlbum.js +61 -44
- package/build/adapter-nextjs/page-props/home.js +81 -62
- package/build/adapter-nextjs/page-props/index.js +8 -9
- package/build/adapter-nextjs/page-props/lib/types.js +1 -2
- package/build/adapter-nextjs/page-props/search.js +23 -24
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +28 -45
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js +12 -14
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +32 -30
- package/build/adapter-nextjs/page-props/sitemap/index.js +4 -5
- package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
- package/build/adapter-nextjs/page-props/story.js +74 -55
- package/build/adapter-nextjs/page-props/storyPreview.js +26 -21
- package/build/adapter-nextjs/processRequest.js +33 -20
- package/build/adapter-nextjs/processStaticRequest.js +18 -11
- package/build/components-nextjs/PageSeo/PageSeo.js +81 -71
- package/build/components-nextjs/PageSeo/index.js +2 -3
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +4 -5
- package/build/components-nextjs/PageSeo/lib/types.js +1 -2
- package/build/components-nextjs/StorySeo/StorySeo.js +67 -41
- package/build/components-nextjs/StorySeo/index.js +1 -2
- package/build/components-nextjs/document.js +29 -19
- package/build/components-nextjs/index.js +3 -4
- package/build/data-fetching/api/PrezlyApi.js +205 -185
- package/build/data-fetching/api/getPrezlyApi.js +20 -16
- package/build/data-fetching/api/index.js +1 -2
- package/build/data-fetching/api/queries.js +71 -34
- package/build/data-fetching/index.js +3 -4
- package/build/data-fetching/lib/getAlgoliaSettings.js +21 -17
- package/build/data-fetching/lib/getEnvVariables.js +33 -29
- package/build/data-fetching/lib/index.js +4 -5
- package/build/data-fetching/lib/isSdkError.js +2 -3
- package/build/data-fetching/lib/isUuid.js +2 -3
- package/build/data-fetching/types.js +1 -2
- package/build/index.js +9 -10
- package/build/infinite-loading/index.js +4 -5
- package/build/infinite-loading/types.js +1 -2
- package/build/infinite-loading/useInfiniteGalleriesLoading.js +41 -32
- package/build/infinite-loading/useInfiniteLoading.js +48 -37
- package/build/infinite-loading/useInfiniteStoriesLoading.js +54 -44
- package/build/intl/index.d.ts +1 -1
- package/build/intl/index.js +4 -5
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.js +135 -97
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.d.ts +0 -1
- package/build/intl/locale.js +47 -97
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.d.ts +3 -1
- package/build/intl/localeConfig.js +20 -13
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeList.js +1 -108
- package/build/intl/localeObject.js +79 -74
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.js +34 -20
- package/build/newsroom-context/hooks/index.js +11 -12
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +4 -5
- package/build/newsroom-context/hooks/useCategories.js +4 -5
- package/build/newsroom-context/hooks/useCompanyInformation.js +4 -5
- package/build/newsroom-context/hooks/useCurrentCategory.js +4 -5
- package/build/newsroom-context/hooks/useCurrentLocale.js +4 -5
- package/build/newsroom-context/hooks/useCurrentStory.js +4 -5
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +15 -15
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +48 -44
- package/build/newsroom-context/hooks/useLanguages.js +4 -5
- package/build/newsroom-context/hooks/useNewsroom.js +4 -5
- package/build/newsroom-context/hooks/useNewsroomContext.js +9 -10
- package/build/newsroom-context/index.js +2 -3
- package/build/sentry/client.js +3 -4
- package/build/sentry/common.js +25 -24
- package/build/sentry/index.js +2 -3
- package/build/sentry/server.js +3 -4
- package/build/types.js +1 -2
- package/build/utils/boilerplate.js +4 -13
- package/build/utils/constants.js +1 -2
- package/build/utils/getAssetsUrl.js +3 -4
- package/build/utils/getDataRequestLink.js +5 -7
- package/build/utils/getLocalizedCategoryData.js +30 -24
- package/build/utils/getNewsroomLogoUrl.js +12 -13
- package/build/utils/getPrivacyPortalUrl.js +10 -8
- package/build/utils/getStoryPublicationDate.js +8 -9
- package/build/utils/getUploadcareGroupUrl.js +4 -5
- package/build/utils/index.js +10 -11
- package/build/utils/isEmbargoStory.js +2 -3
- package/package.json +17 -2
- package/build/tsconfig.tsbuildinfo +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { PageSeo } from
|
|
2
|
-
export { StorySeo } from
|
|
3
|
-
export { PrezlyThemeDocument } from
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { PageSeo } from "./PageSeo/index.js";
|
|
2
|
+
export { StorySeo } from "./StorySeo/index.js";
|
|
3
|
+
export { PrezlyThemeDocument } from "./document.js";
|
|
@@ -1,194 +1,214 @@
|
|
|
1
1
|
import { createPrezlyClient } from '@prezly/sdk';
|
|
2
|
-
import { getCompanyInformation, getDefaultLanguage, getLanguageFromNextLocaleIsoCode, getLanguageFromStory, getNotifications, LocaleObject
|
|
3
|
-
import { DEFAULT_PAGE_SIZE } from
|
|
4
|
-
import { getAlgoliaSettings, isSdkError, isUuid } from
|
|
5
|
-
import { getContactsQuery, getGalleriesQuery, getSlugQuery, getSortByPublishedDate, getStoriesQuery
|
|
2
|
+
import { getCompanyInformation, getDefaultLanguage, getLanguageFromNextLocaleIsoCode, getLanguageFromStory, getNotifications, LocaleObject } from "../../intl/index.js";
|
|
3
|
+
import { DEFAULT_PAGE_SIZE } from "../../utils/index.js";
|
|
4
|
+
import { getAlgoliaSettings, isSdkError, isUuid } from "../lib/index.js";
|
|
5
|
+
import { getContactsQuery, getGalleriesQuery, getSlugQuery, getSortByPublishedDate, getStoriesQuery } from "./queries.js";
|
|
6
6
|
const CATEGORIES_SORT_ORDER = '+order';
|
|
7
7
|
const DEFAULT_SORT_ORDER = 'desc';
|
|
8
8
|
const ERROR_CODE_NOT_FOUND = 404;
|
|
9
9
|
const ERROR_CODE_FORBIDDEN = 403;
|
|
10
10
|
const ERROR_CODE_GONE = 410;
|
|
11
11
|
export class PrezlyApi {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
catch (error) {
|
|
35
|
-
if (isSdkError(error) &&
|
|
36
|
-
(error.status === ERROR_CODE_NOT_FOUND ||
|
|
37
|
-
error.status === ERROR_CODE_GONE ||
|
|
38
|
-
error.status === ERROR_CODE_FORBIDDEN)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async getNewsroom() {
|
|
45
|
-
return this.sdk.newsrooms.get(this.newsroomUuid);
|
|
46
|
-
}
|
|
47
|
-
async getNewsroomContacts() {
|
|
48
|
-
return this.sdk.newsroomContacts.search(this.newsroomUuid, {
|
|
49
|
-
query: JSON.stringify(getContactsQuery()),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async getNewsroomLanguages() {
|
|
53
|
-
return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
|
|
57
|
-
*/
|
|
58
|
-
async getAllStories(order = DEFAULT_SORT_ORDER) {
|
|
59
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
60
|
-
const newsroom = await this.getNewsroom();
|
|
61
|
-
const query = JSON.stringify(getStoriesQuery(newsroom.uuid));
|
|
62
|
-
const maxStories = newsroom.stories_number;
|
|
63
|
-
const chunkSize = 200;
|
|
64
|
-
const pages = Math.ceil(maxStories / chunkSize);
|
|
65
|
-
const storiesPromises = Array.from({ length: pages }, (_, pageIndex) => this.searchStories({
|
|
66
|
-
limit: chunkSize,
|
|
67
|
-
sortOrder,
|
|
68
|
-
query,
|
|
69
|
-
offset: pageIndex * chunkSize,
|
|
70
|
-
}));
|
|
71
|
-
const stories = (await Promise.all(storiesPromises)).flatMap((response) => response.stories);
|
|
72
|
-
return stories;
|
|
73
|
-
}
|
|
74
|
-
async getStories({ page = undefined, pageSize = DEFAULT_PAGE_SIZE, order = DEFAULT_SORT_ORDER, include, localeCode, } = {}) {
|
|
75
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
76
|
-
const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
|
|
77
|
-
const { stories, pagination } = await this.searchStories({
|
|
78
|
-
limit: pageSize,
|
|
79
|
-
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
80
|
-
sortOrder,
|
|
81
|
-
query,
|
|
82
|
-
include,
|
|
83
|
-
});
|
|
84
|
-
const storiesTotal = pagination.matched_records_number;
|
|
85
|
-
return { stories, storiesTotal };
|
|
86
|
-
}
|
|
87
|
-
async getStoriesFromCategory(category, { page = undefined, pageSize = DEFAULT_PAGE_SIZE, order = DEFAULT_SORT_ORDER, include, localeCode, } = {}) {
|
|
88
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
89
|
-
const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, category.id, localeCode));
|
|
90
|
-
const { stories, pagination } = await this.searchStories({
|
|
91
|
-
limit: pageSize,
|
|
92
|
-
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
93
|
-
sortOrder,
|
|
94
|
-
query,
|
|
95
|
-
include,
|
|
96
|
-
});
|
|
97
|
-
const storiesTotal = pagination.matched_records_number;
|
|
98
|
-
return { stories, storiesTotal };
|
|
99
|
-
}
|
|
100
|
-
async getStoryBySlug(slug) {
|
|
101
|
-
const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
|
|
102
|
-
const { stories } = await this.searchStories({
|
|
103
|
-
limit: 1,
|
|
104
|
-
query,
|
|
105
|
-
});
|
|
106
|
-
if (stories[0]) {
|
|
107
|
-
return this.getStory(stories[0].uuid);
|
|
108
|
-
}
|
|
12
|
+
constructor(accessToken, newsroomUuid, themeUuid) {
|
|
13
|
+
const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
|
|
14
|
+
this.sdk = createPrezlyClient({
|
|
15
|
+
accessToken,
|
|
16
|
+
baseUrl,
|
|
17
|
+
// This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
|
|
18
|
+
headers: {
|
|
19
|
+
'X-Convert-v1-To-v3': 'true'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
this.newsroomUuid = newsroomUuid;
|
|
23
|
+
this.themeUuid = themeUuid;
|
|
24
|
+
}
|
|
25
|
+
async getStory(uuid) {
|
|
26
|
+
if (!isUuid(uuid)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const story = await this.sdk.stories.get(uuid);
|
|
31
|
+
return story;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (isSdkError(error) && (error.status === ERROR_CODE_NOT_FOUND || error.status === ERROR_CODE_GONE || error.status === ERROR_CODE_FORBIDDEN)) {
|
|
109
34
|
return null;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async getNewsroom() {
|
|
40
|
+
return this.sdk.newsrooms.get(this.newsroomUuid);
|
|
41
|
+
}
|
|
42
|
+
async getNewsroomContacts() {
|
|
43
|
+
return this.sdk.newsroomContacts.search(this.newsroomUuid, {
|
|
44
|
+
query: JSON.stringify(getContactsQuery())
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async getNewsroomLanguages() {
|
|
48
|
+
return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
|
|
53
|
+
*/
|
|
54
|
+
async getAllStories(order = DEFAULT_SORT_ORDER) {
|
|
55
|
+
const sortOrder = getSortByPublishedDate(order);
|
|
56
|
+
const newsroom = await this.getNewsroom();
|
|
57
|
+
const query = JSON.stringify(getStoriesQuery(newsroom.uuid));
|
|
58
|
+
const maxStories = newsroom.stories_number;
|
|
59
|
+
const chunkSize = 200;
|
|
60
|
+
const pages = Math.ceil(maxStories / chunkSize);
|
|
61
|
+
const storiesPromises = Array.from({
|
|
62
|
+
length: pages
|
|
63
|
+
}, (_, pageIndex) => this.searchStories({
|
|
64
|
+
limit: chunkSize,
|
|
65
|
+
sortOrder,
|
|
66
|
+
query,
|
|
67
|
+
offset: pageIndex * chunkSize
|
|
68
|
+
}));
|
|
69
|
+
const stories = (await Promise.all(storiesPromises)).flatMap(response => response.stories);
|
|
70
|
+
return stories;
|
|
71
|
+
}
|
|
72
|
+
async getStories({
|
|
73
|
+
page = undefined,
|
|
74
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
75
|
+
order = DEFAULT_SORT_ORDER,
|
|
76
|
+
include,
|
|
77
|
+
localeCode
|
|
78
|
+
} = {}) {
|
|
79
|
+
const sortOrder = getSortByPublishedDate(order);
|
|
80
|
+
const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
|
|
81
|
+
const {
|
|
82
|
+
stories,
|
|
83
|
+
pagination
|
|
84
|
+
} = await this.searchStories({
|
|
85
|
+
limit: pageSize,
|
|
86
|
+
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
87
|
+
sortOrder,
|
|
88
|
+
query,
|
|
89
|
+
include
|
|
90
|
+
});
|
|
91
|
+
const storiesTotal = pagination.matched_records_number;
|
|
92
|
+
return {
|
|
93
|
+
stories,
|
|
94
|
+
storiesTotal
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async getStoriesFromCategory(category, {
|
|
98
|
+
page = undefined,
|
|
99
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
100
|
+
order = DEFAULT_SORT_ORDER,
|
|
101
|
+
include,
|
|
102
|
+
localeCode
|
|
103
|
+
} = {}) {
|
|
104
|
+
const sortOrder = getSortByPublishedDate(order);
|
|
105
|
+
const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, category.id, localeCode));
|
|
106
|
+
const {
|
|
107
|
+
stories,
|
|
108
|
+
pagination
|
|
109
|
+
} = await this.searchStories({
|
|
110
|
+
limit: pageSize,
|
|
111
|
+
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
112
|
+
sortOrder,
|
|
113
|
+
query,
|
|
114
|
+
include
|
|
115
|
+
});
|
|
116
|
+
const storiesTotal = pagination.matched_records_number;
|
|
117
|
+
return {
|
|
118
|
+
stories,
|
|
119
|
+
storiesTotal
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async getStoryBySlug(slug) {
|
|
123
|
+
const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
|
|
124
|
+
const {
|
|
125
|
+
stories
|
|
126
|
+
} = await this.searchStories({
|
|
127
|
+
limit: 1,
|
|
128
|
+
query
|
|
129
|
+
});
|
|
130
|
+
if (stories[0]) {
|
|
131
|
+
return this.getStory(stories[0].uuid);
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
async getCategories() {
|
|
136
|
+
const categories = await this.sdk.newsroomCategories.list(this.newsroomUuid, {
|
|
137
|
+
sortOrder: CATEGORIES_SORT_ORDER
|
|
138
|
+
});
|
|
139
|
+
return Array.isArray(categories) ? categories : Object.values(categories);
|
|
140
|
+
}
|
|
141
|
+
async getCategoryBySlug(slug) {
|
|
142
|
+
const categories = await this.getCategories();
|
|
143
|
+
return categories.find(category => Object.values(category.i18n).some(t => t.slug === slug));
|
|
144
|
+
}
|
|
145
|
+
searchStories = options => this.sdk.stories.search(options);
|
|
146
|
+
async getGalleries({
|
|
147
|
+
page,
|
|
148
|
+
pageSize
|
|
149
|
+
}) {
|
|
150
|
+
return this.sdk.newsroomGalleries.search(this.newsroomUuid, {
|
|
151
|
+
limit: pageSize,
|
|
152
|
+
offset: typeof page === 'undefined' || typeof pageSize === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
153
|
+
query: getGalleriesQuery()
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async getGallery(uuid) {
|
|
157
|
+
if (!isUuid(uuid)) {
|
|
158
|
+
// Check for legacy number ID reference, which is also supported for back-compat.
|
|
159
|
+
if (Number.isNaN(Number(uuid))) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const gallery = await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
|
|
165
|
+
return gallery;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (isSdkError(error) && error.status === 404) {
|
|
156
168
|
return null;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
|
|
176
|
+
*/
|
|
177
|
+
async getThemePreset() {
|
|
178
|
+
if (this.themeUuid) {
|
|
179
|
+
return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
async getNewsroomServerSideProps(request, nextLocaleIsoCode, story) {
|
|
184
|
+
const [newsroom, languages, categories, themePreset] = await Promise.all([this.getNewsroom(), this.getNewsroomLanguages(), this.getCategories(), this.getThemePreset()]);
|
|
185
|
+
const currentLanguage = story ? getLanguageFromStory(languages, story) : getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode);
|
|
186
|
+
const defaultLanguage = getDefaultLanguage(languages);
|
|
187
|
+
const {
|
|
188
|
+
code: localeCode
|
|
189
|
+
} = currentLanguage || defaultLanguage;
|
|
190
|
+
const locale = LocaleObject.fromAnyCode(localeCode);
|
|
191
|
+
|
|
192
|
+
// TODO: if no information given for current language, show boilerplate from default language
|
|
193
|
+
const companyInformation = getCompanyInformation(languages, locale);
|
|
194
|
+
const notifications = getNotifications(languages, locale);
|
|
195
|
+
const algoliaSettings = getAlgoliaSettings(request);
|
|
196
|
+
return {
|
|
197
|
+
newsroomContextProps: {
|
|
198
|
+
newsroom,
|
|
199
|
+
companyInformation,
|
|
200
|
+
categories,
|
|
201
|
+
languages,
|
|
202
|
+
localeCode,
|
|
203
|
+
notifications,
|
|
204
|
+
themePreset,
|
|
205
|
+
algoliaSettings
|
|
206
|
+
},
|
|
207
|
+
localeResolved: Boolean(currentLanguage)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async getNewsroomDefaultLanguage() {
|
|
211
|
+
const languages = await this.getNewsroomLanguages();
|
|
212
|
+
return getDefaultLanguage(languages);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { getEnvVariables } from
|
|
2
|
-
import { PrezlyApi } from
|
|
1
|
+
import { getEnvVariables } from "../lib/getEnvVariables.js";
|
|
2
|
+
import { PrezlyApi } from "./PrezlyApi.js";
|
|
3
3
|
export function getPrezlyApi(req) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
throw new Error('"getPrezlyApi" should only be used on back-end side.');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// `getEnvVariables` handles both cases for envs parsing - .env and request headers
|
|
9
|
+
const {
|
|
10
|
+
PREZLY_ACCESS_TOKEN,
|
|
11
|
+
PREZLY_NEWSROOM_UUID,
|
|
12
|
+
PREZLY_THEME_UUID
|
|
13
|
+
} = getEnvVariables(req);
|
|
14
|
+
if (!PREZLY_ACCESS_TOKEN) {
|
|
15
|
+
throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
|
|
16
|
+
}
|
|
17
|
+
if (!PREZLY_NEWSROOM_UUID) {
|
|
18
|
+
throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
|
|
19
|
+
}
|
|
20
|
+
return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
|
|
21
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./getPrezlyApi.js";
|
|
@@ -1,43 +1,80 @@
|
|
|
1
|
-
const publishedAndAccessible = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const publishedAndAccessible = [{
|
|
2
|
+
lifecycle_status: {
|
|
3
|
+
$in: ['published', 'embargo']
|
|
4
|
+
}
|
|
5
|
+
}, {
|
|
6
|
+
visibility: {
|
|
7
|
+
$in: ['public', 'private', 'embargo']
|
|
8
|
+
}
|
|
9
|
+
}];
|
|
10
|
+
const publishedAndPublic = [{
|
|
11
|
+
lifecycle_status: {
|
|
12
|
+
$in: ['published']
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
visibility: {
|
|
16
|
+
$in: ['public']
|
|
17
|
+
}
|
|
18
|
+
}];
|
|
9
19
|
export function getSlugQuery(newsroomUuid, slug) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
return {
|
|
21
|
+
$and: [{
|
|
22
|
+
'newsroom.uuid': {
|
|
23
|
+
$in: [newsroomUuid]
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
slug: {
|
|
27
|
+
$eq: slug
|
|
28
|
+
}
|
|
29
|
+
}, ...publishedAndAccessible]
|
|
30
|
+
};
|
|
17
31
|
}
|
|
18
32
|
export function getStoriesQuery(newsroomUuid, categoryId, localeCode) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
const query = {
|
|
34
|
+
$and: [...publishedAndPublic, {
|
|
35
|
+
'newsroom.uuid': {
|
|
36
|
+
$in: [newsroomUuid]
|
|
37
|
+
}
|
|
38
|
+
}]
|
|
39
|
+
};
|
|
40
|
+
if (categoryId) {
|
|
41
|
+
query.$and.push({
|
|
42
|
+
'category.id': {
|
|
43
|
+
$any: [categoryId]
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (localeCode) {
|
|
48
|
+
query.$and.push({
|
|
49
|
+
locale: {
|
|
50
|
+
$in: [localeCode]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return query;
|
|
29
55
|
}
|
|
30
56
|
export function getSortByPublishedDate(order) {
|
|
31
|
-
|
|
57
|
+
return order === 'desc' ? '-published_at' : 'published_at';
|
|
32
58
|
}
|
|
33
59
|
export function getGalleriesQuery() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
return {
|
|
61
|
+
$and: [{
|
|
62
|
+
status: {
|
|
63
|
+
$eq: 'public'
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
images_number: {
|
|
67
|
+
$gt: 0
|
|
68
|
+
}
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
37
71
|
}
|
|
38
72
|
export function getContactsQuery() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
return {
|
|
74
|
+
$and: [{
|
|
75
|
+
is_featured: {
|
|
76
|
+
$eq: true
|
|
77
|
+
}
|
|
78
|
+
}]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./api/index.js";
|
|
2
|
+
export * from "./lib/index.js";
|
|
3
|
+
export * from "./types.js";
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { getEnvVariables } from
|
|
1
|
+
import { getEnvVariables } from "./getEnvVariables.js";
|
|
2
2
|
export function getAlgoliaSettings(req) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// `getEnvVariables` handles both cases for envs parsing - .env and request headers
|
|
8
|
+
const {
|
|
9
|
+
ALGOLIA_API_KEY = '',
|
|
10
|
+
ALGOLIA_APP_ID = 'UI4CNRAHQB',
|
|
11
|
+
ALGOLIA_INDEX = 'public_stories_prod'
|
|
12
|
+
} = getEnvVariables(req);
|
|
13
|
+
if (!ALGOLIA_API_KEY) {
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
15
|
+
console.error('"ALGOLIA_API_KEY" is not set in env variables. Search will not be enabled');
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
ALGOLIA_API_KEY,
|
|
19
|
+
ALGOLIA_APP_ID,
|
|
20
|
+
ALGOLIA_INDEX
|
|
21
|
+
};
|
|
22
|
+
}
|