@prezly/theme-kit-nextjs 3.3.2-alpha.0 → 4.0.0-alpha.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/README.md +5 -4
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js +1 -1
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.d.ts +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.js +6 -7
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +3 -3
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.js +3 -3
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/story.js +3 -3
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +3 -2
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +13 -20
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/index.d.ts +0 -1
- package/build/components-nextjs/PageSeo/index.js +0 -15
- package/build/components-nextjs/PageSeo/index.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/index.d.ts +1 -0
- package/build/components-nextjs/PageSeo/lib/index.js +6 -0
- package/build/components-nextjs/PageSeo/lib/index.js.map +1 -0
- package/build/components-nextjs/document.js +4 -4
- package/build/components-nextjs/document.js.map +1 -1
- package/build/data-fetching/NextPrezlyApi.d.ts +8 -0
- package/build/data-fetching/NextPrezlyApi.js +40 -0
- package/build/data-fetching/NextPrezlyApi.js.map +1 -0
- package/build/data-fetching/getNextPrezlyApi.d.ts +4 -0
- package/build/data-fetching/getNextPrezlyApi.js +21 -0
- package/build/data-fetching/getNextPrezlyApi.js.map +1 -0
- package/build/data-fetching/index.d.ts +1 -3
- package/build/data-fetching/index.js +3 -17
- package/build/data-fetching/index.js.map +1 -1
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +1 -1
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/index.d.ts +0 -2
- package/build/intl/index.js +0 -7
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.d.ts +1 -44
- package/build/intl/languages.js +8 -151
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.d.ts +0 -8
- package/build/intl/locale.js +3 -93
- package/build/intl/locale.js.map +1 -1
- package/build/newsroom-context/context.d.ts +2 -2
- package/build/newsroom-context/context.js +2 -2
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +3 -3
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +3 -3
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/types.d.ts +0 -29
- package/package.json +15 -13
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +2 -2
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +2 -2
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +2 -2
- package/src/adapter-nextjs/getNewsroomStaticProps.ts +2 -2
- package/src/adapter-nextjs/page-props/category.ts +3 -4
- package/src/adapter-nextjs/page-props/gallery.ts +1 -1
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +2 -2
- package/src/adapter-nextjs/page-props/home.ts +1 -1
- package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +2 -2
- package/src/adapter-nextjs/page-props/story.ts +4 -4
- package/src/adapter-nextjs/page-props/storyPreview.ts +2 -2
- package/src/adapter-nextjs/processRequest.ts +2 -1
- package/src/components-nextjs/PageSeo/PageSeo.tsx +7 -5
- package/src/components-nextjs/PageSeo/index.ts +0 -1
- package/src/components-nextjs/PageSeo/lib/index.ts +1 -0
- package/src/components-nextjs/document.tsx +1 -1
- package/src/data-fetching/NextPrezlyApi.ts +57 -0
- package/src/data-fetching/{api/getPrezlyApi.ts → getNextPrezlyApi.ts} +5 -6
- package/src/data-fetching/index.ts +1 -3
- package/src/index.ts +0 -2
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +1 -1
- package/src/intl/index.ts +0 -3
- package/src/intl/languages.test.ts +1 -196
- package/src/intl/languages.ts +8 -201
- package/src/intl/locale.test.ts +1 -55
- package/src/intl/locale.ts +1 -106
- package/src/newsroom-context/context.tsx +2 -3
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +1 -2
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +2 -3
- package/src/types.ts +0 -35
- package/build/components-nextjs/PageSeo/lib/types.d.ts +0 -4
- package/build/components-nextjs/PageSeo/lib/types.js +0 -3
- package/build/components-nextjs/PageSeo/lib/types.js.map +0 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +0 -57
- package/build/data-fetching/api/PrezlyApi.js +0 -200
- package/build/data-fetching/api/PrezlyApi.js.map +0 -1
- package/build/data-fetching/api/getPrezlyApi.d.ts +0 -4
- package/build/data-fetching/api/getPrezlyApi.js +0 -21
- package/build/data-fetching/api/getPrezlyApi.js.map +0 -1
- package/build/data-fetching/api/index.d.ts +0 -1
- package/build/data-fetching/api/index.js +0 -18
- package/build/data-fetching/api/index.js.map +0 -1
- package/build/data-fetching/api/lib.d.ts +0 -11
- package/build/data-fetching/api/lib.js +0 -20
- package/build/data-fetching/api/lib.js.map +0 -1
- package/build/data-fetching/api/queries.d.ts +0 -46
- package/build/data-fetching/api/queries.js +0 -56
- package/build/data-fetching/api/queries.js.map +0 -1
- package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
- package/build/data-fetching/lib/getAlgoliaSettings.js +0 -22
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
- package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
- package/build/data-fetching/lib/getEnvVariables.js +0 -44
- package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
- package/build/data-fetching/lib/index.d.ts +0 -4
- package/build/data-fetching/lib/index.js +0 -12
- package/build/data-fetching/lib/index.js.map +0 -1
- package/build/data-fetching/lib/isSdkError.d.ts +0 -2
- package/build/data-fetching/lib/isSdkError.js +0 -8
- package/build/data-fetching/lib/isSdkError.js.map +0 -1
- package/build/data-fetching/lib/isUuid.d.ts +0 -1
- package/build/data-fetching/lib/isUuid.js +0 -9
- package/build/data-fetching/lib/isUuid.js.map +0 -1
- package/build/data-fetching/types.d.ts +0 -13
- package/build/data-fetching/types.js +0 -3
- package/build/data-fetching/types.js.map +0 -1
- package/build/intl/localeConfig.d.ts +0 -2
- package/build/intl/localeConfig.js +0 -20
- package/build/intl/localeConfig.js.map +0 -1
- package/build/intl/localeList.d.ts +0 -2
- package/build/intl/localeList.js +0 -112
- package/build/intl/localeList.js.map +0 -1
- package/build/intl/localeObject.d.ts +0 -45
- package/build/intl/localeObject.js +0 -91
- package/build/intl/localeObject.js.map +0 -1
- package/build/utils/boilerplate.d.ts +0 -4
- package/build/utils/boilerplate.js +0 -27
- package/build/utils/boilerplate.js.map +0 -1
- package/build/utils/constants.d.ts +0 -3
- package/build/utils/constants.js +0 -7
- package/build/utils/constants.js.map +0 -1
- package/build/utils/getAssetsUrl.d.ts +0 -5
- package/build/utils/getAssetsUrl.js +0 -13
- package/build/utils/getAssetsUrl.js.map +0 -1
- package/build/utils/getDataRequestLink.d.ts +0 -3
- package/build/utils/getDataRequestLink.js +0 -12
- package/build/utils/getDataRequestLink.js.map +0 -1
- package/build/utils/getLocalizedCategoryData.d.ts +0 -10
- package/build/utils/getLocalizedCategoryData.js +0 -37
- package/build/utils/getLocalizedCategoryData.js.map +0 -1
- package/build/utils/getNewsroomLogoUrl.d.ts +0 -3
- package/build/utils/getNewsroomLogoUrl.js +0 -22
- package/build/utils/getNewsroomLogoUrl.js.map +0 -1
- package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
- package/build/utils/getPrivacyPortalUrl.js +0 -13
- package/build/utils/getPrivacyPortalUrl.js.map +0 -1
- package/build/utils/getStoryPublicationDate.d.ts +0 -3
- package/build/utils/getStoryPublicationDate.js +0 -14
- package/build/utils/getStoryPublicationDate.js.map +0 -1
- package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
- package/build/utils/getUploadcareGroupUrl.js +0 -17
- package/build/utils/getUploadcareGroupUrl.js.map +0 -1
- package/build/utils/index.d.ts +0 -10
- package/build/utils/index.js +0 -27
- package/build/utils/index.js.map +0 -1
- package/build/utils/isEmbargoStory.d.ts +0 -6
- package/build/utils/isEmbargoStory.js +0 -8
- package/build/utils/isEmbargoStory.js.map +0 -1
- package/src/@types/global.d.ts +0 -7
- package/src/__mocks__/story.ts +0 -359
- package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
- package/src/data-fetching/api/PrezlyApi.ts +0 -312
- package/src/data-fetching/api/index.ts +0 -1
- package/src/data-fetching/api/lib.ts +0 -24
- package/src/data-fetching/api/queries.ts +0 -59
- 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/intl/getFallbackLocale.ts +0 -29
- 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 -107
- package/src/seo/getAlternateLanguageLinks.test.ts +0 -166
- package/src/seo/getAlternateLanguageLinks.ts +0 -115
- package/src/seo/index.ts +0 -1
- package/src/seo/utils/bindLanguagesWithLocales.ts +0 -31
- package/src/seo/utils/createAlternateLanguageLink.ts +0 -17
- package/src/utils/boilerplate.ts +0 -30
- 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
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { LocaleObject } from './localeObject';
|
|
2
|
-
|
|
3
|
-
it('throws when created from invalid code', () => {
|
|
4
|
-
// @ts-expect-error
|
|
5
|
-
expect(() => new LocaleObject('en_US')).toThrow('Invalid locale code provided!');
|
|
6
|
-
// @ts-expect-error
|
|
7
|
-
expect(() => new LocaleObject('1234')).toThrow('Invalid locale code provided!');
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
expect(() => new LocaleObject('*!en-US')).toThrow('Invalid locale code provided!');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('throws when created with unsupported code', () => {
|
|
13
|
-
const unsupportedCode = 'unknown-code';
|
|
14
|
-
expect(() => LocaleObject.fromAnyCode(unsupportedCode)).toThrow(
|
|
15
|
-
`Unsupported locale code provided: "${unsupportedCode}"`,
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('accepts any valid code type and converts it to hyphen code consistently', () => {
|
|
20
|
-
expect(LocaleObject.fromAnyCode('en').toHyphenCode()).toBe('en');
|
|
21
|
-
expect(LocaleObject.fromAnyCode('en-us').toHyphenCode()).toBe('en-US');
|
|
22
|
-
expect(LocaleObject.fromAnyCode('en-US').toHyphenCode()).toBe('en-US');
|
|
23
|
-
expect(LocaleObject.fromAnyCode('EN-US').toHyphenCode()).toBe('en-US');
|
|
24
|
-
expect(LocaleObject.fromAnyCode('en_us').toHyphenCode()).toBe('en-US');
|
|
25
|
-
expect(LocaleObject.fromAnyCode('en_US').toHyphenCode()).toBe('en-US');
|
|
26
|
-
expect(LocaleObject.fromAnyCode('EN_US').toHyphenCode()).toBe('en-US');
|
|
27
|
-
|
|
28
|
-
expect(LocaleObject.fromAnyCode('es-419').toHyphenCode()).toBe('es-419');
|
|
29
|
-
expect(LocaleObject.fromAnyCode('es_419').toHyphenCode()).toBe('es-419');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('converts to underscore code consistently', () => {
|
|
33
|
-
expect(LocaleObject.fromAnyCode('en').toUnderscoreCode()).toBe('en');
|
|
34
|
-
expect(LocaleObject.fromAnyCode('en-us').toUnderscoreCode()).toBe('en_US');
|
|
35
|
-
expect(LocaleObject.fromAnyCode('en-US').toUnderscoreCode()).toBe('en_US');
|
|
36
|
-
expect(LocaleObject.fromAnyCode('EN-US').toUnderscoreCode()).toBe('en_US');
|
|
37
|
-
expect(LocaleObject.fromAnyCode('en_us').toUnderscoreCode()).toBe('en_US');
|
|
38
|
-
expect(LocaleObject.fromAnyCode('en_US').toUnderscoreCode()).toBe('en_US');
|
|
39
|
-
expect(LocaleObject.fromAnyCode('EN_US').toUnderscoreCode()).toBe('en_US');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('converts to URL slug consistently', () => {
|
|
43
|
-
expect(LocaleObject.fromAnyCode('en').toUrlSlug()).toBe('en');
|
|
44
|
-
expect(LocaleObject.fromAnyCode('en-us').toUrlSlug()).toBe('en-us');
|
|
45
|
-
expect(LocaleObject.fromAnyCode('en-US').toUrlSlug()).toBe('en-us');
|
|
46
|
-
expect(LocaleObject.fromAnyCode('EN-US').toUrlSlug()).toBe('en-us');
|
|
47
|
-
expect(LocaleObject.fromAnyCode('en_us').toUrlSlug()).toBe('en-us');
|
|
48
|
-
expect(LocaleObject.fromAnyCode('en_US').toUrlSlug()).toBe('en-us');
|
|
49
|
-
expect(LocaleObject.fromAnyCode('EN_US').toUrlSlug()).toBe('en-us');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('converts to neutral language code consistently', () => {
|
|
53
|
-
expect(LocaleObject.fromAnyCode('en').toNeutralLanguageCode()).toBe('en');
|
|
54
|
-
expect(LocaleObject.fromAnyCode('en-us').toNeutralLanguageCode()).toBe('en');
|
|
55
|
-
expect(LocaleObject.fromAnyCode('en-US').toNeutralLanguageCode()).toBe('en');
|
|
56
|
-
expect(LocaleObject.fromAnyCode('EN-US').toNeutralLanguageCode()).toBe('en');
|
|
57
|
-
expect(LocaleObject.fromAnyCode('en_us').toNeutralLanguageCode()).toBe('en');
|
|
58
|
-
expect(LocaleObject.fromAnyCode('en_US').toNeutralLanguageCode()).toBe('en');
|
|
59
|
-
expect(LocaleObject.fromAnyCode('EN_US').toNeutralLanguageCode()).toBe('en');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('converts to region code consistently', () => {
|
|
63
|
-
expect(LocaleObject.fromAnyCode('en').toRegionCode()).toBe('EN');
|
|
64
|
-
expect(LocaleObject.fromAnyCode('en-us').toRegionCode()).toBe('US');
|
|
65
|
-
expect(LocaleObject.fromAnyCode('en-US').toRegionCode()).toBe('US');
|
|
66
|
-
expect(LocaleObject.fromAnyCode('EN-US').toRegionCode()).toBe('US');
|
|
67
|
-
expect(LocaleObject.fromAnyCode('en_us').toRegionCode()).toBe('US');
|
|
68
|
-
expect(LocaleObject.fromAnyCode('en_US').toRegionCode()).toBe('US');
|
|
69
|
-
expect(LocaleObject.fromAnyCode('EN_US').toRegionCode()).toBe('US');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('can compare two objects', () => {
|
|
73
|
-
const enUsLocale = LocaleObject.fromAnyCode('en-US');
|
|
74
|
-
const enUsLocaleDuplicate = LocaleObject.fromAnyCode('en-US');
|
|
75
|
-
const deDeLocale = LocaleObject.fromAnyCode('de-DE');
|
|
76
|
-
|
|
77
|
-
expect(enUsLocale.isEqual(enUsLocaleDuplicate)).toBe(true);
|
|
78
|
-
expect(enUsLocaleDuplicate.isEqual(enUsLocale)).toBe(true);
|
|
79
|
-
expect(enUsLocale.isEqual(deDeLocale)).toBe(false);
|
|
80
|
-
expect(deDeLocale.isEqual(enUsLocale)).toBe(false);
|
|
81
|
-
});
|
package/src/intl/localeObject.ts
DELETED
|
@@ -1,107 +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
|
-
/**
|
|
16
|
-
* Whether the locale is region independent (without region/culture part).
|
|
17
|
-
* I.E. `en` is region independent, while `en-US` is not.
|
|
18
|
-
*/
|
|
19
|
-
public isRegionIndependent: boolean;
|
|
20
|
-
|
|
21
|
-
private constructor(localeCode: string) {
|
|
22
|
-
if (!/^([a-z]{2,3})(-[a-z\d]{1,4})?$/i.test(localeCode)) {
|
|
23
|
-
throw new Error('Invalid locale code provided!');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const [language, region] = localeCode.split('-');
|
|
27
|
-
|
|
28
|
-
if (region) {
|
|
29
|
-
this.isRegionIndependent = false;
|
|
30
|
-
// Workaround for `zh-Hant` locale, which is the only locale with non-uppercase region part
|
|
31
|
-
const regionSuffix = region === 'hant' ? 'Hant' : region.toUpperCase();
|
|
32
|
-
|
|
33
|
-
this.localeCode = [language, regionSuffix].join('-');
|
|
34
|
-
} else {
|
|
35
|
-
this.isRegionIndependent = true;
|
|
36
|
-
this.localeCode = language;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @param localeCode Locale code in any of the formats below.
|
|
42
|
-
* Examples:
|
|
43
|
-
* - Hyphen-codes: `nl-BE`, `en-US`, `fr`, `fil`
|
|
44
|
-
* - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
|
|
45
|
-
* - Slugs: `nl-be`, `en-us`, `fr`, `fil`
|
|
46
|
-
*/
|
|
47
|
-
public static fromAnyCode(localeCode: string): LocaleObject {
|
|
48
|
-
const lowercaseCode = localeCode.toLowerCase().replace('_', '-');
|
|
49
|
-
const foundCode = localeConfig.find((code) => code === lowercaseCode);
|
|
50
|
-
|
|
51
|
-
if (!foundCode) {
|
|
52
|
-
throw new Error(`Unsupported locale code provided: "${lowercaseCode}"`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return new LocaleObject(foundCode);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @returns Code formatted into hyphen format: `nl-BE`, `en-US`, `fr`, `fil`
|
|
60
|
-
*/
|
|
61
|
-
public toHyphenCode(): string {
|
|
62
|
-
return this.localeCode;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @returns Code formatted into underscore format, as expected by Prezly API: `nl_BE`, `en_US`, `fr`, `fil`
|
|
67
|
-
*/
|
|
68
|
-
public toUnderscoreCode(): string {
|
|
69
|
-
return this.localeCode.replace('-', '_');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @returns Code formatted to a URL-friendly lowercase slug format: `nl-be`, `en-us`, `fr`, `fil`
|
|
74
|
-
*/
|
|
75
|
-
public toUrlSlug(): string {
|
|
76
|
-
return this.localeCode.toLowerCase();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @returns Only the language part of the code without culture/region part: `nl`, `en`, `fr`
|
|
81
|
-
*/
|
|
82
|
-
public toNeutralLanguageCode(): string {
|
|
83
|
-
const [language] = this.localeCode.split('-');
|
|
84
|
-
|
|
85
|
-
return language;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
90
|
-
*/
|
|
91
|
-
public toRegionCode(): string {
|
|
92
|
-
const [language, region] = this.localeCode.split('-');
|
|
93
|
-
|
|
94
|
-
if (!region) {
|
|
95
|
-
return language.toUpperCase();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return region.toUpperCase();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Check if two LocaleObject instances are representing the same locale code.
|
|
103
|
-
*/
|
|
104
|
-
public isEqual(anotherLocale: LocaleObject) {
|
|
105
|
-
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import type { NewsroomLanguageSettings } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { LocaleCode, LocaleObject } from '../intl';
|
|
4
|
-
|
|
5
|
-
import { getAlternateLanguageLinks } from './getAlternateLanguageLinks';
|
|
6
|
-
|
|
7
|
-
function lang(code: LocaleCode, isDefault = false) {
|
|
8
|
-
return { code, is_default: isDefault } as NewsroomLanguageSettings;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function getTranslationUrl(locale: LocaleObject) {
|
|
12
|
-
return `translationUrl/${locale.toHyphenCode()}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function generateTranslationUrl(locale: LocaleObject) {
|
|
16
|
-
const translationUrl = getTranslationUrl(locale);
|
|
17
|
-
|
|
18
|
-
return `http://localhost:3000/${locale.toNeutralLanguageCode()}/${translationUrl}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('getAlternateLanguageLinks', () => {
|
|
22
|
-
it('should handle one en-GB non-default language', () => {
|
|
23
|
-
const links = getAlternateLanguageLinks([lang('en-GB')], generateTranslationUrl);
|
|
24
|
-
|
|
25
|
-
expect(links).toMatchObject([
|
|
26
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en' },
|
|
27
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
28
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'x-default' },
|
|
29
|
-
]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should handle one en-GB default language', () => {
|
|
33
|
-
const links = getAlternateLanguageLinks([lang('en-GB', true)], generateTranslationUrl);
|
|
34
|
-
|
|
35
|
-
expect(links).toMatchObject([
|
|
36
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en' },
|
|
37
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
38
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'x-default' },
|
|
39
|
-
]);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should handle two full locales', () => {
|
|
43
|
-
const links = getAlternateLanguageLinks(
|
|
44
|
-
[lang('en-GB', true), lang('fr-FR')],
|
|
45
|
-
generateTranslationUrl,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(links).toMatchObject([
|
|
49
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en' },
|
|
50
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
51
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr' },
|
|
52
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
53
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'x-default' },
|
|
54
|
-
]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should use en-GB locale as x-default even if other locale is set as default', () => {
|
|
58
|
-
const links = getAlternateLanguageLinks(
|
|
59
|
-
[lang('en-GB'), lang('fr-FR', true)],
|
|
60
|
-
generateTranslationUrl,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(links).toMatchObject([
|
|
64
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en' },
|
|
65
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
66
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr' },
|
|
67
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
68
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'x-default' },
|
|
69
|
-
]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should use default locale as x-default when there is eng locale', () => {
|
|
73
|
-
const links = getAlternateLanguageLinks(
|
|
74
|
-
[lang('ru-RU'), lang('fr-FR', true)],
|
|
75
|
-
generateTranslationUrl,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(links).toMatchObject([
|
|
79
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr' },
|
|
80
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
81
|
-
{ href: 'http://localhost:3000/ru/translationUrl/ru-RU', hrefLang: 'ru' },
|
|
82
|
-
{ href: 'http://localhost:3000/ru/translationUrl/ru-RU', hrefLang: 'ru-RU' },
|
|
83
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'x-default' },
|
|
84
|
-
]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should include provided region independent locale', () => {
|
|
88
|
-
const links = getAlternateLanguageLinks(
|
|
89
|
-
[lang('en-US'), lang('fr'), lang('fr-FR', true)],
|
|
90
|
-
generateTranslationUrl,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
expect(links).toMatchObject([
|
|
94
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en' },
|
|
95
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en-US' },
|
|
96
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr', hrefLang: 'fr' },
|
|
97
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
98
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'x-default' },
|
|
99
|
-
]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should use provided en region independent locale as x-default', () => {
|
|
103
|
-
const links = getAlternateLanguageLinks(
|
|
104
|
-
[lang('en'), lang('en-US'), lang('fr'), lang('fr-FR')],
|
|
105
|
-
generateTranslationUrl,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
expect(links).toMatchObject([
|
|
109
|
-
{ href: 'http://localhost:3000/en/translationUrl/en', hrefLang: 'en' },
|
|
110
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en-US' },
|
|
111
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr', hrefLang: 'fr' },
|
|
112
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
113
|
-
{ href: 'http://localhost:3000/en/translationUrl/en', hrefLang: 'x-default' },
|
|
114
|
-
]);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should fallback en link to en-US locale when there is en-GB locale', () => {
|
|
118
|
-
const links = getAlternateLanguageLinks(
|
|
119
|
-
[lang('en-GB'), lang('en-US')],
|
|
120
|
-
generateTranslationUrl,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
expect(links).toMatchObject([
|
|
124
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en' },
|
|
125
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
126
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en-US' },
|
|
127
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'x-default' },
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should should omit locales if getTranslationUrl is undefined', () => {
|
|
132
|
-
const links = getAlternateLanguageLinks(
|
|
133
|
-
[lang('en-US'), lang('fr'), lang('fr-FR', true)],
|
|
134
|
-
(locale) => {
|
|
135
|
-
const translationUrl =
|
|
136
|
-
locale.toHyphenCode() === 'en-US' ? undefined : getTranslationUrl(locale);
|
|
137
|
-
|
|
138
|
-
if (translationUrl) {
|
|
139
|
-
return generateTranslationUrl(locale);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return undefined;
|
|
143
|
-
},
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expect(links).toMatchObject([
|
|
147
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr', hrefLang: 'fr' },
|
|
148
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'fr-FR' },
|
|
149
|
-
{ href: 'http://localhost:3000/fr/translationUrl/fr-FR', hrefLang: 'x-default' },
|
|
150
|
-
]);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should should not duplicate links when equal languages passed', () => {
|
|
154
|
-
const links = getAlternateLanguageLinks(
|
|
155
|
-
[lang('en-GB'), lang('en-GB'), lang('en-US'), lang('en-US')],
|
|
156
|
-
generateTranslationUrl,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
expect(links).toMatchObject([
|
|
160
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en' },
|
|
161
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-GB', hrefLang: 'en-GB' },
|
|
162
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'en-US' },
|
|
163
|
-
{ href: 'http://localhost:3000/en/translationUrl/en-US', hrefLang: 'x-default' },
|
|
164
|
-
]);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { NewsroomLanguageSettings } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { AlternateLanguageLink } from '../components-nextjs/PageSeo';
|
|
4
|
-
import type { LocaleObject } from '../intl';
|
|
5
|
-
import { getFallbackLocale } from '../intl';
|
|
6
|
-
|
|
7
|
-
import { bindLanguagesWithLocales } from './utils/bindLanguagesWithLocales';
|
|
8
|
-
import { createAlternateLanguageLink } from './utils/createAlternateLanguageLink';
|
|
9
|
-
|
|
10
|
-
// We use english locale as fallback since English is the most common language
|
|
11
|
-
const ENG_FALLBACK = 'en';
|
|
12
|
-
const DEFAULT_HREF_LANG = 'x-default';
|
|
13
|
-
|
|
14
|
-
export function getAlternateLanguageLinks(
|
|
15
|
-
availableLanguages: NewsroomLanguageSettings[],
|
|
16
|
-
generateTranslationUrl: (locale: LocaleObject) => string | undefined,
|
|
17
|
-
): AlternateLanguageLink[] {
|
|
18
|
-
const languagesWithLocales = bindLanguagesWithLocales(availableLanguages);
|
|
19
|
-
const hrefLangLinks: Array<AlternateLanguageLink> = [];
|
|
20
|
-
|
|
21
|
-
function pushLocaleToLinks(locale: LocaleObject, hrefLang?: string) {
|
|
22
|
-
const link = createAlternateLanguageLink(locale, generateTranslationUrl);
|
|
23
|
-
|
|
24
|
-
if (!link) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (hrefLang) {
|
|
29
|
-
hrefLangLinks.push({ ...link, hrefLang });
|
|
30
|
-
} else {
|
|
31
|
-
hrefLangLinks.push(link);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function populateDirectLinks() {
|
|
36
|
-
languagesWithLocales.forEach((binds) =>
|
|
37
|
-
binds.forEach(({ locale }) => pushLocaleToLinks(locale)),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function populateRegionIndependentLinks() {
|
|
42
|
-
languagesWithLocales.forEach((binds, regionIndependentLocaleCode) => {
|
|
43
|
-
// When there is no region independent locale of provided locales
|
|
44
|
-
// we still need something as a region independent locale
|
|
45
|
-
const localesArray = Array.from(binds.values()).map(({ locale }) => locale);
|
|
46
|
-
|
|
47
|
-
const hasRegionIndependentLocale = localesArray.some(
|
|
48
|
-
(locale) => locale.isRegionIndependent,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (hasRegionIndependentLocale) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Try to find some possible fallback for the regionIndependentLocaleCode from hardcoded list
|
|
56
|
-
// We try to find fallback from provided translations of current regionIndependentLocaleCode
|
|
57
|
-
// If there is no defined fallback in the list we will use just first translation as a region independent translation
|
|
58
|
-
const fallback =
|
|
59
|
-
getFallbackLocale(regionIndependentLocaleCode, localesArray) ?? localesArray.at(0);
|
|
60
|
-
|
|
61
|
-
if (fallback) {
|
|
62
|
-
pushLocaleToLinks(fallback, regionIndependentLocaleCode);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function populateDefault() {
|
|
68
|
-
let isDefaultAddedToLinks = false;
|
|
69
|
-
|
|
70
|
-
// First we try to find region independent english locale (en)
|
|
71
|
-
// If the story has just region independent `en` translation we will use it as default hreflang
|
|
72
|
-
languagesWithLocales.forEach((binds) =>
|
|
73
|
-
binds.forEach(({ locale }) => {
|
|
74
|
-
if (locale.isRegionIndependent && locale.toNeutralLanguageCode() === ENG_FALLBACK) {
|
|
75
|
-
pushLocaleToLinks(locale, DEFAULT_HREF_LANG);
|
|
76
|
-
isDefaultAddedToLinks = true;
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
if (!isDefaultAddedToLinks) {
|
|
82
|
-
// If there is no explicit region independent `en` translation for this story
|
|
83
|
-
// we will try to find some link that already has `en` fallback
|
|
84
|
-
const fallbackFromRegionIndependentLocales = hrefLangLinks.find(
|
|
85
|
-
(alternate) => alternate.hrefLang === ENG_FALLBACK,
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
if (fallbackFromRegionIndependentLocales) {
|
|
89
|
-
hrefLangLinks.push({
|
|
90
|
-
...fallbackFromRegionIndependentLocales,
|
|
91
|
-
hrefLang: DEFAULT_HREF_LANG,
|
|
92
|
-
});
|
|
93
|
-
isDefaultAddedToLinks = true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!isDefaultAddedToLinks) {
|
|
98
|
-
// If there is no english locale at all we will use is_default language (provided from server)
|
|
99
|
-
languagesWithLocales.forEach((binds) =>
|
|
100
|
-
binds.forEach(({ locale, language }) => {
|
|
101
|
-
if (language.is_default) {
|
|
102
|
-
pushLocaleToLinks(locale, DEFAULT_HREF_LANG);
|
|
103
|
-
isDefaultAddedToLinks = true;
|
|
104
|
-
}
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
populateDirectLinks();
|
|
111
|
-
populateRegionIndependentLinks();
|
|
112
|
-
populateDefault();
|
|
113
|
-
|
|
114
|
-
return hrefLangLinks.sort((a, b) => a.hrefLang.localeCompare(b.hrefLang));
|
|
115
|
-
}
|
package/src/seo/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getAlternateLanguageLinks';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { NewsroomLanguageSettings } from '@prezly/sdk';
|
|
2
|
-
|
|
3
|
-
import type { LangCode, LocaleCode } from '../../intl';
|
|
4
|
-
import { LocaleObject } from '../../intl';
|
|
5
|
-
|
|
6
|
-
interface LocaleWithLanguage {
|
|
7
|
-
language: NewsroomLanguageSettings;
|
|
8
|
-
locale: LocaleObject;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Group languages by their region independent language code (e.g. "en" for "en-US" and "en-GB").
|
|
13
|
-
*/
|
|
14
|
-
export function bindLanguagesWithLocales(languages: NewsroomLanguageSettings[]) {
|
|
15
|
-
const localesByLangCode = new Map<LangCode, Map<LocaleCode, LocaleWithLanguage>>();
|
|
16
|
-
|
|
17
|
-
languages.forEach((language) => {
|
|
18
|
-
const languageLocale = LocaleObject.fromAnyCode(language.code);
|
|
19
|
-
const regionIndependentLanguageCode = languageLocale.toNeutralLanguageCode();
|
|
20
|
-
let currentLocale = localesByLangCode.get(regionIndependentLanguageCode);
|
|
21
|
-
|
|
22
|
-
if (!currentLocale) {
|
|
23
|
-
currentLocale = new Map();
|
|
24
|
-
localesByLangCode.set(regionIndependentLanguageCode, currentLocale);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
currentLocale.set(languageLocale.toHyphenCode(), { language, locale: languageLocale });
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return localesByLangCode;
|
|
31
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { LocaleObject } from '../../intl';
|
|
2
|
-
|
|
3
|
-
export function createAlternateLanguageLink(
|
|
4
|
-
locale: LocaleObject,
|
|
5
|
-
generateTranslationUrl: (locale: LocaleObject) => string | undefined,
|
|
6
|
-
) {
|
|
7
|
-
const translationUrl = generateTranslationUrl(locale);
|
|
8
|
-
|
|
9
|
-
if (!translationUrl) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
hrefLang: locale.toHyphenCode(),
|
|
15
|
-
href: translationUrl,
|
|
16
|
-
};
|
|
17
|
-
}
|
package/src/utils/boilerplate.ts
DELETED
|
@@ -1,30 +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 ||
|
|
26
|
-
companyInformation.phone ||
|
|
27
|
-
companyInformation.email ||
|
|
28
|
-
companyInformation.website,
|
|
29
|
-
);
|
|
30
|
-
}
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Newsroom } from '@prezly/sdk';
|
|
2
|
-
import { UploadcareImage } from '@prezly/uploadcare';
|
|
3
|
-
|
|
4
|
-
export function getNewsroomLogoUrl(newsroom: Newsroom): string {
|
|
5
|
-
if (newsroom.newsroom_logo) {
|
|
6
|
-
const image = UploadcareImage.createFromPrezlyStoragePayload(newsroom.newsroom_logo);
|
|
7
|
-
return image.cdnUrl;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getNewsroomFaviconUrl(newsroom: Newsroom, previewSize = 400): string {
|
|
14
|
-
const imageObject = newsroom.icon || newsroom.square_logo;
|
|
15
|
-
|
|
16
|
-
if (imageObject) {
|
|
17
|
-
const image = UploadcareImage.createFromPrezlyStoragePayload(imageObject);
|
|
18
|
-
return image.preview(previewSize, previewSize).cdnUrl;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return '';
|
|
22
|
-
}
|