@prezly/theme-kit-nextjs 1.18.2 → 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.
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js +3 -7
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +3 -7
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/index.js +2 -7
- package/build/adapter-nextjs/api-handlers/index.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +3 -7
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +3 -7
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/index.js +6 -22
- package/build/adapter-nextjs/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.d.ts +2 -2
- package/build/adapter-nextjs/page-props/category.js +19 -25
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +13 -18
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +13 -19
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.d.ts +2 -2
- package/build/adapter-nextjs/page-props/home.js +13 -18
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/index.js +8 -41
- package/build/adapter-nextjs/page-props/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/lib/types.js +1 -2
- package/build/adapter-nextjs/page-props/search.js +10 -15
- package/build/adapter-nextjs/page-props/search.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +1 -5
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js +1 -5
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +7 -11
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/index.js +4 -24
- package/build/adapter-nextjs/page-props/sitemap/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
- package/build/adapter-nextjs/page-props/story.js +17 -23
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +7 -11
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +5 -9
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/adapter-nextjs/processStaticRequest.js +1 -5
- package/build/adapter-nextjs/processStaticRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +25 -29
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/index.js +2 -20
- package/build/components-nextjs/PageSeo/index.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +1 -5
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/types.js +1 -2
- package/build/components-nextjs/StorySeo/StorySeo.js +7 -11
- package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/components-nextjs/StorySeo/index.js +1 -5
- package/build/components-nextjs/StorySeo/index.js.map +1 -1
- package/build/components-nextjs/document.js +8 -35
- package/build/components-nextjs/document.js.map +1 -1
- package/build/components-nextjs/index.js +3 -9
- package/build/components-nextjs/index.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +4 -5
- package/build/data-fetching/api/PrezlyApi.js +39 -44
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +5 -9
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/index.js +1 -17
- package/build/data-fetching/api/index.js.map +1 -1
- package/build/data-fetching/api/queries.js +5 -13
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/index.js +3 -19
- package/build/data-fetching/index.js.map +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.js +3 -7
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +3 -10
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/data-fetching/lib/index.js +4 -11
- package/build/data-fetching/lib/index.js.map +1 -1
- package/build/data-fetching/lib/isSdkError.js +1 -5
- package/build/data-fetching/lib/isSdkError.js.map +1 -1
- package/build/data-fetching/lib/isUuid.js +1 -5
- package/build/data-fetching/lib/isUuid.js.map +1 -1
- package/build/data-fetching/types.js +1 -2
- package/build/index.js +9 -25
- package/build/index.js.map +1 -1
- package/build/infinite-loading/index.js +4 -24
- package/build/infinite-loading/index.js.map +1 -1
- package/build/infinite-loading/types.js +1 -2
- package/build/infinite-loading/useInfiniteGalleriesLoading.js +3 -7
- package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +9 -13
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.d.ts +2 -2
- package/build/infinite-loading/useInfiniteStoriesLoading.js +7 -11
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/index.d.ts +1 -1
- package/build/intl/index.js +4 -25
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.d.ts +1 -1
- package/build/intl/languages.js +23 -37
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.js +11 -17
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.d.ts +1 -2
- package/build/intl/localeConfig.js +3 -4
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeList.d.ts +4 -2
- package/build/intl/localeList.js +1 -2
- package/build/intl/localeList.js.map +1 -1
- package/build/intl/localeObject.js +3 -10
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.js +7 -11
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/index.js +11 -27
- package/build/newsroom-context/hooks/index.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +3 -7
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.js +3 -7
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +3 -7
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.js +3 -7
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +3 -7
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.js +3 -7
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +10 -14
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +24 -31
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +3 -7
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +3 -7
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.js +4 -8
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/newsroom-context/index.js +2 -21
- package/build/newsroom-context/index.js.map +1 -1
- package/build/sentry/client.js +3 -7
- package/build/sentry/client.js.map +1 -1
- package/build/sentry/common.js +1 -5
- package/build/sentry/common.js.map +1 -1
- package/build/sentry/index.js +2 -7
- package/build/sentry/index.js.map +1 -1
- package/build/sentry/server.js +3 -7
- package/build/sentry/server.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -2
- package/build/utils/boilerplate.js +3 -9
- package/build/utils/boilerplate.js.map +1 -1
- package/build/utils/constants.js +3 -6
- package/build/utils/constants.js.map +1 -1
- package/build/utils/getAssetsUrl.js +3 -7
- package/build/utils/getAssetsUrl.js.map +1 -1
- package/build/utils/getDataRequestLink.js +3 -7
- package/build/utils/getDataRequestLink.js.map +1 -1
- package/build/utils/getLocalizedCategoryData.js +3 -9
- package/build/utils/getLocalizedCategoryData.js.map +1 -1
- package/build/utils/getNewsroomLogoUrl.js +5 -10
- package/build/utils/getNewsroomLogoUrl.js.map +1 -1
- package/build/utils/getPrivacyPortalUrl.js +1 -5
- package/build/utils/getPrivacyPortalUrl.js.map +1 -1
- package/build/utils/getStoryPublicationDate.js +1 -5
- package/build/utils/getStoryPublicationDate.js.map +1 -1
- package/build/utils/getUploadcareGroupUrl.js +3 -7
- package/build/utils/getUploadcareGroupUrl.js.map +1 -1
- package/build/utils/index.js +10 -26
- package/build/utils/index.js.map +1 -1
- package/build/utils/isEmbargoStory.js +1 -5
- package/build/utils/isEmbargoStory.js.map +1 -1
- package/package.json +17 -17
- package/src/@types/global.d.ts +0 -7
- package/src/__mocks__/languages.ts +0 -417
- package/src/__mocks__/story.ts +0 -351
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -26
- package/src/adapter-nextjs/api-handlers/index.ts +0 -2
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +0 -29
- package/src/adapter-nextjs/getNewsroomStaticProps.ts +0 -29
- package/src/adapter-nextjs/index.ts +0 -6
- package/src/adapter-nextjs/page-props/category.ts +0 -157
- package/src/adapter-nextjs/page-props/gallery.ts +0 -114
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +0 -89
- package/src/adapter-nextjs/page-props/home.ts +0 -113
- package/src/adapter-nextjs/page-props/index.ts +0 -26
- package/src/adapter-nextjs/page-props/lib/types.ts +0 -8
- package/src/adapter-nextjs/page-props/search.ts +0 -53
- package/src/adapter-nextjs/page-props/sitemap/SitemapBuilder.ts +0 -56
- package/src/adapter-nextjs/page-props/sitemap/createPaths.ts +0 -21
- package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +0 -43
- package/src/adapter-nextjs/page-props/sitemap/index.ts +0 -5
- package/src/adapter-nextjs/page-props/sitemap/types.ts +0 -5
- package/src/adapter-nextjs/page-props/story.ts +0 -94
- package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
- package/src/adapter-nextjs/processRequest.ts +0 -49
- package/src/adapter-nextjs/processStaticRequest.ts +0 -32
- package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -131
- package/src/components-nextjs/PageSeo/index.ts +0 -2
- package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
- package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
- package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -80
- package/src/components-nextjs/StorySeo/index.ts +0 -1
- package/src/components-nextjs/document.tsx +0 -38
- package/src/components-nextjs/index.ts +0 -3
- package/src/data-fetching/api/PrezlyApi.ts +0 -302
- package/src/data-fetching/api/getPrezlyApi.ts +0 -24
- package/src/data-fetching/api/index.ts +0 -1
- package/src/data-fetching/api/queries.ts +0 -51
- package/src/data-fetching/index.ts +0 -3
- package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
- package/src/data-fetching/lib/getEnvVariables.ts +0 -46
- package/src/data-fetching/lib/index.ts +0 -4
- package/src/data-fetching/lib/isSdkError.ts +0 -5
- package/src/data-fetching/lib/isUuid.ts +0 -5
- package/src/data-fetching/types.ts +0 -14
- package/src/index.ts +0 -9
- package/src/infinite-loading/index.ts +0 -4
- package/src/infinite-loading/types.ts +0 -5
- package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -53
- package/src/infinite-loading/useInfiniteLoading.ts +0 -66
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -81
- package/src/intl/index.ts +0 -4
- package/src/intl/languages.test.ts +0 -232
- package/src/intl/languages.ts +0 -233
- package/src/intl/locale.test.ts +0 -94
- package/src/intl/locale.ts +0 -140
- package/src/intl/localeConfig.js +0 -23
- package/src/intl/localeList.js +0 -110
- package/src/intl/localeObject.test.ts +0 -81
- package/src/intl/localeObject.ts +0 -99
- package/src/newsroom-context/context.tsx +0 -115
- package/src/newsroom-context/hooks/index.ts +0 -11
- package/src/newsroom-context/hooks/useAlgoliaSettings.ts +0 -7
- package/src/newsroom-context/hooks/useCategories.ts +0 -7
- package/src/newsroom-context/hooks/useCompanyInformation.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentCategory.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentLocale.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentStory.ts +0 -7
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +0 -37
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -96
- package/src/newsroom-context/hooks/useLanguages.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroom.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroomContext.ts +0 -15
- package/src/newsroom-context/index.ts +0 -2
- package/src/sentry/client.ts +0 -7
- package/src/sentry/common.ts +0 -27
- package/src/sentry/index.ts +0 -2
- package/src/sentry/server.ts +0 -7
- package/src/types.ts +0 -51
- package/src/utils/boilerplate.ts +0 -27
- package/src/utils/constants.ts +0 -3
- package/src/utils/getAssetsUrl.test.ts +0 -9
- package/src/utils/getAssetsUrl.ts +0 -9
- package/src/utils/getDataRequestLink.ts +0 -14
- package/src/utils/getLocalizedCategoryData.ts +0 -47
- package/src/utils/getNewsroomLogoUrl.ts +0 -22
- package/src/utils/getPrivacyPortalUrl.ts +0 -25
- package/src/utils/getStoryPublicationDate.tsx +0 -15
- package/src/utils/getUploadcareGroupUrl.ts +0 -13
- package/src/utils/index.ts +0 -10
- package/src/utils/isEmbargoStory.ts +0 -10
package/src/intl/localeObject.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import localeConfig from './localeConfig';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This class is created to simplify working with locales and transforming between different locale code formats.
|
|
5
|
-
* Prezly API uses underscore-codes, while most frontend application tend to use hyphen-codes or slugs.
|
|
6
|
-
* Note that `fromAnyCode` constructor only accepts locales supported by Prezly backend. See `localeConfig` for reference.
|
|
7
|
-
*/
|
|
8
|
-
export class LocaleObject {
|
|
9
|
-
/**
|
|
10
|
-
* Hyphen-separated locale code.
|
|
11
|
-
* Examples: `nl-BE`, `en-US`, `fr`, `fil`
|
|
12
|
-
*/
|
|
13
|
-
private localeCode: string;
|
|
14
|
-
|
|
15
|
-
private constructor(localeCode: string) {
|
|
16
|
-
if (!/^([a-z]{2,3})(-[a-z\d]{1,4})?$/i.test(localeCode)) {
|
|
17
|
-
throw new Error('Invalid locale code provided!');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const [language, region] = localeCode.split('-');
|
|
21
|
-
|
|
22
|
-
if (region) {
|
|
23
|
-
// Workaround for `zh-Hant` locale, which is the only locale with non-uppercase region part
|
|
24
|
-
const regionSuffix = region === 'hant' ? 'Hant' : region.toUpperCase();
|
|
25
|
-
|
|
26
|
-
this.localeCode = [language, regionSuffix].join('-');
|
|
27
|
-
} else {
|
|
28
|
-
this.localeCode = language;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param localeCode Locale code in any of the formats below.
|
|
34
|
-
* Examples:
|
|
35
|
-
* - Hyphen-codes: `nl-BE`, `en-US`, `fr`, `fil`
|
|
36
|
-
* - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
|
|
37
|
-
* - Slugs: `nl-be`, `en-us`, `fr`, `fil`
|
|
38
|
-
*/
|
|
39
|
-
public static fromAnyCode(localeCode: string): LocaleObject {
|
|
40
|
-
const lowercaseCode = localeCode.toLowerCase().replace('_', '-');
|
|
41
|
-
const foundCode = localeConfig.find((code) => code === lowercaseCode);
|
|
42
|
-
|
|
43
|
-
if (!foundCode) {
|
|
44
|
-
throw new Error(`Unsupported locale code provided: "${lowercaseCode}"`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return new LocaleObject(foundCode);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @returns Code formatted into hyphen format: `nl-BE`, `en-US`, `fr`, `fil`
|
|
52
|
-
*/
|
|
53
|
-
public toHyphenCode(): string {
|
|
54
|
-
return this.localeCode;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @returns Code formatted into underscore format, as expected by Prezly API: `nl_BE`, `en_US`, `fr`, `fil`
|
|
59
|
-
*/
|
|
60
|
-
public toUnderscoreCode(): string {
|
|
61
|
-
return this.localeCode.replace('-', '_');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @returns Code formatted to a URL-friendly lowercase slug format: `nl-be`, `en-us`, `fr`, `fil`
|
|
66
|
-
*/
|
|
67
|
-
public toUrlSlug(): string {
|
|
68
|
-
return this.localeCode.toLowerCase();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @returns Only the language part of the code without culture/region part: `nl`, `en`, `fr`
|
|
73
|
-
*/
|
|
74
|
-
public toNeutralLanguageCode(): string {
|
|
75
|
-
const [language] = this.localeCode.split('-');
|
|
76
|
-
|
|
77
|
-
return language;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
82
|
-
*/
|
|
83
|
-
public toRegionCode(): string {
|
|
84
|
-
const [language, region] = this.localeCode.split('-');
|
|
85
|
-
|
|
86
|
-
if (!region) {
|
|
87
|
-
return language.toUpperCase();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return region.toUpperCase();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Check if two LocaleObject instances are representing the same locale code.
|
|
95
|
-
*/
|
|
96
|
-
public isEqual(anotherLocale: LocaleObject) {
|
|
97
|
-
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Category,
|
|
3
|
-
ExtendedStory,
|
|
4
|
-
Newsroom,
|
|
5
|
-
NewsroomCompanyInformation,
|
|
6
|
-
NewsroomContact,
|
|
7
|
-
NewsroomLanguageSettings,
|
|
8
|
-
NewsroomThemePreset,
|
|
9
|
-
Notification,
|
|
10
|
-
} from '@prezly/sdk';
|
|
11
|
-
import type { PropsWithChildren } from 'react';
|
|
12
|
-
import { createContext, useMemo } from 'react';
|
|
13
|
-
|
|
14
|
-
import type { AlgoliaSettings } from '../data-fetching';
|
|
15
|
-
import { DEFAULT_LOCALE, LocaleObject } from '../intl';
|
|
16
|
-
|
|
17
|
-
export interface NewsroomContextType {
|
|
18
|
-
/**
|
|
19
|
-
* Basic newsroom information: newsroom logos, settings, etc.
|
|
20
|
-
*/
|
|
21
|
-
newsroom: Newsroom;
|
|
22
|
-
/**
|
|
23
|
-
* Contact information of the newsroom in the default language, usually displayed in the "About" section
|
|
24
|
-
*/
|
|
25
|
-
companyInformation: NewsroomCompanyInformation;
|
|
26
|
-
/**
|
|
27
|
-
* List of all categories enabled on the newsroom
|
|
28
|
-
*/
|
|
29
|
-
categories: Category[];
|
|
30
|
-
/**
|
|
31
|
-
* Optional: Contacts set up to be displayed on the newsroom home page.
|
|
32
|
-
* Will only be loaded if `loadHomepageContacts` option of `getNewsroomServerSideProps` is set to `true`.
|
|
33
|
-
*/
|
|
34
|
-
contacts?: NewsroomContact[];
|
|
35
|
-
/**
|
|
36
|
-
* Optional: Refers to a currently selected category when navigated to `/category/[slug]` page.
|
|
37
|
-
*/
|
|
38
|
-
currentCategory?: Category;
|
|
39
|
-
/**
|
|
40
|
-
* Optional: Refers to a currently selected story when navigated to `/[slug]` page.
|
|
41
|
-
*/
|
|
42
|
-
currentStory?: ExtendedStory;
|
|
43
|
-
/**
|
|
44
|
-
* List of currently enabled newsroom languages, as well as company information translated for each language
|
|
45
|
-
*/
|
|
46
|
-
languages: NewsroomLanguageSettings[];
|
|
47
|
-
/**
|
|
48
|
-
* Currently chosen locale
|
|
49
|
-
*/
|
|
50
|
-
locale: LocaleObject;
|
|
51
|
-
/**
|
|
52
|
-
* Newsroom user-facing notifications (usually displayed as top-edge banners)
|
|
53
|
-
*/
|
|
54
|
-
notifications: Notification[];
|
|
55
|
-
/**
|
|
56
|
-
* Theme settings as set in the Prezly app.
|
|
57
|
-
* You need to provide `PREZLY_THEME_UUID` in environment variables in order for the preset to be loaded.
|
|
58
|
-
* Only applicable to themes hosted on the Prezly infrastructure.
|
|
59
|
-
*/
|
|
60
|
-
themePreset: NewsroomThemePreset | null;
|
|
61
|
-
/**
|
|
62
|
-
* Environment variables required for Algolia search to work.
|
|
63
|
-
*/
|
|
64
|
-
algoliaSettings: AlgoliaSettings;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
68
|
-
localeCode: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const NewsroomContext = createContext<NewsroomContextType | undefined>(undefined);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
75
|
-
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
76
|
-
*/
|
|
77
|
-
export function NewsroomContextProvider({
|
|
78
|
-
categories,
|
|
79
|
-
contacts,
|
|
80
|
-
newsroom,
|
|
81
|
-
currentCategory,
|
|
82
|
-
currentStory,
|
|
83
|
-
companyInformation,
|
|
84
|
-
languages,
|
|
85
|
-
localeCode,
|
|
86
|
-
notifications,
|
|
87
|
-
themePreset,
|
|
88
|
-
algoliaSettings,
|
|
89
|
-
children,
|
|
90
|
-
}: PropsWithChildren<NewsroomContextProps>) {
|
|
91
|
-
const locale = useMemo(
|
|
92
|
-
() => LocaleObject.fromAnyCode(localeCode || DEFAULT_LOCALE),
|
|
93
|
-
[localeCode],
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<NewsroomContext.Provider
|
|
98
|
-
value={{
|
|
99
|
-
categories,
|
|
100
|
-
contacts,
|
|
101
|
-
newsroom,
|
|
102
|
-
currentCategory,
|
|
103
|
-
currentStory,
|
|
104
|
-
companyInformation,
|
|
105
|
-
languages,
|
|
106
|
-
locale,
|
|
107
|
-
notifications,
|
|
108
|
-
themePreset,
|
|
109
|
-
algoliaSettings,
|
|
110
|
-
}}
|
|
111
|
-
>
|
|
112
|
-
{children}
|
|
113
|
-
</NewsroomContext.Provider>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './useAlgoliaSettings';
|
|
2
|
-
export * from './useCategories';
|
|
3
|
-
export * from './useCompanyInformation';
|
|
4
|
-
export * from './useCurrentCategory';
|
|
5
|
-
export * from './useCurrentLocale';
|
|
6
|
-
export * from './useCurrentStory';
|
|
7
|
-
export * from './useGetLinkLocaleSlug';
|
|
8
|
-
export * from './useGetTranslationUrl';
|
|
9
|
-
export * from './useLanguages';
|
|
10
|
-
export * from './useNewsroom';
|
|
11
|
-
export * from './useNewsroomContext';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { NewsroomLanguageSettings } from '@prezly/sdk';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
import { getShortestLocaleCode, LocaleObject } from '../../intl';
|
|
5
|
-
|
|
6
|
-
import { useCurrentLocale } from './useCurrentLocale';
|
|
7
|
-
import { useLanguages } from './useLanguages';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Determines correct locale slug for the link (trying to shorten the locale code if possible).
|
|
11
|
-
* E.g. if newsroom has a single locale for Dutch (`nl_BE`), it will be shortened to `nl`.
|
|
12
|
-
* If there are more than one locale with the same language part, a full locale code will be used instead.
|
|
13
|
-
* `false` means that a default locale should be used (no locale in URL required).
|
|
14
|
-
*/
|
|
15
|
-
function getLinkLocaleSlug(
|
|
16
|
-
languages: NewsroomLanguageSettings[],
|
|
17
|
-
locale: LocaleObject,
|
|
18
|
-
): string | false {
|
|
19
|
-
const shortestLocaleCode = getShortestLocaleCode(languages, locale);
|
|
20
|
-
// When navigating to default language, we don't append the locale to the URL.
|
|
21
|
-
if (!shortestLocaleCode) {
|
|
22
|
-
return shortestLocaleCode;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function useGetLinkLocaleSlug() {
|
|
29
|
-
const currentLocale = useCurrentLocale();
|
|
30
|
-
const languages = useLanguages();
|
|
31
|
-
|
|
32
|
-
// The `locale` parameter is mainly used for Language Dropdown
|
|
33
|
-
return useCallback(
|
|
34
|
-
(locale?: LocaleObject) => getLinkLocaleSlug(languages, locale || currentLocale),
|
|
35
|
-
[languages, currentLocale],
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { Category, ExtendedStory } from '@prezly/sdk';
|
|
2
|
-
import { useRouter } from 'next/router';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
|
|
5
|
-
import type { LocaleObject } from '../../intl';
|
|
6
|
-
import { getCategoryHasTranslation, getCategoryUrl } from '../../utils';
|
|
7
|
-
|
|
8
|
-
import { useCurrentCategory } from './useCurrentCategory';
|
|
9
|
-
import { useCurrentStory } from './useCurrentStory';
|
|
10
|
-
|
|
11
|
-
// Pulled from SDK types to not leak the `@prezly/sdk` dependency into the client bundle
|
|
12
|
-
enum StoryVisibility {
|
|
13
|
-
PUBLIC = 'public',
|
|
14
|
-
EMBARGO = 'embargo',
|
|
15
|
-
PRIVATE = 'private',
|
|
16
|
-
CONFIDENTIAL = 'confidential',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getAllowedTranslationVisibilityValues(story: ExtendedStory): StoryVisibility[] {
|
|
20
|
-
const { visibility } = story;
|
|
21
|
-
|
|
22
|
-
switch (visibility) {
|
|
23
|
-
case StoryVisibility.EMBARGO:
|
|
24
|
-
return [StoryVisibility.EMBARGO, StoryVisibility.PUBLIC];
|
|
25
|
-
case StoryVisibility.PRIVATE:
|
|
26
|
-
return [StoryVisibility.PRIVATE, StoryVisibility.PUBLIC];
|
|
27
|
-
case StoryVisibility.CONFIDENTIAL:
|
|
28
|
-
return [StoryVisibility.CONFIDENTIAL, StoryVisibility.PRIVATE, StoryVisibility.PUBLIC];
|
|
29
|
-
default:
|
|
30
|
-
return [StoryVisibility.PUBLIC];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Determine correct URL for translated stories/categories with a fallback to homepage.
|
|
36
|
-
* E.g. if a story has a translation, the function will return the localized slug URL.
|
|
37
|
-
* If there is no translation for the story, it will return the index page URL (`/`),
|
|
38
|
-
* or empty string, if `noFallback` is set to `true` (this is useful for alternate locale links).
|
|
39
|
-
*/
|
|
40
|
-
function getTranslationUrl(
|
|
41
|
-
locale: LocaleObject,
|
|
42
|
-
path: string,
|
|
43
|
-
currentCategory?: Category,
|
|
44
|
-
currentStory?: ExtendedStory,
|
|
45
|
-
noFallback?: boolean,
|
|
46
|
-
) {
|
|
47
|
-
if (currentCategory) {
|
|
48
|
-
if (getCategoryHasTranslation(currentCategory, locale)) {
|
|
49
|
-
return getCategoryUrl(currentCategory, locale);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (noFallback) {
|
|
53
|
-
return '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return '/';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const localeCode = locale.toUnderscoreCode();
|
|
60
|
-
|
|
61
|
-
if (currentStory && currentStory.culture.locale !== localeCode) {
|
|
62
|
-
const allowedVisibilityValues = getAllowedTranslationVisibilityValues(currentStory);
|
|
63
|
-
|
|
64
|
-
const translatedStory = currentStory.translations.find(
|
|
65
|
-
({ culture, visibility }) =>
|
|
66
|
-
culture.locale === localeCode && allowedVisibilityValues.includes(visibility),
|
|
67
|
-
);
|
|
68
|
-
if (translatedStory) {
|
|
69
|
-
return `/${translatedStory.slug}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (noFallback) {
|
|
73
|
-
return '';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return '/';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return path;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
84
|
-
* `noFallback` parameter is useful for alternate language links in the `head` section of the document (so that there are no unwanted links to the homepage).
|
|
85
|
-
*/
|
|
86
|
-
export function useGetTranslationUrl() {
|
|
87
|
-
const { asPath } = useRouter();
|
|
88
|
-
const currentCategory = useCurrentCategory();
|
|
89
|
-
const currentStory = useCurrentStory();
|
|
90
|
-
|
|
91
|
-
return useCallback(
|
|
92
|
-
(locale: LocaleObject, noFallback?: boolean) =>
|
|
93
|
-
getTranslationUrl(locale, asPath, currentCategory, currentStory, noFallback),
|
|
94
|
-
[asPath, currentCategory, currentStory],
|
|
95
|
-
);
|
|
96
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { NewsroomContextType } from '../context';
|
|
4
|
-
import { NewsroomContext } from '../context';
|
|
5
|
-
|
|
6
|
-
export function useNewsroomContext() {
|
|
7
|
-
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
8
|
-
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
9
|
-
const newsroomContext: NewsroomContextType | undefined = useContext(NewsroomContext);
|
|
10
|
-
if (!newsroomContext) {
|
|
11
|
-
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return newsroomContext;
|
|
15
|
-
}
|
package/src/sentry/client.ts
DELETED
package/src/sentry/common.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { init } from '@sentry/nextjs';
|
|
2
|
-
|
|
3
|
-
export function getCommonClientOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
|
|
4
|
-
return {
|
|
5
|
-
dsn,
|
|
6
|
-
// Adjust this value in production, or use tracesSampler for greater control
|
|
7
|
-
tracesSampleRate: 0.02,
|
|
8
|
-
// ...
|
|
9
|
-
// Note: if you want to override the automatic release value, do not set a
|
|
10
|
-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
|
|
11
|
-
// that it will also get attached to your source maps
|
|
12
|
-
|
|
13
|
-
ignoreErrors: [
|
|
14
|
-
// This particular error is coming from Microsoft Outlook SafeLink crawler.
|
|
15
|
-
// It doesn't affect the user experience in any way, but produces a lot of unwanted Sentry events.
|
|
16
|
-
// See https://forum.sentry.io/t/unhandledrejection-non-error-promise-rejection-captured-with-value/14062
|
|
17
|
-
'Object Not Found Matching Id',
|
|
18
|
-
// This error is caused by `beacon.min.js` polyfill in Cloudflare Insights. From what we see, it doesn't affect the user experience.
|
|
19
|
-
'Illegal invocation',
|
|
20
|
-
],
|
|
21
|
-
// Attach theme tag to each event
|
|
22
|
-
initialScope: (scope) => {
|
|
23
|
-
scope.setTags({ prezly_theme: themeName });
|
|
24
|
-
return scope;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
package/src/sentry/index.ts
DELETED
package/src/sentry/server.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { NewsroomContextProps } from './newsroom-context';
|
|
4
|
-
|
|
5
|
-
export interface ServerSidePageProps {
|
|
6
|
-
/**
|
|
7
|
-
* Indicates whether the locale requested by the Next application was correctly resolved to an active newsroom locale.
|
|
8
|
-
* This is used by `processRequest` method to redirect to the default locale if the property is `false`.
|
|
9
|
-
*/
|
|
10
|
-
localeResolved: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* These are the props returned by the `processRequest` method that are meant to be passed to your `_app` to be injected into the `NewsroomContextProvider`.
|
|
15
|
-
*/
|
|
16
|
-
export interface PageProps {
|
|
17
|
-
newsroomContextProps: NewsroomContextProps;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Categories in Algolia index are stored in a simplified format, with `slug` and `name` properties already saved in the correct locale for the story search result.
|
|
22
|
-
*/
|
|
23
|
-
export interface AlgoliaCategoryRef {
|
|
24
|
-
id: number;
|
|
25
|
-
name: string;
|
|
26
|
-
slug: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Stories in Algolia index are stored in a simplified format, with only minimal subset of fields.
|
|
31
|
-
*/
|
|
32
|
-
export type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> &
|
|
33
|
-
Pick<ExtraStoryFields, 'thumbnail_image'> & {
|
|
34
|
-
content_text: string;
|
|
35
|
-
updated_at: number;
|
|
36
|
-
published_at: number;
|
|
37
|
-
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
38
|
-
categories: AlgoliaCategoryRef[];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// TODO: This should be exported from `@prezly/sdk`
|
|
42
|
-
export interface SdkError extends Error {
|
|
43
|
-
status: number;
|
|
44
|
-
statusText: string;
|
|
45
|
-
payload: {
|
|
46
|
-
errors: {
|
|
47
|
-
reason: string;
|
|
48
|
-
};
|
|
49
|
-
message: string;
|
|
50
|
-
};
|
|
51
|
-
}
|
package/src/utils/boilerplate.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { NewsroomCompanyInformation } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
export function hasAnySocialMedia(companyInformation: NewsroomCompanyInformation): boolean {
|
|
4
|
-
return Boolean(
|
|
5
|
-
companyInformation.facebook ||
|
|
6
|
-
companyInformation.instagram ||
|
|
7
|
-
companyInformation.linkedin ||
|
|
8
|
-
companyInformation.pinterest ||
|
|
9
|
-
companyInformation.tiktok ||
|
|
10
|
-
companyInformation.twitter ||
|
|
11
|
-
companyInformation.youtube,
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function hasAnyAboutInformation(companyInformation: NewsroomCompanyInformation): boolean {
|
|
16
|
-
return Boolean(
|
|
17
|
-
companyInformation.about ||
|
|
18
|
-
companyInformation.website ||
|
|
19
|
-
hasAnySocialMedia(companyInformation),
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function hasAnyContactInformation(companyInformation: NewsroomCompanyInformation): boolean {
|
|
24
|
-
return Boolean(
|
|
25
|
-
companyInformation.address || companyInformation.phone || companyInformation.email,
|
|
26
|
-
);
|
|
27
|
-
}
|
package/src/utils/constants.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ASSETS_URL } from './constants';
|
|
2
|
-
import { getAssetsUrl } from './getAssetsUrl';
|
|
3
|
-
|
|
4
|
-
describe('getAssetsUrl', () => {
|
|
5
|
-
it('generates correct asset URL with uuid passed to it', () => {
|
|
6
|
-
const uuid = 'foo-bar';
|
|
7
|
-
expect(getAssetsUrl(uuid)).toBe(`${ASSETS_URL}/${uuid}/`);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ASSETS_URL } from './constants';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param uuid UUID of the assets hosted on Uploadcare
|
|
5
|
-
* @returns Full asset URL that can be used as a source for <img>, <video> and <a> tags.
|
|
6
|
-
*/
|
|
7
|
-
export function getAssetsUrl(uuid: string) {
|
|
8
|
-
return `${ASSETS_URL}/${uuid}/`;
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Newsroom } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { LocaleObject } from '../intl';
|
|
4
|
-
|
|
5
|
-
import { getPrivacyPortalUrl } from './getPrivacyPortalUrl';
|
|
6
|
-
|
|
7
|
-
export function getDataRequestLink(newsroom: Newsroom, currentLocale: LocaleObject) {
|
|
8
|
-
return (
|
|
9
|
-
newsroom.custom_data_request_link ||
|
|
10
|
-
getPrivacyPortalUrl(newsroom, currentLocale, {
|
|
11
|
-
action: 'data-request',
|
|
12
|
-
})
|
|
13
|
-
);
|
|
14
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Category } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { LocaleObject } from '../intl';
|
|
4
|
-
import type { AlgoliaCategoryRef } from '../types';
|
|
5
|
-
|
|
6
|
-
function isAlgoliaCategory(
|
|
7
|
-
category: Category | AlgoliaCategoryRef,
|
|
8
|
-
): category is AlgoliaCategoryRef {
|
|
9
|
-
return 'name' in category && 'slug' in category;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getLocalizedCategoryData(
|
|
13
|
-
category: Category | AlgoliaCategoryRef,
|
|
14
|
-
locale: LocaleObject,
|
|
15
|
-
) {
|
|
16
|
-
if (isAlgoliaCategory(category)) {
|
|
17
|
-
return {
|
|
18
|
-
description: null,
|
|
19
|
-
name: category.name,
|
|
20
|
-
slug: category.slug,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const targetLocaleCode = locale.toUnderscoreCode();
|
|
25
|
-
const { i18n } = category;
|
|
26
|
-
const populatedLocales = Object.keys(i18n).filter((localeCode) => i18n[localeCode].name);
|
|
27
|
-
const targetLocale =
|
|
28
|
-
populatedLocales.find((localeCode) => localeCode === targetLocaleCode) ||
|
|
29
|
-
populatedLocales.find((localeCode) => i18n[localeCode].name === category.display_name) ||
|
|
30
|
-
populatedLocales[0];
|
|
31
|
-
|
|
32
|
-
const { locale: _, ...localizedData } = i18n[targetLocale];
|
|
33
|
-
|
|
34
|
-
return localizedData;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function getCategoryUrl(category: Category | AlgoliaCategoryRef, locale: LocaleObject) {
|
|
38
|
-
const { slug } = getLocalizedCategoryData(category, locale);
|
|
39
|
-
return `/category/${slug}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getCategoryHasTranslation(category: Category, locale: LocaleObject) {
|
|
43
|
-
const targetLocaleCode = locale.toUnderscoreCode();
|
|
44
|
-
const { i18n } = category;
|
|
45
|
-
const populatedLocales = Object.keys(i18n).filter((localeCode) => i18n[localeCode].name);
|
|
46
|
-
return Boolean(populatedLocales.find((localeCode) => localeCode === targetLocaleCode));
|
|
47
|
-
}
|