@prezly/theme-kit-nextjs 1.15.1 → 1.16.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/build/adapter-nextjs/api-handlers/fetchGalleries.js +16 -66
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +18 -68
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +9 -59
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +9 -59
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.d.ts +1 -1
- package/build/adapter-nextjs/page-props/category.js +94 -195
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.d.ts +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +58 -135
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.d.ts +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +40 -132
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.d.ts +1 -1
- package/build/adapter-nextjs/page-props/home.js +56 -135
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/search.d.ts +2 -2
- package/build/adapter-nextjs/page-props/search.js +19 -96
- package/build/adapter-nextjs/page-props/search.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +18 -18
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js +9 -40
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +28 -76
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/story.d.ts +1 -1
- package/build/adapter-nextjs/page-props/story.js +57 -159
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +20 -81
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +8 -19
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/adapter-nextjs/processStaticRequest.js +2 -13
- package/build/adapter-nextjs/processStaticRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +41 -52
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +1 -1
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
- package/build/components-nextjs/StorySeo/StorySeo.js +27 -31
- package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/components-nextjs/document.d.ts +6 -0
- package/build/components-nextjs/document.js +48 -0
- package/build/components-nextjs/document.js.map +1 -0
- package/build/components-nextjs/index.d.ts +1 -0
- package/build/components-nextjs/index.js +3 -1
- package/build/components-nextjs/index.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.js +170 -355
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +3 -3
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/queries.js +8 -32
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.js +5 -5
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +10 -21
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/data-fetching/lib/isUuid.js +1 -1
- package/build/data-fetching/lib/isUuid.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/infinite-loading/useInfiniteGalleriesLoading.js +25 -79
- package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +22 -94
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.js +36 -95
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/languages.js +35 -68
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.js +13 -13
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.js +11 -32
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeObject.js +30 -42
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.js +17 -29
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +2 -2
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.js +2 -2
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +2 -2
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.js +2 -2
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +2 -2
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.js +2 -2
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +8 -8
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +14 -19
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +2 -2
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +2 -2
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.js +3 -3
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/sentry/client.d.ts +2 -0
- package/build/sentry/client.js +9 -0
- package/build/sentry/client.js.map +1 -0
- package/build/sentry/common.d.ts +2 -0
- package/build/sentry/common.js +29 -0
- package/build/sentry/common.js.map +1 -0
- package/build/sentry/index.d.ts +2 -0
- package/build/sentry/index.js +8 -0
- package/build/sentry/index.js.map +1 -0
- package/build/sentry/server.d.ts +2 -0
- package/build/sentry/server.js +9 -0
- package/build/sentry/server.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/utils/getAssetsUrl.js +2 -2
- package/build/utils/getAssetsUrl.js.map +1 -1
- package/build/utils/getDataRequestLink.js +1 -1
- package/build/utils/getDataRequestLink.js.map +1 -1
- package/build/utils/getLocalizedCategoryData.js +12 -23
- package/build/utils/getLocalizedCategoryData.js.map +1 -1
- package/build/utils/getNewsroomLogoUrl.js +4 -5
- package/build/utils/getNewsroomLogoUrl.js.map +1 -1
- package/build/utils/getPrivacyPortalUrl.js +2 -2
- package/build/utils/getPrivacyPortalUrl.js.map +1 -1
- package/build/utils/getStoryPublicationDate.js +1 -1
- package/build/utils/getStoryPublicationDate.js.map +1 -1
- package/build/utils/getUploadcareGroupUrl.js +2 -2
- package/build/utils/getUploadcareGroupUrl.js.map +1 -1
- package/package.json +2 -1
- package/src/adapter-nextjs/page-props/category.ts +1 -1
- package/src/adapter-nextjs/page-props/gallery.ts +1 -1
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +1 -1
- package/src/adapter-nextjs/page-props/home.ts +1 -1
- package/src/adapter-nextjs/page-props/search.ts +1 -1
- package/src/adapter-nextjs/page-props/story.ts +1 -1
- package/src/components-nextjs/document.tsx +38 -0
- package/src/components-nextjs/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/sentry/client.ts +7 -0
- package/src/sentry/common.ts +27 -0
- package/src/sentry/index.ts +2 -0
- package/src/sentry/server.ts +7 -0
|
@@ -1,81 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.useInfiniteStoriesLoading = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
function fetchStories(page, pageSize, category, locale, include) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
result = _a.sent();
|
|
70
|
-
if (!!result.ok) return [3 /*break*/, 3];
|
|
71
|
-
return [4 /*yield*/, result.json()];
|
|
72
|
-
case 2:
|
|
73
|
-
message = (_a.sent()).message;
|
|
74
|
-
throw new Error(message);
|
|
75
|
-
case 3: return [2 /*return*/, result.json()];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const newsroom_context_1 = require("../newsroom-context");
|
|
6
|
+
const useInfiniteLoading_1 = require("./useInfiniteLoading");
|
|
7
|
+
async function fetchStories(page, pageSize, category, locale, include) {
|
|
8
|
+
const result = await fetch('/api/fetch-stories', {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
page,
|
|
15
|
+
pageSize,
|
|
16
|
+
category,
|
|
17
|
+
include,
|
|
18
|
+
...(locale && {
|
|
19
|
+
localeCode: locale.toUnderscoreCode(),
|
|
20
|
+
}),
|
|
21
|
+
}),
|
|
78
22
|
});
|
|
23
|
+
if (!result.ok) {
|
|
24
|
+
const { message } = await result.json();
|
|
25
|
+
throw new Error(message);
|
|
26
|
+
}
|
|
27
|
+
return result.json();
|
|
79
28
|
}
|
|
80
29
|
/**
|
|
81
30
|
* NOTE: This hook depends on the presence of a Next API route (/api/fetch-stories)!
|
|
@@ -83,31 +32,23 @@ function fetchStories(page, pageSize, category, locale, include) {
|
|
|
83
32
|
* See https://github.com/prezly/theme-nextjs-bea/blob/d381e9878187ca98815d240d3ffdf10a75993c14/pages/index.tsx#L24 for usage example
|
|
84
33
|
*/
|
|
85
34
|
function useInfiniteStoriesLoading(initialStories, pagination, category, include) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
switch (_a.label) {
|
|
93
|
-
case 0: return [4 /*yield*/, fetchStories(nextPage, pageSize, category, currentLocale, include)];
|
|
94
|
-
case 1:
|
|
95
|
-
stories = (_a.sent()).stories;
|
|
96
|
-
return [2 /*return*/, stories];
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}); },
|
|
35
|
+
const currentLocale = (0, newsroom_context_1.useCurrentLocale)();
|
|
36
|
+
const { canLoadMore, data, isLoading, loadMore, resetData } = (0, useInfiniteLoading_1.useInfiniteLoading)({
|
|
37
|
+
fetchingFn: async (nextPage, pageSize) => {
|
|
38
|
+
const { stories } = await fetchStories(nextPage, pageSize, category, currentLocale, include);
|
|
39
|
+
return stories;
|
|
40
|
+
},
|
|
100
41
|
initialData: initialStories,
|
|
101
|
-
pagination
|
|
102
|
-
})
|
|
103
|
-
(0, react_1.useEffect)(
|
|
104
|
-
if (category
|
|
42
|
+
pagination,
|
|
43
|
+
});
|
|
44
|
+
(0, react_1.useEffect)(() => {
|
|
45
|
+
if (category?.id) {
|
|
105
46
|
resetData();
|
|
106
47
|
}
|
|
107
|
-
}, [category
|
|
48
|
+
}, [category?.id, resetData]);
|
|
108
49
|
return {
|
|
109
|
-
canLoadMore
|
|
110
|
-
isLoading
|
|
50
|
+
canLoadMore,
|
|
51
|
+
isLoading,
|
|
111
52
|
loadMoreStories: loadMore,
|
|
112
53
|
stories: data,
|
|
113
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteStoriesLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteStoriesLoading.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useInfiniteStoriesLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteStoriesLoading.ts"],"names":[],"mappings":";;;AACA,iCAAkC;AAGlC,0DAAuD;AAGvD,6DAA0D;AAE1D,KAAK,UAAU,YAAY,CACvB,IAAY,EACZ,QAAgB,EAChB,QAAmB,EACnB,MAAqB,EACrB,OAAoC;IAEpC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE;QAC7C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;SACrC;QACD,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
|
package/build/intl/languages.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getShortestLocaleCode = exports.getCompanyInformation = exports.getLanguageFromStory = exports.getLanguageFromNextLocaleIsoCode = exports.getLanguageByShortRegionCode = exports.getLanguageByNeutralLocaleCode = exports.getLanguageByExactLocaleCode = exports.getUsedLanguages = exports.getDefaultLanguage = exports.getLanguageDisplayName = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const locale_1 = require("./locale");
|
|
5
|
+
const localeObject_1 = require("./localeObject");
|
|
6
6
|
function isOnlyCulture(culture, languages) {
|
|
7
|
-
|
|
8
|
-
var language_code = _a.locale.language_code;
|
|
9
|
-
return language_code === culture.language_code;
|
|
10
|
-
}).length;
|
|
7
|
+
const numberOfLanguages = languages.filter(({ locale: { language_code } }) => language_code === culture.language_code).length;
|
|
11
8
|
return numberOfLanguages === 1;
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
@@ -23,9 +20,9 @@ function isOnlyCulture(culture, languages) {
|
|
|
23
20
|
* - -> English (Global), English (UK), Spanish
|
|
24
21
|
*/
|
|
25
22
|
function getLanguageDisplayName(language, languages) {
|
|
26
|
-
|
|
23
|
+
const { locale } = language;
|
|
27
24
|
if (isOnlyCulture(locale, languages)) {
|
|
28
|
-
|
|
25
|
+
const cultureNameIndex = locale.native_name.indexOf('(');
|
|
29
26
|
if (cultureNameIndex !== -1) {
|
|
30
27
|
return locale.native_name.slice(0, cultureNameIndex - 1);
|
|
31
28
|
}
|
|
@@ -37,74 +34,56 @@ exports.getLanguageDisplayName = getLanguageDisplayName;
|
|
|
37
34
|
* @returns Language set as default in the Newsroom Settings.
|
|
38
35
|
*/
|
|
39
36
|
function getDefaultLanguage(languages) {
|
|
40
|
-
return languages.find(
|
|
41
|
-
var is_default = _a.is_default;
|
|
42
|
-
return is_default;
|
|
43
|
-
}) || languages[0];
|
|
37
|
+
return languages.find(({ is_default }) => is_default) || languages[0];
|
|
44
38
|
}
|
|
45
39
|
exports.getDefaultLanguage = getDefaultLanguage;
|
|
46
40
|
/**
|
|
47
41
|
* @returns Only languages having at least one published story
|
|
48
42
|
*/
|
|
49
43
|
function getUsedLanguages(languages) {
|
|
50
|
-
return languages.filter(
|
|
44
|
+
return languages.filter((language) => language.public_stories_count > 0);
|
|
51
45
|
}
|
|
52
46
|
exports.getUsedLanguages = getUsedLanguages;
|
|
53
47
|
function getLanguageByExactLocaleCode(languages, locale) {
|
|
54
|
-
|
|
55
|
-
return languages.find(
|
|
56
|
-
var code = _a.code;
|
|
57
|
-
return code === localeCode;
|
|
58
|
-
});
|
|
48
|
+
const localeCode = locale.toUnderscoreCode();
|
|
49
|
+
return languages.find(({ code }) => code === localeCode);
|
|
59
50
|
}
|
|
60
51
|
exports.getLanguageByExactLocaleCode = getLanguageByExactLocaleCode;
|
|
61
52
|
// See https://github.com/prezly/prezly/blob/master/lib/model/CulturePeer.php#L123
|
|
62
53
|
function getLanguageByNeutralLocaleCode(languages, locale) {
|
|
63
|
-
|
|
54
|
+
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
64
55
|
// Prefer default language
|
|
65
|
-
|
|
56
|
+
const defaultLanguage = getDefaultLanguage(languages);
|
|
66
57
|
// TODO: This doesn't align with other methods logic
|
|
67
58
|
if (defaultLanguage.code === locale.toUnderscoreCode()) {
|
|
68
59
|
return defaultLanguage;
|
|
69
60
|
}
|
|
70
61
|
// Try to look in used cultures first (giving priority to used ones)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var code = _a.code;
|
|
74
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode;
|
|
75
|
-
});
|
|
62
|
+
const usedLanguages = getUsedLanguages(languages);
|
|
63
|
+
const usedLanguage = usedLanguages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode);
|
|
76
64
|
if (usedLanguage) {
|
|
77
65
|
return usedLanguage;
|
|
78
66
|
}
|
|
79
67
|
// Search in all languages
|
|
80
|
-
return languages.find(
|
|
81
|
-
var code = _a.code;
|
|
82
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode;
|
|
83
|
-
});
|
|
68
|
+
return languages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode);
|
|
84
69
|
}
|
|
85
70
|
exports.getLanguageByNeutralLocaleCode = getLanguageByNeutralLocaleCode;
|
|
86
71
|
// See https://github.com/prezly/prezly/blob/master/lib/model/CulturePeer.php#L159
|
|
87
72
|
function getLanguageByShortRegionCode(languages, locale) {
|
|
88
|
-
|
|
73
|
+
const shortRegionCode = locale.toRegionCode();
|
|
89
74
|
// Prefer default language
|
|
90
|
-
|
|
75
|
+
const defaultLanguage = getDefaultLanguage(languages);
|
|
91
76
|
if (localeObject_1.LocaleObject.fromAnyCode(defaultLanguage.code).toRegionCode() === shortRegionCode) {
|
|
92
77
|
return defaultLanguage;
|
|
93
78
|
}
|
|
94
79
|
// Try to look in used cultures first (giving priority to used ones)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var code = _a.code;
|
|
98
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode;
|
|
99
|
-
});
|
|
80
|
+
const usedLanguages = getUsedLanguages(languages);
|
|
81
|
+
const usedLanguage = usedLanguages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
100
82
|
if (usedLanguage) {
|
|
101
83
|
return usedLanguage;
|
|
102
84
|
}
|
|
103
85
|
// Search in all languages
|
|
104
|
-
return languages.find(
|
|
105
|
-
var code = _a.code;
|
|
106
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode;
|
|
107
|
-
});
|
|
86
|
+
return languages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
108
87
|
}
|
|
109
88
|
exports.getLanguageByShortRegionCode = getLanguageByShortRegionCode;
|
|
110
89
|
/**
|
|
@@ -112,12 +91,12 @@ exports.getLanguageByShortRegionCode = getLanguageByShortRegionCode;
|
|
|
112
91
|
* Pulled from https://github.com/prezly/prezly/blob/de9900d9890a33502780494aa3fb85c9a732b3c3/lib/model/CulturePeer.php#L91-L114
|
|
113
92
|
*/
|
|
114
93
|
function getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode) {
|
|
115
|
-
|
|
94
|
+
const defaultLanguage = getDefaultLanguage(languages);
|
|
116
95
|
if (!nextLocaleIsoCode || nextLocaleIsoCode === locale_1.DUMMY_DEFAULT_LOCALE) {
|
|
117
96
|
return defaultLanguage;
|
|
118
97
|
}
|
|
119
|
-
|
|
120
|
-
|
|
98
|
+
const locale = localeObject_1.LocaleObject.fromAnyCode(nextLocaleIsoCode);
|
|
99
|
+
let targetLanguage;
|
|
121
100
|
if (nextLocaleIsoCode.length >= 2 && nextLocaleIsoCode.length <= 4) {
|
|
122
101
|
// The order of methods here is reversed from `getShortestLocaleCode`, so that the logic "unwraps" the possible variants with no collisions
|
|
123
102
|
targetLanguage =
|
|
@@ -132,18 +111,15 @@ function getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode) {
|
|
|
132
111
|
}
|
|
133
112
|
exports.getLanguageFromNextLocaleIsoCode = getLanguageFromNextLocaleIsoCode;
|
|
134
113
|
function getLanguageFromStory(languages, story) {
|
|
135
|
-
|
|
136
|
-
return languages.find(
|
|
137
|
-
var code = _a.code;
|
|
138
|
-
return code === storyLocaleCode;
|
|
139
|
-
});
|
|
114
|
+
const { code: storyLocaleCode } = story.culture;
|
|
115
|
+
return languages.find(({ code }) => code === storyLocaleCode);
|
|
140
116
|
}
|
|
141
117
|
exports.getLanguageFromStory = getLanguageFromStory;
|
|
142
118
|
/**
|
|
143
119
|
* Extracts company information for the selected locale
|
|
144
120
|
*/
|
|
145
121
|
function getCompanyInformation(languages, locale) {
|
|
146
|
-
|
|
122
|
+
const currentLanguage = getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);
|
|
147
123
|
return currentLanguage.company_information;
|
|
148
124
|
}
|
|
149
125
|
exports.getCompanyInformation = getCompanyInformation;
|
|
@@ -156,35 +132,26 @@ exports.getCompanyInformation = getCompanyInformation;
|
|
|
156
132
|
* @param locale A LocaleObject constructed from FULL locale code (taken straight from the selected language)
|
|
157
133
|
*/
|
|
158
134
|
function getShortestLocaleCode(languages, locale) {
|
|
159
|
-
|
|
160
|
-
|
|
135
|
+
const localeCode = locale.toUnderscoreCode();
|
|
136
|
+
const defaultLanguage = getDefaultLanguage(languages);
|
|
161
137
|
// If it's a default locale, return false (no locale needed in URL)
|
|
162
138
|
if (localeCode === defaultLanguage.code) {
|
|
163
139
|
return false;
|
|
164
140
|
}
|
|
165
141
|
// Try shorting to neutral language code
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode ||
|
|
170
|
-
code === neutralLanguageCode;
|
|
171
|
-
});
|
|
142
|
+
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
143
|
+
const matchingLanguagesByNeutralCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode ||
|
|
144
|
+
code === neutralLanguageCode);
|
|
172
145
|
if (matchingLanguagesByNeutralCode.length === 1) {
|
|
173
146
|
return neutralLanguageCode;
|
|
174
147
|
}
|
|
175
148
|
// Try shorting to region code
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
var code = _a.code;
|
|
179
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode;
|
|
180
|
-
});
|
|
149
|
+
const shortRegionCode = locale.toRegionCode();
|
|
150
|
+
const matchingLanguagesByRegionCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
181
151
|
// Prevent collision with neutral language codes
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === lowerCasedShortRegionCode ||
|
|
186
|
-
code === lowerCasedShortRegionCode;
|
|
187
|
-
});
|
|
152
|
+
const lowerCasedShortRegionCode = shortRegionCode.toLowerCase();
|
|
153
|
+
const mathchingNeutralLanguagesByRegionCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === lowerCasedShortRegionCode ||
|
|
154
|
+
code === lowerCasedShortRegionCode);
|
|
188
155
|
if (matchingLanguagesByRegionCode.length === 1 &&
|
|
189
156
|
// If there are 2 or more matching neutral languages, it means that there are no languages that can be shortened to neutral code
|
|
190
157
|
mathchingNeutralLanguagesByRegionCode.length !== 1 &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/intl/languages.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/intl/languages.ts"],"names":[],"mappings":";;;AAEA,qCAAgD;AAChD,iDAA8C;AAE9C,SAAS,aAAa,CAAC,OAAmB,EAAE,SAAqC;IAC7E,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,CACtC,CAAC,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,EAAE,CAAC,aAAa,KAAK,OAAO,CAAC,aAAa,CAC7E,CAAC,MAAM,CAAC;IAET,OAAO,iBAAiB,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,sBAAsB,CAClC,QAAkC,EAClC,SAAqC;IAErC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAE5B,IAAI,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,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I,qCAAqC,CAAC,MAAM,KAAK,CAAC;QAClD,gDAAgD;QAChD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,EACvC;QACE,OAAO,eAAe,CAAC;KAC1B;IAED,OAAO,UAAU,CAAC;AACtB,CAAC;AA7CD,sDA6CC"}
|
package/build/intl/locale.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLocaleDirection = exports.getRedirectToCanonicalLocale = exports.getSupportedLocaleIsoCode = exports.DUMMY_DEFAULT_LOCALE = exports.DEFAULT_LOCALE = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const querystring_1 = require("querystring");
|
|
5
|
+
const localeObject_1 = require("./localeObject");
|
|
6
6
|
exports.DEFAULT_LOCALE = 'en';
|
|
7
7
|
// We use pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
|
|
8
8
|
exports.DUMMY_DEFAULT_LOCALE = 'qps-ploc';
|
|
@@ -10,7 +10,7 @@ exports.DUMMY_DEFAULT_LOCALE = 'qps-ploc';
|
|
|
10
10
|
* This a list of locales that Prezly has translations for. Each code represents a language file in the `@prezly/themes-intl-messages` package.
|
|
11
11
|
* See https://github.com/prezly/themes-intl-messages for more info.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
const SUPPORTED_LOCALES = [
|
|
14
14
|
'af',
|
|
15
15
|
'ar',
|
|
16
16
|
'az',
|
|
@@ -64,13 +64,13 @@ var SUPPORTED_LOCALES = [
|
|
|
64
64
|
* See https://github.com/prezly/theme-nextjs-bea/blob/main/utils/lang.ts for a usage example.
|
|
65
65
|
*/
|
|
66
66
|
function getSupportedLocaleIsoCode(locale) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const localeIsoCode = locale.toHyphenCode();
|
|
68
|
+
const isSupportedLocale = localeIsoCode.length >= 2 && SUPPORTED_LOCALES.includes(localeIsoCode);
|
|
69
69
|
if (isSupportedLocale) {
|
|
70
70
|
return localeIsoCode;
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const language = locale.toNeutralLanguageCode();
|
|
73
|
+
const isSupportedLanguage = SUPPORTED_LOCALES.includes(language);
|
|
74
74
|
if (isSupportedLanguage) {
|
|
75
75
|
return language;
|
|
76
76
|
}
|
|
@@ -92,16 +92,16 @@ function getRedirectToCanonicalLocale(shortestLocaleCode, nextLocaleIsoCode, red
|
|
|
92
92
|
if (!nextLocaleIsoCode || nextLocaleIsoCode === exports.DUMMY_DEFAULT_LOCALE) {
|
|
93
93
|
return undefined;
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
const shortestLocaleSlug = shortestLocaleCode
|
|
96
96
|
? localeObject_1.LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
|
|
97
97
|
: shortestLocaleCode;
|
|
98
98
|
if (shortestLocaleSlug !== nextLocaleIsoCode) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const prefixedPath = redirectPath && !redirectPath.startsWith('/') ? `/${redirectPath}` : redirectPath;
|
|
100
|
+
const urlQuery = query ? `?${(0, querystring_1.stringify)(query)}` : '';
|
|
101
101
|
return {
|
|
102
102
|
destination: shortestLocaleSlug
|
|
103
|
-
?
|
|
104
|
-
:
|
|
103
|
+
? `/${shortestLocaleSlug}${prefixedPath}${urlQuery}`
|
|
104
|
+
: `${prefixedPath}${urlQuery}`,
|
|
105
105
|
permanent: false,
|
|
106
106
|
};
|
|
107
107
|
}
|
|
@@ -109,7 +109,7 @@ function getRedirectToCanonicalLocale(shortestLocaleCode, nextLocaleIsoCode, red
|
|
|
109
109
|
}
|
|
110
110
|
exports.getRedirectToCanonicalLocale = getRedirectToCanonicalLocale;
|
|
111
111
|
function getLocaleDirection(locale) {
|
|
112
|
-
|
|
112
|
+
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
113
113
|
if (['ar', 'he', 'ur'].includes(neutralLanguageCode)) {
|
|
114
114
|
return 'rtl';
|
|
115
115
|
}
|
package/build/intl/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AAEA,6CAAwC;AAExC,iDAA8C;AAEjC,QAAA,cAAc,GAAG,IAAI,CAAC;AACnC,oIAAoI;AACvH,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAE/C;;;GAGG;AACH,MAAM,iBAAiB,GAAG;IACtB,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,OAAO;CACV,CAAC;AAEF;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,MAAoB;IAC1D,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IAE5C,MAAM,iBAAiB,GACnB,aAAa,CAAC,MAAM,IAAI,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC3E,IAAI,iBAAiB,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IAAI,kBAAkB,GAAG,YAAY,GAAG,QAAQ,EAAE;gBACpD,CAAC,CAAC,GAAG,YAAY,GAAG,QAAQ,EAAE;YAClC,SAAS,EAAE,KAAK;SACnB,CAAC;KACL;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AA9BD,oEA8BC;AAED,SAAgB,kBAAkB,CAAC,MAAoB;IACnD,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAE3D,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;KAChB;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AARD,gDAQC"}
|
|
@@ -1,41 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
2
|
/**
|
|
28
3
|
* This list is pulled from the main Prezly application. The underscores are replaced with dashes.
|
|
29
4
|
* Together with permutation performed lower in the code,
|
|
30
5
|
* the exported list represents all of the possible locale codes that Next.js theme application might accept.
|
|
31
6
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
const supportedLocales = require('./localeList');
|
|
8
|
+
const lowercaseLocales = supportedLocales.map((l) => l.toLowerCase());
|
|
34
9
|
// Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes and neutral language codes)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
const lowercaseLocalPermutations = Array.from(new Set([
|
|
11
|
+
...lowercaseLocales,
|
|
12
|
+
...lowercaseLocales.map((code) => code.split('-')[0]),
|
|
13
|
+
...lowercaseLocales
|
|
14
|
+
.map((code) => code.split('-')[1])
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
// Remove number-only codes from possible permutations (like `419` for `es-419`)
|
|
17
|
+
.filter((code) => Number.isNaN(Number(code))),
|
|
18
|
+
])).sort();
|
|
40
19
|
module.exports = lowercaseLocalPermutations;
|
|
41
20
|
//# sourceMappingURL=localeConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeConfig.js","sourceRoot":"","sources":["../../src/intl/localeConfig.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localeConfig.js","sourceRoot":"","sources":["../../src/intl/localeConfig.js"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAEjD,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAEtE,6HAA6H;AAC7H,MAAM,0BAA0B,GAAG,KAAK,CAAC,IAAI,CACzC,IAAI,GAAG,CAAC;IACJ,GAAG,gBAAgB;IACnB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,GAAG,gBAAgB;SACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACjC,MAAM,CAAC,OAAO,CAAC;QAChB,gFAAgF;SAC/E,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;CACpD,CAAC,CACL,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,CAAC,OAAO,GAAG,0BAA0B,CAAC"}
|