@prezly/theme-kit-nextjs 3.2.4-0 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/build/components-nextjs/PageSeo/PageSeo.js +13 -8
  2. package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  3. package/build/components-nextjs/document.js.map +1 -1
  4. package/build/intl/index.d.ts +1 -2
  5. package/build/intl/index.js +1 -2
  6. package/build/intl/index.js.map +1 -1
  7. package/build/intl/locale.d.ts +0 -3
  8. package/build/intl/locale.js.map +1 -1
  9. package/build/intl/localeObject.d.ts +0 -5
  10. package/build/intl/localeObject.js +0 -7
  11. package/build/intl/localeObject.js.map +1 -1
  12. package/build/sentry/client.d.ts +1 -1
  13. package/build/sentry/client.js.map +1 -1
  14. package/build/sentry/common.d.ts +1 -1
  15. package/build/sentry/common.js +27 -16
  16. package/build/sentry/common.js.map +1 -1
  17. package/build/sentry/server.d.ts +1 -1
  18. package/build/sentry/server.js.map +1 -1
  19. package/build/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +3 -3
  21. package/src/components-nextjs/PageSeo/PageSeo.tsx +23 -15
  22. package/src/components-nextjs/document.tsx +1 -0
  23. package/src/intl/index.ts +1 -2
  24. package/src/intl/locale.ts +1 -5
  25. package/src/intl/localeObject.ts +0 -8
  26. package/src/sentry/client.ts +4 -1
  27. package/src/sentry/common.ts +43 -30
  28. package/src/sentry/server.ts +4 -1
  29. package/build/intl/getFallbackLocale.d.ts +0 -10
  30. package/build/intl/getFallbackLocale.js +0 -24
  31. package/build/intl/getFallbackLocale.js.map +0 -1
  32. package/build/seo/getAlternateLanguageLinks.d.ts +0 -4
  33. package/build/seo/getAlternateLanguageLinks.js +0 -84
  34. package/build/seo/getAlternateLanguageLinks.js.map +0 -1
  35. package/build/seo/index.d.ts +0 -1
  36. package/build/seo/index.js +0 -18
  37. package/build/seo/index.js.map +0 -1
  38. package/build/seo/utils/bindLanguagesWithLocales.d.ts +0 -11
  39. package/build/seo/utils/bindLanguagesWithLocales.js +0 -23
  40. package/build/seo/utils/bindLanguagesWithLocales.js.map +0 -1
  41. package/build/seo/utils/createAlternateLanguageLink.d.ts +0 -5
  42. package/build/seo/utils/createAlternateLanguageLink.js +0 -15
  43. package/build/seo/utils/createAlternateLanguageLink.js.map +0 -1
  44. package/src/intl/getFallbackLocale.ts +0 -29
  45. package/src/seo/getAlternateLanguageLinks.test.ts +0 -164
  46. package/src/seo/getAlternateLanguageLinks.ts +0 -115
  47. package/src/seo/index.ts +0 -1
  48. package/src/seo/utils/bindLanguagesWithLocales.ts +0 -31
  49. package/src/seo/utils/createAlternateLanguageLink.ts +0 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-nextjs",
3
- "version": "3.2.4-0",
3
+ "version": "3.2.4",
4
4
  "description": "Data layer and utility library for developing Prezly themes with NextJS",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -56,14 +56,14 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@prezly/eslint-config": "4.4.1",
59
- "@sentry/nextjs": "7.38.0",
59
+ "@sentry/nextjs": "7.41.0",
60
60
  "@types/jest": "29.4.0",
61
61
  "@types/node": "17.0.14",
62
62
  "@types/parse-data-url": "3.0.0",
63
63
  "@types/react": "18.0.28",
64
64
  "@types/react-dom": "18.0.11",
65
65
  "eslint": "8.35.0",
66
- "jest": "29.4.3",
66
+ "jest": "29.5.0",
67
67
  "np": "7.6.3",
68
68
  "prettier": "2.8.4",
69
69
  "rimraf": "3.0.2",
@@ -3,7 +3,7 @@ import type { NextSeoProps } from 'next-seo';
3
3
  import { useRouter } from 'next/router';
4
4
  import { useMemo } from 'react';
5
5
 
