@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
package/build/intl/localeList.js
CHANGED
|
@@ -1,111 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This list is pulled from the main Prezly application. The underscores are replaced with dashes.
|
|
3
3
|
*/
|
|
4
|
-
export const localeList = [
|
|
5
|
-
'af-ZA',
|
|
6
|
-
'ar',
|
|
7
|
-
'ar-AE',
|
|
8
|
-
'ar-BH',
|
|
9
|
-
'ar-QA',
|
|
10
|
-
'ar-SA',
|
|
11
|
-
'az',
|
|
12
|
-
'be',
|
|
13
|
-
'bg-BG',
|
|
14
|
-
'ca',
|
|
15
|
-
'cs-CZ',
|
|
16
|
-
'da-DK',
|
|
17
|
-
'de',
|
|
18
|
-
'de-DE',
|
|
19
|
-
'de-BE',
|
|
20
|
-
'de-AT',
|
|
21
|
-
'de-CH',
|
|
22
|
-
'el-GR',
|
|
23
|
-
'en',
|
|
24
|
-
'en-US',
|
|
25
|
-
'en-AE',
|
|
26
|
-
'en-AU',
|
|
27
|
-
'en-BD',
|
|
28
|
-
'en-BE',
|
|
29
|
-
'en-BH',
|
|
30
|
-
'en-CA',
|
|
31
|
-
'en-CN',
|
|
32
|
-
'en-DE',
|
|
33
|
-
'en-DK',
|
|
34
|
-
'en-GB',
|
|
35
|
-
'en-HK',
|
|
36
|
-
'en-ID',
|
|
37
|
-
'en-IE',
|
|
38
|
-
'en-IL',
|
|
39
|
-
'en-IN',
|
|
40
|
-
'en-JM',
|
|
41
|
-
'en-JP',
|
|
42
|
-
'en-KH',
|
|
43
|
-
'en-KR',
|
|
44
|
-
'en-LK',
|
|
45
|
-
'en-MV',
|
|
46
|
-
'en-MM',
|
|
47
|
-
'en-MY',
|
|
48
|
-
'en-NP',
|
|
49
|
-
'en-NZ',
|
|
50
|
-
'en-PH',
|
|
51
|
-
'en-PK',
|
|
52
|
-
'en-QA',
|
|
53
|
-
'en-SA',
|
|
54
|
-
'en-SG',
|
|
55
|
-
'en-TH',
|
|
56
|
-
'en-TW',
|
|
57
|
-
'en-VN',
|
|
58
|
-
'en-ZA',
|
|
59
|
-
'es',
|
|
60
|
-
'es-ES',
|
|
61
|
-
'es-MX',
|
|
62
|
-
'et-EE',
|
|
63
|
-
'es-419',
|
|
64
|
-
'fi-FI',
|
|
65
|
-
'fil',
|
|
66
|
-
'fr',
|
|
67
|
-
'fr-BE',
|
|
68
|
-
'fr-FR',
|
|
69
|
-
'fr-CA',
|
|
70
|
-
'fr-LU',
|
|
71
|
-
'ga-IE',
|
|
72
|
-
'he-IL',
|
|
73
|
-
'hi-IN',
|
|
74
|
-
'hr-HR',
|
|
75
|
-
'hu-HU',
|
|
76
|
-
'id-ID',
|
|
77
|
-
'it-IT',
|
|
78
|
-
'ja-JP',
|
|
79
|
-
'kk',
|
|
80
|
-
'ko-KR',
|
|
81
|
-
'ky',
|
|
82
|
-
'lt-LT',
|
|
83
|
-
'lv-LV',
|
|
84
|
-
'mt-MT',
|
|
85
|
-
'ms-MY',
|
|
86
|
-
'nb-NO',
|
|
87
|
-
'nl',
|
|
88
|
-
'nl-BE',
|
|
89
|
-
'nl-NL',
|
|
90
|
-
'pl-PL',
|
|
91
|
-
'pt',
|
|
92
|
-
'pt-BR',
|
|
93
|
-
'pt-PT',
|
|
94
|
-
'ro-RO',
|
|
95
|
-
'ru-RU',
|
|
96
|
-
'sk-SK',
|
|
97
|
-
'sl-SI',
|
|
98
|
-
'sv-SE',
|
|
99
|
-
'sw',
|
|
100
|
-
'th-TH',
|
|
101
|
-
'tr-TR',
|
|
102
|
-
'uk-UA',
|
|
103
|
-
'ur-PK',
|
|
104
|
-
'uz',
|
|
105
|
-
'vi-VN',
|
|
106
|
-
'zh-Hant',
|
|
107
|
-
'zh-HK',
|
|
108
|
-
'zh-TW',
|
|
109
|
-
'zh-CN',
|
|
110
|
-
];
|
|
111
|
-
//# sourceMappingURL=localeList.js.map
|
|
4
|
+
export const localeList = ['af-ZA', 'ar', 'ar-AE', 'ar-BH', 'ar-QA', 'ar-SA', 'az', 'be', 'bg-BG', 'ca', 'cs-CZ', 'da-DK', 'de', 'de-DE', 'de-BE', 'de-AT', 'de-CH', 'el-GR', 'en', 'en-US', 'en-AE', 'en-AU', 'en-BD', 'en-BE', 'en-BH', 'en-CA', 'en-CN', 'en-DE', 'en-DK', 'en-GB', 'en-HK', 'en-ID', 'en-IE', 'en-IL', 'en-IN', 'en-JM', 'en-JP', 'en-KH', 'en-KR', 'en-LK', 'en-MV', 'en-MM', 'en-MY', 'en-NP', 'en-NZ', 'en-PH', 'en-PK', 'en-QA', 'en-SA', 'en-SG', 'en-TH', 'en-TW', 'en-VN', 'en-ZA', 'es', 'es-ES', 'es-MX', 'et-EE', 'es-419', 'fi-FI', 'fil', 'fr', 'fr-BE', 'fr-FR', 'fr-CA', 'fr-LU', 'ga-IE', 'he-IL', 'hi-IN', 'hr-HR', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk', 'ko-KR', 'ky', 'lt-LT', 'lv-LV', 'mt-MT', 'ms-MY', 'nb-NO', 'nl', 'nl-BE', 'nl-NL', 'pl-PL', 'pt', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sl-SI', 'sv-SE', 'sw', 'th-TH', 'tr-TR', 'uk-UA', 'ur-PK', 'uz', 'vi-VN', 'zh-Hant', 'zh-HK', 'zh-TW', 'zh-CN'];
|
|
@@ -1,84 +1,89 @@
|
|
|
1
|
-
import { localeConfig } from
|
|
1
|
+
import { localeConfig } from "./localeConfig.js";
|
|
2
2
|
/**
|
|
3
3
|
* This class is created to simplify working with locales and transforming between different locale code formats.
|
|
4
4
|
* Prezly API uses underscore-codes, while most frontend application tend to use hyphen-codes or slugs.
|
|
5
5
|
* Note that `fromAnyCode` constructor only accepts locales supported by Prezly backend. See `localeConfig` for reference.
|
|
6
6
|
*/
|
|
7
7
|
export class LocaleObject {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const [language, region] = localeCode.split('-');
|
|
18
|
-
if (region) {
|
|
19
|
-
// Workaround for `zh-Hant` locale, which is the only locale with non-uppercase region part
|
|
20
|
-
const regionSuffix = region === 'hant' ? 'Hant' : region.toUpperCase();
|
|
21
|
-
this.localeCode = [language, regionSuffix].join('-');
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
this.localeCode = language;
|
|
25
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* Hyphen-separated locale code.
|
|
10
|
+
* Examples: `nl-BE`, `en-US`, `fr`, `fil`
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
constructor(localeCode) {
|
|
14
|
+
if (!/^([a-z]{2,3})(-[a-z\d]{1,4})?$/i.test(localeCode)) {
|
|
15
|
+
throw new Error('Invalid locale code provided!');
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
static fromAnyCode(localeCode) {
|
|
35
|
-
const lowercaseCode = localeCode.toLowerCase().replace('_', '-');
|
|
36
|
-
const foundCode = localeConfig.find((code) => code === lowercaseCode);
|
|
37
|
-
if (!foundCode) {
|
|
38
|
-
throw new Error(`Unsupported locale code provided: "${lowercaseCode}"`);
|
|
39
|
-
}
|
|
40
|
-
return new LocaleObject(foundCode);
|
|
17
|
+
const [language, region] = localeCode.split('-');
|
|
18
|
+
if (region) {
|
|
19
|
+
// Workaround for `zh-Hant` locale, which is the only locale with non-uppercase region part
|
|
20
|
+
const regionSuffix = region === 'hant' ? 'Hant' : region.toUpperCase();
|
|
21
|
+
this.localeCode = [language, regionSuffix].join('-');
|
|
22
|
+
} else {
|
|
23
|
+
this.localeCode = language;
|
|
41
24
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param localeCode Locale code in any of the formats below.
|
|
29
|
+
* Examples:
|
|
30
|
+
* - Hyphen-codes: `nl-BE`, `en-US`, `fr`, `fil`
|
|
31
|
+
* - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
|
|
32
|
+
* - Slugs: `nl-be`, `en-us`, `fr`, `fil`
|
|
33
|
+
*/
|
|
34
|
+
static fromAnyCode(localeCode) {
|
|
35
|
+
const lowercaseCode = localeCode.toLowerCase().replace('_', '-');
|
|
36
|
+
const foundCode = localeConfig.locales.find(code => code === lowercaseCode);
|
|
37
|
+
if (!foundCode) {
|
|
38
|
+
throw new Error(`Unsupported locale code provided: "${lowercaseCode}"`);
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
return new LocaleObject(foundCode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @returns Code formatted into hyphen format: `nl-BE`, `en-US`, `fr`, `fil`
|
|
45
|
+
*/
|
|
46
|
+
toHyphenCode() {
|
|
47
|
+
return this.localeCode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns Code formatted into underscore format, as expected by Prezly API: `nl_BE`, `en_US`, `fr`, `fil`
|
|
52
|
+
*/
|
|
53
|
+
toUnderscoreCode() {
|
|
54
|
+
return this.localeCode.replace('-', '_');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @returns Code formatted to a URL-friendly lowercase slug format: `nl-be`, `en-us`, `fr`, `fil`
|
|
59
|
+
*/
|
|
60
|
+
toUrlSlug() {
|
|
61
|
+
return this.localeCode.toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @returns Only the language part of the code without culture/region part: `nl`, `en`, `fr`
|
|
66
|
+
*/
|
|
67
|
+
toNeutralLanguageCode() {
|
|
68
|
+
const [language] = this.localeCode.split('-');
|
|
69
|
+
return language;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
74
|
+
*/
|
|
75
|
+
toRegionCode() {
|
|
76
|
+
const [language, region] = this.localeCode.split('-');
|
|
77
|
+
if (!region) {
|
|
78
|
+
return language.toUpperCase();
|
|
53
79
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const [language] = this.localeCode.split('-');
|
|
65
|
-
return language;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
69
|
-
*/
|
|
70
|
-
toRegionCode() {
|
|
71
|
-
const [language, region] = this.localeCode.split('-');
|
|
72
|
-
if (!region) {
|
|
73
|
-
return language.toUpperCase();
|
|
74
|
-
}
|
|
75
|
-
return region.toUpperCase();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Check if two LocaleObject instances are representing the same locale code.
|
|
79
|
-
*/
|
|
80
|
-
isEqual(anotherLocale) {
|
|
81
|
-
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=localeObject.js.map
|
|
80
|
+
return region.toUpperCase();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Check if two LocaleObject instances are representing the same locale code.
|
|
85
|
+
*/
|
|
86
|
+
isEqual(anotherLocale) {
|
|
87
|
+
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACrB;;;OAGG;IACK,UAAU,CAAS;IAE3B,YAAoB,UAAkB;QAClC,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAED,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,2FAA2F;YAC3F,MAAM,YAAY,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAEvE,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACxD;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CAAC,UAAkB;QACxC,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACrB;;;OAGG;IACK,UAAU,CAAS;IAE3B,YAAoB,UAAkB;QAClC,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAED,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,2FAA2F;YAC3F,MAAM,YAAY,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAEvE,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACxD;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CAAC,UAAkB;QACxC,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;QAE9E,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,sCAAsC,aAAa,GAAG,CAAC,CAAC;SAC3E;QAED,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,gBAAgB;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,qBAAqB;QACxB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,YAAY;QACf,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEtD,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,aAA2B;QACtC,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;IAC5D,CAAC;CACJ"}
|
|
@@ -1,25 +1,39 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { createContext, useMemo } from 'react';
|
|
3
|
-
import { DEFAULT_LOCALE, LocaleObject } from
|
|
4
|
-
export const NewsroomContext = createContext(undefined);
|
|
2
|
+
import { DEFAULT_LOCALE, LocaleObject } from "../intl/index.js";
|
|
3
|
+
export const NewsroomContext = /*#__PURE__*/createContext(undefined);
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
7
7
|
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
8
8
|
*/
|
|
9
|
-
export function NewsroomContextProvider({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
export function NewsroomContextProvider({
|
|
10
|
+
categories,
|
|
11
|
+
contacts,
|
|
12
|
+
newsroom,
|
|
13
|
+
currentCategory,
|
|
14
|
+
currentStory,
|
|
15
|
+
companyInformation,
|
|
16
|
+
languages,
|
|
17
|
+
localeCode,
|
|
18
|
+
notifications,
|
|
19
|
+
themePreset,
|
|
20
|
+
algoliaSettings,
|
|
21
|
+
children
|
|
22
|
+
}) {
|
|
23
|
+
const locale = useMemo(() => LocaleObject.fromAnyCode(localeCode || DEFAULT_LOCALE), [localeCode]);
|
|
24
|
+
return /*#__PURE__*/React.createElement(NewsroomContext.Provider, {
|
|
25
|
+
value: {
|
|
26
|
+
categories,
|
|
27
|
+
contacts,
|
|
28
|
+
newsroom,
|
|
29
|
+
currentCategory,
|
|
30
|
+
currentStory,
|
|
31
|
+
companyInformation,
|
|
32
|
+
languages,
|
|
33
|
+
locale,
|
|
34
|
+
notifications,
|
|
35
|
+
themePreset,
|
|
36
|
+
algoliaSettings
|
|
37
|
+
}
|
|
38
|
+
}, children);
|
|
39
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./useAlgoliaSettings.js";
|
|
2
|
+
export * from "./useCategories.js";
|
|
3
|
+
export * from "./useCompanyInformation.js";
|
|
4
|
+
export * from "./useCurrentCategory.js";
|
|
5
|
+
export * from "./useCurrentLocale.js";
|
|
6
|
+
export * from "./useCurrentStory.js";
|
|
7
|
+
export * from "./useGetLinkLocaleSlug.js";
|
|
8
|
+
export * from "./useGetTranslationUrl.js";
|
|
9
|
+
export * from "./useLanguages.js";
|
|
10
|
+
export * from "./useNewsroom.js";
|
|
11
|
+
export * from "./useNewsroomContext.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useAlgoliaSettings() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useAlgoliaSettings.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.algoliaSettings;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useCategories() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useCategories.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.categories;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useCompanyInformation() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useCompanyInformation.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.companyInformation;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useCurrentCategory() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useCurrentCategory.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.currentCategory;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useCurrentLocale() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useCurrentLocale.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.locale;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useCurrentStory() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useCurrentStory.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.currentStory;
|
|
5
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import { getShortestLocaleCode, LocaleObject } from
|
|
3
|
-
import { useCurrentLocale } from
|
|
4
|
-
import { useLanguages } from
|
|
2
|
+
import { getShortestLocaleCode, LocaleObject } from "../../intl/index.js";
|
|
3
|
+
import { useCurrentLocale } from "./useCurrentLocale.js";
|
|
4
|
+
import { useLanguages } from "./useLanguages.js";
|
|
5
5
|
/**
|
|
6
6
|
* Determines correct locale slug for the link (trying to shorten the locale code if possible).
|
|
7
7
|
* E.g. if newsroom has a single locale for Dutch (`nl_BE`), it will be shortened to `nl`.
|
|
@@ -9,17 +9,17 @@ import { useLanguages } from './useLanguages';
|
|
|
9
9
|
* `false` means that a default locale should be used (no locale in URL required).
|
|
10
10
|
*/
|
|
11
11
|
function getLinkLocaleSlug(languages, locale) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const shortestLocaleCode = getShortestLocaleCode(languages, locale);
|
|
13
|
+
// When navigating to default language, we don't append the locale to the URL.
|
|
14
|
+
if (!shortestLocaleCode) {
|
|
15
|
+
return shortestLocaleCode;
|
|
16
|
+
}
|
|
17
|
+
return LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug();
|
|
18
18
|
}
|
|
19
19
|
export function useGetLinkLocaleSlug() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const currentLocale = useCurrentLocale();
|
|
21
|
+
const languages = useLanguages();
|
|
22
|
+
|
|
23
|
+
// The `locale` parameter is mainly used for Language Dropdown
|
|
24
|
+
return useCallback(locale => getLinkLocaleSlug(languages, locale || currentLocale), [languages, currentLocale]);
|
|
25
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { Story } from '@prezly/sdk';
|
|
2
2
|
import { useRouter } from 'next/router';
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
|
-
import { getCategoryHasTranslation, getCategoryUrl } from
|
|
5
|
-
import { useCurrentCategory } from
|
|
6
|
-
import { useCurrentStory } from
|
|
4
|
+
import { getCategoryHasTranslation, getCategoryUrl } from "../../utils/index.js";
|
|
5
|
+
import { useCurrentCategory } from "./useCurrentCategory.js";
|
|
6
|
+
import { useCurrentStory } from "./useCurrentStory.js";
|
|
7
7
|
function getAllowedTranslationVisibilityValues(story) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return [Story.Visibility.PUBLIC];
|
|
22
|
-
}
|
|
8
|
+
const {
|
|
9
|
+
visibility
|
|
10
|
+
} = story;
|
|
11
|
+
switch (visibility) {
|
|
12
|
+
case Story.Visibility.EMBARGO:
|
|
13
|
+
return [Story.Visibility.EMBARGO, Story.Visibility.PUBLIC];
|
|
14
|
+
case Story.Visibility.PRIVATE:
|
|
15
|
+
return [Story.Visibility.PRIVATE, Story.Visibility.PUBLIC];
|
|
16
|
+
case Story.Visibility.CONFIDENTIAL:
|
|
17
|
+
return [Story.Visibility.CONFIDENTIAL, Story.Visibility.PRIVATE, Story.Visibility.PUBLIC];
|
|
18
|
+
default:
|
|
19
|
+
return [Story.Visibility.PUBLIC];
|
|
20
|
+
}
|
|
23
21
|
}
|
|
22
|
+
|
|
24
23
|
/**
|
|
25
24
|
* Determine correct URL for translated stories/categories with a fallback to homepage.
|
|
26
25
|
* E.g. if a story has a translation, the function will return the localized slug URL.
|
|
@@ -28,37 +27,42 @@ function getAllowedTranslationVisibilityValues(story) {
|
|
|
28
27
|
* or empty string, if `noFallback` is set to `true` (this is useful for alternate locale links).
|
|
29
28
|
*/
|
|
30
29
|
function getTranslationUrl(locale, path, currentCategory, currentStory, noFallback) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return '/';
|
|
30
|
+
if (currentCategory) {
|
|
31
|
+
if (getCategoryHasTranslation(currentCategory, locale)) {
|
|
32
|
+
return getCategoryUrl(currentCategory, locale);
|
|
33
|
+
}
|
|
34
|
+
if (noFallback) {
|
|
35
|
+
return '';
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
return '/';
|
|
38
|
+
}
|
|
39
|
+
const localeCode = locale.toUnderscoreCode();
|
|
40
|
+
if (currentStory && currentStory.culture.locale !== localeCode) {
|
|
41
|
+
const allowedVisibilityValues = getAllowedTranslationVisibilityValues(currentStory);
|
|
42
|
+
const translatedStory = currentStory.translations.find(({
|
|
43
|
+
culture,
|
|
44
|
+
visibility
|
|
45
|
+
}) => culture.locale === localeCode && allowedVisibilityValues.includes(visibility));
|
|
46
|
+
if (translatedStory) {
|
|
47
|
+
return `/${translatedStory.slug}`;
|
|
51
48
|
}
|
|
52
|
-
|
|
49
|
+
if (noFallback) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
return '/';
|
|
53
|
+
}
|
|
54
|
+
return path;
|
|
53
55
|
}
|
|
56
|
+
|
|
54
57
|
/**
|
|
55
58
|
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
56
59
|
* `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).
|
|
57
60
|
*/
|
|
58
61
|
export function useGetTranslationUrl() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const {
|
|
63
|
+
asPath
|
|
64
|
+
} = useRouter();
|
|
65
|
+
const currentCategory = useCurrentCategory();
|
|
66
|
+
const currentStory = useCurrentStory();
|
|
67
|
+
return useCallback((locale, noFallback) => getTranslationUrl(locale, asPath, currentCategory, currentStory, noFallback), [asPath, currentCategory, currentStory]);
|
|
68
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useLanguages() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useLanguages.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.languages;
|
|
5
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useNewsroomContext } from
|
|
1
|
+
import { useNewsroomContext } from "./useNewsroomContext.js";
|
|
2
2
|
export function useNewsroom() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=useNewsroom.js.map
|
|
3
|
+
const context = useNewsroomContext();
|
|
4
|
+
return context.newsroom;
|
|
5
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { NewsroomContext } from
|
|
2
|
+
import { NewsroomContext } from "../context.js";
|
|
3
3
|
export function useNewsroomContext() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=useNewsroomContext.js.map
|
|
4
|
+
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
5
|
+
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
6
|
+
const newsroomContext = useContext(NewsroomContext);
|
|
7
|
+
if (!newsroomContext) {
|
|
8
|
+
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
9
|
+
}
|
|
10
|
+
return newsroomContext;
|
|
11
|
+
}
|