6
- import { getUsedLanguages } from '../../intl';
6
+ import { getUsedLanguages, LocaleObject } from '../../intl';
7
7
  import {
8
8
  useCompanyInformation,
9
9
  useCurrentLocale,
@@ -13,7 +13,6 @@ import {
13
13
  useLanguages,
14
14
  useNewsroom,
15
15
  } from '../../newsroom-context';
16
- import { getAlternateLanguageLinks } from '../../seo';
17
16
  import { getNewsroomLogoUrl } from '../../utils';
18
17
 
19
18
  import { getAbsoluteUrl } from './lib/getAbsoluteUrl';
@@ -66,22 +65,31 @@ export function PageSeo({
66
65
  return [];
67
66
  }
68
67
 
69
- const usedLanguages = getUsedLanguages(languages);
68
+ const alternateLanguages = getUsedLanguages(languages).filter(
69
+ (language) => language.code !== currentLocale.toUnderscoreCode(),
70
+ );
70
71
 
71
- return getAlternateLanguageLinks(usedLanguages, (locale) => {
72
- const translationUrl = getTranslationUrl(locale);
72
+ return alternateLanguages
73
+ .map((language) => {
74
+ const locale = LocaleObject.fromAnyCode(language.code);
73
75
 
74
- if (!translationUrl) {
75
- return undefined;
76
- }
76
+ const translationLink = getTranslationUrl(locale, true);
77
77
 
78
- return getAbsoluteUrl(
79
- translationUrl,
80
- site.url,
81
- currentStory && translationUrl !== '/' ? false : getLinkLocaleSlug(locale),
82
- );
83
- });
84
- }, [currentStory, getLinkLocaleSlug, getTranslationUrl, languages, site.url]);
78
+ if (!translationLink) {
79
+ return undefined;
80
+ }
81
+
82
+ return {
83
+ hrefLang: locale.toHyphenCode(),
84
+ href: getAbsoluteUrl(
85
+ translationLink,
86
+ site.url,
87
+ currentStory && translationLink !== '/' ? false : getLinkLocaleSlug(locale),
88
+ ),
89
+ };
90
+ })
91
+ .filter<AlternateLanguageLink>(Boolean as any);
92
+ }, [currentLocale, getLinkLocaleSlug, getTranslationUrl, languages, site.url, currentStory]);
85
93
 
86
94
  return (
87
95
  <NextSeo
@@ -26,6 +26,7 @@ export class PrezlyThemeDocument extends Document {
26
26
  <Html lang={locale.toHyphenCode()} dir={direction}>
27
27
  <Head>
28
28
  <meta name="og:locale" content={locale.toHyphenCode()} />
29
+ {/* TODO: Add alternate locales */}
29
30
  </Head>
30
31
  <body>
31
32
  <Main />
package/src/intl/index.ts CHANGED
@@ -1,5 +1,4 @@
1
- export * from './getFallbackLocale';
2
1
  export * from './languages';
3
- export { default as localeConfig } from './localeConfig';
4
2
  export * from './locale';
3
+ export { default as localeConfig } from './localeConfig';
5
4
  export * from './localeObject';
@@ -8,15 +8,11 @@ export const DEFAULT_LOCALE = 'en';
8
8
  // We use pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
9
9
  export const DUMMY_DEFAULT_LOCALE = 'qps-ploc';
10
10
 
11
- export type LangCode = string;
12
- export type RegionCode = string;
13
- export type LocaleCode = string;
14
-
15
11
  /**
16
12
  * This a list of locales that Prezly has translations for. Each code represents a language file in the `@prezly/themes-intl-messages` package.
17
13
  * See https://github.com/prezly/themes-intl-messages for more info.
18
14
  */
19
- const SUPPORTED_LOCALES: LocaleCode[] = [
15
+ const SUPPORTED_LOCALES = [
20
16
  'af',
21
17
  'ar',
22
18
  'az',
@@ -12,12 +12,6 @@ export class LocaleObject {
12
12
  */
13
13
  private localeCode: string;
14
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
15
  private constructor(localeCode: string) {
22
16
  if (!/^([a-z]{2,3})(-[a-z\d]{1,4})?$/i.test(localeCode)) {
23
17
  throw new Error('Invalid locale code provided!');
@@ -26,13 +20,11 @@ export class LocaleObject {
26
20
  const [language, region] = localeCode.split('-');
27
21
 
28
22
  if (region) {
29
- this.isRegionIndependent = false;
30
23
  // Workaround for `zh-Hant` locale, which is the only locale with non-uppercase region part
31
24
  const regionSuffix = region === 'hant' ? 'Hant' : region.toUpperCase();
32
25
 
33
26
  this.localeCode = [language, regionSuffix].join('-');
34
27
  } else {
35
- this.isRegionIndependent = true;
36
28
  this.localeCode = language;
37
29
  }
38
30
  }
@@ -2,6 +2,9 @@ import type { init } from '@sentry/nextjs';
2
2
 
3
3
  import { getCommonClientOptions } from './common';
4
4
 
5
- export function getSentryClientOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
5
+ export function getSentryClientOptions(
6
+ dsn: string,
7
+ themeName: string | null,
8
+ ): Parameters<typeof init>[0] {
6
9
  return getCommonClientOptions(dsn, themeName);
7
10
  }
@@ -1,14 +1,50 @@
1
- import type { init } from '@sentry/nextjs';
1
+ import type { Exception, init, StackFrame } from '@sentry/nextjs';
2
2
 
3
3
  const IGNORED_EVENT_CULPRITS = [
4
4
  // This usually means that something happened outside of application code.
5
5
  // All instances of errors with this origin that I found usually were caused by referring to variables that couldn't ever exist in our code.
6
6
  // Likely misbehaving browser extensions or people playing around in DevTools trying to break the app.
7
+ '<anonymous>',
7
8
  '?(<anonymous>)',
8
9
  'global code',
9
10
  ];
10
11
 
11
- export function getCommonClientOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
12
+ function shouldStackFrameBeIgnored(frame: StackFrame) {
13
+ const { abs_path, function: frameFunction } = frame;
14
+
15
+ if (
16
+ abs_path &&
17
+ IGNORED_EVENT_CULPRITS.some((ignoredCulprit) => abs_path.includes(ignoredCulprit))
18
+ ) {
19
+ return true;
20
+ }
21
+
22
+ if (
23
+ frameFunction &&
24
+ IGNORED_EVENT_CULPRITS.some((ignoredCulprit) => frameFunction.includes(ignoredCulprit))
25
+ ) {
26
+ return true;
27
+ }
28
+
29
+ return false;
30
+ }
31
+
32
+ function shouldExceptionBeIgnored(exception: Exception) {
33
+ const { stacktrace } = exception;
34
+
35
+ // Ignore global code errors that are not related to the application code.
36
+ // See comments in `IGNORED_EVENT_CULPRITS` const for context on each entry
37
+ if (stacktrace && stacktrace.frames?.some(shouldStackFrameBeIgnored)) {
38
+ return true;
39
+ }
40
+
41
+ return false;
42
+ }
43
+
44
+ export function getCommonClientOptions(
45
+ dsn: string,
46
+ themeName: string | null,
47
+ ): Parameters<typeof init>[0] {
12
48
  return {
13
49
  dsn,
14
50
  // Adjust this value in production, or use tracesSampler for greater control
@@ -27,34 +63,9 @@ export function getCommonClientOptions(dsn: string, themeName: string): Paramete
27
63
  'Illegal invocation',
28
64
  ],
29
65
 
30
- // Ignore global code errors that are not related to the application code.
31
- // See comments in `IGNORED_EVENT_CULPRITS` const for context on each entry
32
66
  beforeSend: (event) => {
33
- // `culprit` is not a documented property, but it is present in all Sentry events and is even displayed in the interface.
34
- // Just in case it's not defined, we can fallback to the stack trace.
35
- if ('culprit' in event && typeof event.culprit === 'string') {
36
- const { culprit } = event;
37
- if (
38
- IGNORED_EVENT_CULPRITS.some((ignoredCulprit) =>
39
- culprit.includes(ignoredCulprit),
40
- )
41
- ) {
42
- return null;
43
- }
44
- } else if (event.exception) {
45
- if (
46
- event.exception.values?.some((value) =>
47
- value.stacktrace?.frames?.some(
48
- (frame) =>
49
- frame.abs_path &&
50
- IGNORED_EVENT_CULPRITS.some((ignoredCulprit) =>
51
- frame.abs_path?.includes(ignoredCulprit),
52
- ),
53
- ),
54
- )
55
- ) {
56
- return null;
57
- }
67
+ if (event.exception?.values?.every(shouldExceptionBeIgnored)) {
68
+ return null;
58
69
  }
59
70
 
60
71
  return event;
@@ -62,7 +73,9 @@ export function getCommonClientOptions(dsn: string, themeName: string): Paramete
62
73
 
63
74
  // Attach theme tag to each event
64
75
  initialScope: (scope) => {
65
- scope.setTags({ prezly_theme: themeName });
76
+ if (themeName) {
77
+ scope.setTags({ prezly_theme: themeName });
78
+ }
66
79
  return scope;
67
80
  },
68
81
  };
@@ -2,6 +2,9 @@ import type { init } from '@sentry/nextjs';
2
2
 
3
3
  import { getCommonClientOptions } from './common';
4
4
 
5
- export function getSentryServerOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
5
+ export function getSentryServerOptions(
6
+ dsn: string,
7
+ themeName: string | null,
8
+ ): Parameters<typeof init>[0] {
6
9
  return getCommonClientOptions(dsn, themeName);
7
10
  }
@@ -1,10 +0,0 @@
1
- import type { LangCode } from './locale';
2
- import { LocaleObject } from './localeObject';
3
- /**
4
- * Fallback locales for each region independent locale.
5
- * For example, a story has en-CA en-AU and en-GB locales. As you can see there is no region independent locale.
6
- * We will use a list of possible fallbacks to determine region independent locale alias.
7
- * In the provided example the result will be en-GB since it is defined in the localeFallback list
8
- * If the list will be en-CA en-AU and en-US then the result will be en-US since it is the first one and hence takes precedence.
9
- */
10
- export declare function getFallbackLocale(langCode: LangCode, availableLocales: LocaleObject[]): LocaleObject | undefined;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFallbackLocale = void 0;
4
- const localeObject_1 = require("./localeObject");
5
- const localeFallback = {
6
- en: [localeObject_1.LocaleObject.fromAnyCode('en-US'), localeObject_1.LocaleObject.fromAnyCode('en-GB')],
7
- fr: [localeObject_1.LocaleObject.fromAnyCode('fr-FR'), localeObject_1.LocaleObject.fromAnyCode('fr-CA')],
8
- };
9
- /**
10
- * Fallback locales for each region independent locale.
11
- * For example, a story has en-CA en-AU and en-GB locales. As you can see there is no region independent locale.
12
- * We will use a list of possible fallbacks to determine region independent locale alias.
13
- * In the provided example the result will be en-GB since it is defined in the localeFallback list
14
- * If the list will be en-CA en-AU and en-US then the result will be en-US since it is the first one and hence takes precedence.
15
- */
16
- function getFallbackLocale(langCode, availableLocales) {
17
- const fallbacks = localeFallback[langCode];
18
- if (!fallbacks) {
19
- return undefined;
20
- }
21
- return fallbacks.find((fallback) => Boolean(availableLocales.find((available) => available.isEqual(fallback))));
22
- }
23
- exports.getFallbackLocale = getFallbackLocale;
24
- //# sourceMappingURL=getFallbackLocale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFallbackLocale.js","sourceRoot":"","sources":["../../src/intl/getFallbackLocale.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAE9C,MAAM,cAAc,GAAqC;IACrD,EAAE,EAAE,CAAC,2BAAY,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,2BAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1E,EAAE,EAAE,CAAC,2BAAY,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,2BAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;CAC7E,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC7B,QAAkB,EAClB,gBAAgC;IAEhC,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE3C,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC/B,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC7E,CAAC;AACN,CAAC;AAbD,8CAaC"}
@@ -1,4 +0,0 @@
1
- import type { NewsroomLanguageSettings } from '@prezly/sdk';
2
- import type { AlternateLanguageLink } from '../components-nextjs/PageSeo';
3
- import type { LocaleObject } from '../intl';
4
- export declare function getAlternateLanguageLinks(availableLanguages: NewsroomLanguageSettings[], generateTranslationUrl: (locale: LocaleObject) => string | undefined): AlternateLanguageLink[];
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAlternateLanguageLinks = void 0;
4
- const intl_1 = require("../intl");
5
- const bindLanguagesWithLocales_1 = require("./utils/bindLanguagesWithLocales");
6
- const createAlternateLanguageLink_1 = require("./utils/createAlternateLanguageLink");
7
- function getAlternateLanguageLinks(availableLanguages, generateTranslationUrl) {
8
- const languagesWithLocales = (0, bindLanguagesWithLocales_1.bindLanguagesWithLocales)(availableLanguages);
9
- const hrefLangLinks = [];
10
- function pushLocaleToLinks(locale, hrefLang) {
11
- const link = (0, createAlternateLanguageLink_1.createAlternateLanguageLink)(locale, generateTranslationUrl);
12
- if (!link) {
13
- return;
14
- }
15
- if (hrefLang) {
16
- hrefLangLinks.push({ ...link, hrefLang });
17
- }
18
- else {
19
- hrefLangLinks.push(link);
20
- }
21
- }
22
- function populateDirectLinks() {
23
- languagesWithLocales.forEach((binds) => binds.forEach(({ locale }) => pushLocaleToLinks(locale)));
24
- }
25
- function populateRegionIndependentLinks() {
26
- languagesWithLocales.forEach((binds, regionIndependentLocaleCode) => {
27
- // When there is no region independent locale of provided locales
28
- // we still need something as a region independent locale
29
- const localesArray = Array.from(binds.values()).map(({ locale }) => locale);
30
- const hasRegionIndependentLocale = localesArray.some((locale) => locale.isRegionIndependent);
31
- if (hasRegionIndependentLocale) {
32
- return;
33
- }
34
- // Try to find some possible fallback for the regionIndependentLocaleCode from hardcoded list
35
- // We try to find fallback from provided translations of current regionIndependentLocaleCode
36
- // If there is no defined fallback in the list we will use just first translation as a region independent translation
37
- const fallback = (0, intl_1.getFallbackLocale)(regionIndependentLocaleCode, localesArray) ?? localesArray.at(0);
38
- if (fallback) {
39
- pushLocaleToLinks(fallback, regionIndependentLocaleCode);
40
- }
41
- });
42
- }
43
- function populateDefault() {
44
- // We use english locale as fallback since English is the most common language
45
- const engFallback = 'en';
46
- const defaultHrefLang = 'x-default';
47
- let isDefaultAddedToLinks = false;
48
- // First we try to find region independent english locale (en)
49
- // If the story has just region independent `en` translation we will use it as default hreflang
50
- languagesWithLocales.forEach((binds) => binds.forEach(({ locale }) => {
51
- if (locale.isRegionIndependent && locale.toNeutralLanguageCode() === engFallback) {
52
- pushLocaleToLinks(locale, defaultHrefLang);
53
- isDefaultAddedToLinks = true;
54
- }
55
- }));
56
- if (!isDefaultAddedToLinks) {
57
- // If there is no explicit region independent `en` translation for this story
58
- // we will try to find some link that already has `en` fallback
59
- const fallbackFromRegionIndependentLocales = hrefLangLinks.find((alternate) => alternate.hrefLang === engFallback);
60
- if (fallbackFromRegionIndependentLocales) {
61
- hrefLangLinks.push({
62
- ...fallbackFromRegionIndependentLocales,
63
- hrefLang: defaultHrefLang,
64
- });
65
- isDefaultAddedToLinks = true;
66
- }
67
- }
68
- if (!isDefaultAddedToLinks) {
69
- // If there is no english locale at all we will use is_default language (provided from server)
70
- languagesWithLocales.forEach((binds) => binds.forEach(({ locale, language }) => {
71
- if (language.is_default) {
72
- pushLocaleToLinks(locale, defaultHrefLang);
73
- isDefaultAddedToLinks = true;
74
- }
75
- }));
76
- }
77
- }
78
- populateDirectLinks();
79
- populateRegionIndependentLinks();
80
- populateDefault();
81
- return hrefLangLinks.sort((a, b) => a.hrefLang.localeCompare(b.hrefLang));
82
- }
83
- exports.getAlternateLanguageLinks = getAlternateLanguageLinks;
84
- //# sourceMappingURL=getAlternateLanguageLinks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getAlternateLanguageLinks.js","sourceRoot":"","sources":["../../src/seo/getAlternateLanguageLinks.ts"],"names":[],"mappings":"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"}
@@ -1 +0,0 @@
1
- export * from './getAlternateLanguageLinks';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getAlternateLanguageLinks"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
@@ -1,11 +0,0 @@
1
- import type { NewsroomLanguageSettings } from '@prezly/sdk';
2
- import { LocaleObject } from '../../intl';
3
- interface LocaleWithLanguage {
4
- language: NewsroomLanguageSettings;
5
- locale: LocaleObject;
6
- }
7
- /**
8
- * Group languages by their region independent language code (e.g. "en" for "en-US" and "en-GB").
9
- */
10
- export declare function bindLanguagesWithLocales(languages: NewsroomLanguageSettings[]): Map<string, Map<string, LocaleWithLanguage>>;
11
- export {};
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bindLanguagesWithLocales = void 0;
4
- const intl_1 = require("../../intl");
5
- /**
6
- * Group languages by their region independent language code (e.g. "en" for "en-US" and "en-GB").
7
- */
8
- function bindLanguagesWithLocales(languages) {
9
- const localesByLangCode = new Map();
10
- languages.forEach((language) => {
11
- const languageLocale = intl_1.LocaleObject.fromAnyCode(language.code);
12
- const regionIndependentLanguageCode = languageLocale.toNeutralLanguageCode();
13
- let currentLocale = localesByLangCode.get(regionIndependentLanguageCode);
14
- if (!currentLocale) {
15
- currentLocale = new Map();
16
- localesByLangCode.set(regionIndependentLanguageCode, currentLocale);
17
- }
18
- currentLocale.set(languageLocale.toHyphenCode(), { language, locale: languageLocale });
19
- });
20
- return localesByLangCode;
21
- }
22
- exports.bindLanguagesWithLocales = bindLanguagesWithLocales;
23
- //# sourceMappingURL=bindLanguagesWithLocales.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bindLanguagesWithLocales.js","sourceRoot":"","sources":["../../../src/seo/utils/bindLanguagesWithLocales.ts"],"names":[],"mappings":";;;AAGA,qCAA0C;AAO1C;;GAEG;AACH,SAAgB,wBAAwB,CAAC,SAAqC;IAC1E,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAiD,CAAC;IAEnF,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC3B,MAAM,cAAc,GAAG,mBAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/D,MAAM,6BAA6B,GAAG,cAAc,CAAC,qBAAqB,EAAE,CAAC;QAC7E,IAAI,aAAa,GAAG,iBAAiB,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAEzE,IAAI,CAAC,aAAa,EAAE;YAChB,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;YAC1B,iBAAiB,CAAC,GAAG,CAAC,6BAA6B,EAAE,aAAa,CAAC,CAAC;SACvE;QAED,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC7B,CAAC;AAjBD,4DAiBC"}
@@ -1,5 +0,0 @@
1
- import type { LocaleObject } from '../../intl';
2
- export declare function createAlternateLanguageLink(locale: LocaleObject, generateTranslationUrl: (locale: LocaleObject) => string | undefined): {
3
- hrefLang: string;
4
- href: string;
5
- } | undefined;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAlternateLanguageLink = void 0;
4
- function createAlternateLanguageLink(locale, generateTranslationUrl) {
5
- const translationUrl = generateTranslationUrl(locale);
6
- if (!translationUrl) {
7
- return undefined;
8
- }
9
- return {
10
- hrefLang: locale.toHyphenCode(),
11
- href: translationUrl,
12
- };
13
- }
14
- exports.createAlternateLanguageLink = createAlternateLanguageLink;
15
- //# sourceMappingURL=createAlternateLanguageLink.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAlternateLanguageLink.js","sourceRoot":"","sources":["../../../src/seo/utils/createAlternateLanguageLink.ts"],"names":[],"mappings":";;;AAEA,SAAgB,2BAA2B,CACvC,MAAoB,EACpB,sBAAoE;IAEpE,MAAM,cAAc,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAEtD,IAAI,CAAC,cAAc,EAAE;QACjB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO;QACH,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE;QAC/B,IAAI,EAAE,cAAc;KACvB,CAAC;AACN,CAAC;AAdD,kEAcC"}
@@ -1,29 +0,0 @@
1
- import type { LangCode } from './locale';
2
- import { LocaleObject } from './localeObject';
3
-
4
- const localeFallback: Record<LangCode, LocaleObject[]> = {
5
- en: [LocaleObject.fromAnyCode('en-US'), LocaleObject.fromAnyCode('en-GB')],
6
- fr: [LocaleObject.fromAnyCode('fr-FR'), LocaleObject.fromAnyCode('fr-CA')],
7
- };
8
-
9
- /**
10
- * Fallback locales for each region independent locale.
11
- * For example, a story has en-CA en-AU and en-GB locales. As you can see there is no region independent locale.
12
- * We will use a list of possible fallbacks to determine region independent locale alias.
13
- * In the provided example the result will be en-GB since it is defined in the localeFallback list
14
- * If the list will be en-CA en-AU and en-US then the result will be en-US since it is the first one and hence takes precedence.
15
- */
16
- export function getFallbackLocale(
17
- langCode: LangCode,
18
- availableLocales: LocaleObject[],
19
- ): LocaleObject | undefined {
20
- const fallbacks = localeFallback[langCode];
21
-
22
- if (!fallbacks) {
23
- return undefined;
24
- }
25
-
26
- return fallbacks.find((fallback) =>
27
- Boolean(availableLocales.find((available) => available.isEqual(fallback))),
28
- );
29
- }