@prezly/theme-kit-nextjs 1.3.3 → 1.3.4-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 +15 -11
- package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +4 -0
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +4 -0
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/processRequest.d.ts +9 -0
- package/build/adapter-nextjs/processRequest.js +9 -0
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +9 -2
- package/build/data-fetching/api/PrezlyApi.js +13 -2
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +2 -2
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/languages.d.ts +9 -0
- package/build/data-fetching/api/languages.js +9 -0
- package/build/data-fetching/api/languages.js.map +1 -1
- package/build/data-fetching/getAssetsUrl.d.ts +4 -0
- package/build/data-fetching/getAssetsUrl.js +4 -0
- package/build/data-fetching/getAssetsUrl.js.map +1 -1
- package/build/data-fetching/getUploadcareGroupUrl.d.ts +7 -0
- package/build/data-fetching/getUploadcareGroupUrl.js +7 -0
- package/build/data-fetching/getUploadcareGroupUrl.js.map +1 -1
- package/build/data-fetching/types.d.ts +1 -0
- package/build/intl/lang.d.ts +4 -2
- package/build/intl/lang.js +4 -2
- package/build/intl/lang.js.map +1 -1
- package/build/intl/locale.d.ts +4 -0
- package/build/intl/locale.js +9 -0
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.js +6 -2
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeObject.d.ts +23 -0
- package/build/intl/localeObject.js +23 -0
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.d.ts +38 -1
- package/build/newsroom-context/context.js +4 -0
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +6 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +4 -0
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +10 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/types.d.ts +13 -0
- package/package.json +1 -1
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +4 -0
- package/src/adapter-nextjs/processRequest.ts +9 -0
- package/src/data-fetching/api/PrezlyApi.ts +16 -2
- package/src/data-fetching/api/getPrezlyApi.ts +2 -2
- package/src/data-fetching/api/languages.ts +9 -0
- package/src/data-fetching/getAssetsUrl.ts +4 -0
- package/src/data-fetching/getUploadcareGroupUrl.ts +7 -0
- package/src/data-fetching/types.ts +1 -0
- package/src/intl/lang.ts +4 -2
- package/src/intl/locale.ts +9 -0
- package/src/intl/localeConfig.js +6 -2
- package/src/intl/localeObject.ts +23 -0
- package/src/newsroom-context/context.tsx +38 -1
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +6 -1
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +10 -1
- package/src/types.ts +13 -1
|
@@ -21,6 +21,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.LocaleObject = void 0;
|
|
23
23
|
var localeConfig_1 = __importDefault(require("./localeConfig"));
|
|
24
|
+
/**
|
|
25
|
+
* This class is created to simplify working with locales and transforming between different locale code formats.
|
|
26
|
+
* Prezly API uses underscore-codes, while most frontend application tend to use hyphen-codes or slugs.
|
|
27
|
+
* Note that `fromAnyCode` constructor only accepts locales supported by Prezly backend. See `localeConfig` for reference.
|
|
28
|
+
*/
|
|
24
29
|
var LocaleObject = /** @class */ (function () {
|
|
25
30
|
function LocaleObject(localeCode) {
|
|
26
31
|
if (localeCode.indexOf('_') !== -1) {
|
|
@@ -49,19 +54,34 @@ var LocaleObject = /** @class */ (function () {
|
|
|
49
54
|
}
|
|
50
55
|
return new LocaleObject(foundCode);
|
|
51
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* @returns Code formatted into hyphen format: `nl-BE`, `en-US`, `fr`, `fil`
|
|
59
|
+
*/
|
|
52
60
|
LocaleObject.prototype.toHyphenCode = function () {
|
|
53
61
|
return this.localeCode;
|
|
54
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* @returns Code formatted into underscore format, as expected by Prezly API: `nl_BE`, `en_US`, `fr`, `fil`
|
|
65
|
+
*/
|
|
55
66
|
LocaleObject.prototype.toUnderscoreCode = function () {
|
|
56
67
|
return this.localeCode.replace('-', '_');
|
|
57
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* @returns Code formatted to a URL-friendly lowercase slug format: `nl-be`, `en-us`, `fr`, `fil`
|
|
71
|
+
*/
|
|
58
72
|
LocaleObject.prototype.toUrlSlug = function () {
|
|
59
73
|
return this.localeCode.toLowerCase();
|
|
60
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* @returns Only the language part of the code without culture/region part: `nl`, `en`, `fr`
|
|
77
|
+
*/
|
|
61
78
|
LocaleObject.prototype.toNeutralLanguageCode = function () {
|
|
62
79
|
var _a = __read(this.localeCode.split('-'), 1), language = _a[0];
|
|
63
80
|
return language;
|
|
64
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
84
|
+
*/
|
|
65
85
|
LocaleObject.prototype.toRegionCode = function () {
|
|
66
86
|
var _a = __read(this.localeCode.split('-'), 2), language = _a[0], region = _a[1];
|
|
67
87
|
if (!region) {
|
|
@@ -69,6 +89,9 @@ var LocaleObject = /** @class */ (function () {
|
|
|
69
89
|
}
|
|
70
90
|
return region.toUpperCase();
|
|
71
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Check if two LocaleObject instances are representing the same locale code.
|
|
94
|
+
*/
|
|
72
95
|
LocaleObject.prototype.isEqual = function (anotherLocale) {
|
|
73
96
|
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
74
97
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA0C;AAE1C;IAOI,sBAAoB,UAAkB;QAClC,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAEK,IAAA,KAAA,OAAqB,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAAzC,QAAQ,QAAA,EAAE,MAAM,QAAyB,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChE;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACW,wBAAW,GAAzB,UAA0B,UAAkB;QACxC,IAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,IAAM,SAAS,GAAG,sBAAY,CAAC,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,KAAK,aAAa,EAAtB,CAAsB,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,8CAAsC,aAAa,OAAG,CAAC,CAAC;SAC3E;QAED,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;
|
|
1
|
+
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA0C;AAE1C;;;;GAIG;AACH;IAOI,sBAAoB,UAAkB;QAClC,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAEK,IAAA,KAAA,OAAqB,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAAzC,QAAQ,QAAA,EAAE,MAAM,QAAyB,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChE;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACW,wBAAW,GAAzB,UAA0B,UAAkB;QACxC,IAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,IAAM,SAAS,GAAG,sBAAY,CAAC,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,KAAK,aAAa,EAAtB,CAAsB,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,8CAAsC,aAAa,OAAG,CAAC,CAAC;SAC3E;QAED,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,mCAAY,GAAnB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,uCAAgB,GAAvB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,gCAAS,GAAhB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,4CAAqB,GAA5B;QACU,IAAA,KAAA,OAAa,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAAtC,QAAQ,QAA8B,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,mCAAY,GAAnB;QACU,IAAA,KAAA,OAAqB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAA9C,QAAQ,QAAA,EAAE,MAAM,QAA8B,CAAC;QAEtD,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,8BAAO,GAAd,UAAe,aAA2B;QACtC,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;IAC5D,CAAC;IACL,mBAAC;AAAD,CAAC,AAxFD,IAwFC;AAxFY,oCAAY"}
|
|
@@ -3,19 +3,56 @@ import type { PropsWithChildren } from 'react';
|
|
|
3
3
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
4
|
import { LocaleObject } from '../intl';
|
|
5
5
|
export interface NewsroomContextType {
|
|
6
|
+
/**
|
|
7
|
+
* Basic newsroom information: newsroom logos, settings, etc.
|
|
8
|
+
*/
|
|
6
9
|
newsroom: Newsroom;
|
|
10
|
+
/**
|
|
11
|
+
* Contact information of the newsroom in the default language, usually displayed in the "About" section
|
|
12
|
+
*/
|
|
7
13
|
companyInformation: NewsroomCompanyInformation;
|
|
14
|
+
/**
|
|
15
|
+
* List of all categories enabled on the newsroom
|
|
16
|
+
*/
|
|
8
17
|
categories: Category[];
|
|
18
|
+
/**
|
|
19
|
+
* Optional: Contacts set up to be displayed on the newsroom home page.
|
|
20
|
+
* Will only be loaded if `loadHomepageContacts` option of `getNewsroomServerSideProps` is set to `true`.
|
|
21
|
+
*/
|
|
9
22
|
contacts?: NewsroomContact[];
|
|
23
|
+
/**
|
|
24
|
+
* Optional: Refers to a currently selected category when navigated to `/category/[slug]` page.
|
|
25
|
+
*/
|
|
10
26
|
currentCategory?: Category;
|
|
27
|
+
/**
|
|
28
|
+
* Optional: Refers to a currently selected story when navigated to `/[slug]` page.
|
|
29
|
+
*/
|
|
11
30
|
currentStory?: ExtendedStory;
|
|
31
|
+
/**
|
|
32
|
+
* List of currently enabled newsroom languages, as well as company information translated for each language
|
|
33
|
+
*/
|
|
12
34
|
languages: NewsroomLanguageSettings[];
|
|
35
|
+
/**
|
|
36
|
+
* Currently chosen locale
|
|
37
|
+
*/
|
|
13
38
|
locale: LocaleObject;
|
|
14
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Theme settings as set in the Prezly app.
|
|
41
|
+
* You need to provide `PREZLY_THEME_UUID` in environment variables in order for the preset to be loaded.
|
|
42
|
+
* Only applicable to themes hosted on the Prezly infrastructure.
|
|
43
|
+
*/
|
|
44
|
+
themePreset: NewsroomThemePreset | null;
|
|
45
|
+
/**
|
|
46
|
+
* Environment variables required for Algolia search to work.
|
|
47
|
+
*/
|
|
15
48
|
algoliaSettings: AlgoliaSettings;
|
|
16
49
|
}
|
|
17
50
|
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
18
51
|
localeCode: string;
|
|
19
52
|
}
|
|
20
53
|
export declare const NewsroomContext: import("react").Context<NewsroomContextType | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
56
|
+
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
57
|
+
*/
|
|
21
58
|
export declare function NewsroomContextProvider({ categories, contacts, newsroom, currentCategory, currentStory, companyInformation, languages, localeCode, themePreset, algoliaSettings, children, }: PropsWithChildren<NewsroomContextProps>): JSX.Element;
|
|
@@ -16,6 +16,10 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
16
16
|
var react_1 = require("react");
|
|
17
17
|
var intl_1 = require("../intl");
|
|
18
18
|
exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
19
|
+
/**
|
|
20
|
+
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
21
|
+
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
22
|
+
*/
|
|
19
23
|
function NewsroomContextProvider(_a) {
|
|
20
24
|
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, currentCategory = _a.currentCategory, currentStory = _a.currentStory, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode, themePreset = _a.themePreset, algoliaSettings = _a.algoliaSettings, children = _a.children;
|
|
21
25
|
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAUA,+BAA+C;AAG/C,gCAAuD;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAUA,+BAA+C;AAG/C,gCAAuD;AAoD1C,QAAA,eAAe,GAAG,IAAA,qBAAa,EAAkC,SAAS,CAAC,CAAC;AAEzF;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,EAYE;QAXtC,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,eAAe,qBAAA,EACf,YAAY,kBAAA,EACZ,kBAAkB,wBAAA,EAClB,SAAS,eAAA,EACT,UAAU,gBAAA,EACV,WAAW,iBAAA,EACX,eAAe,qBAAA,EACf,QAAQ,cAAA;IAER,IAAM,MAAM,GAAG,IAAA,eAAO,EAClB,cAAM,OAAA,mBAAY,CAAC,WAAW,CAAC,UAAU,IAAI,qBAAc,CAAC,EAAtD,CAAsD,EAC5D,CAAC,UAAU,CAAC,CACf,CAAC;IAEF,OAAO,CACH,uBAAC,uBAAe,CAAC,QAAQ,aACrB,KAAK,EAAE;YACH,UAAU,YAAA;YACV,QAAQ,UAAA;YACR,QAAQ,UAAA;YACR,eAAe,iBAAA;YACf,YAAY,cAAA;YACZ,kBAAkB,oBAAA;YAClB,SAAS,WAAA;YACT,MAAM,QAAA;YACN,WAAW,aAAA;YACX,eAAe,iBAAA;SAClB,gBAEA,QAAQ,YACc,CAC9B,CAAC;AACN,CAAC;AApCD,0DAoCC"}
|
|
@@ -6,7 +6,12 @@ var data_fetching_1 = require("../../data-fetching");
|
|
|
6
6
|
var intl_1 = require("../../intl");
|
|
7
7
|
var useCurrentLocale_1 = require("./useCurrentLocale");
|
|
8
8
|
var useLanguages_1 = require("./useLanguages");
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Determines correct locale slug for the link (trying to shorten the locale code if possible).
|
|
11
|
+
* E.g. if newsroom has a single locale for Dutch (`nl_BE`), it will be shortened to `nl`.
|
|
12
|
+
* If there are more than one locale with the same language part, a full locale code will be used instead.
|
|
13
|
+
* `false` means that a default locale should be used (no locale in URL required).
|
|
14
|
+
*/
|
|
10
15
|
function getLinkLocaleSlug(languages, locale) {
|
|
11
16
|
var shortestLocaleCode = (0, data_fetching_1.getShortestLocaleCode)(languages, locale);
|
|
12
17
|
// When navigating to default language, we don't append the locale to the URL.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetLinkLocaleSlug.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetLinkLocaleSlug.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAEpC,qDAA4D;AAC5D,mCAA0C;AAE1C,uDAAsD;AACtD,+CAA8C;AAE9C
|
|
1
|
+
{"version":3,"file":"useGetLinkLocaleSlug.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetLinkLocaleSlug.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAEpC,qDAA4D;AAC5D,mCAA0C;AAE1C,uDAAsD;AACtD,+CAA8C;AAE9C;;;;;GAKG;AACH,SAAS,iBAAiB,CACtB,SAAqC,EACrC,MAAoB;IAEpB,IAAM,kBAAkB,GAAG,IAAA,qCAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACpE,8EAA8E;IAC9E,IAAI,CAAC,kBAAkB,EAAE;QACrB,OAAO,kBAAkB,CAAC;KAC7B;IAED,OAAO,mBAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;AACpE,CAAC;AAED,SAAgB,oBAAoB;IAChC,IAAM,aAAa,GAAG,IAAA,mCAAgB,GAAE,CAAC;IACzC,IAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;IAEjC,8DAA8D;IAC9D,OAAO,IAAA,mBAAW,EACd,UAAC,MAAqB,IAAK,OAAA,iBAAiB,CAAC,SAAS,EAAE,MAAM,IAAI,aAAa,CAAC,EAArD,CAAqD,EAChF,CAAC,SAAS,EAAE,aAAa,CAAC,CAC7B,CAAC;AACN,CAAC;AATD,oDASC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { LocaleObject } from '../../intl';
|
|
2
|
+
/**
|
|
3
|
+
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
4
|
+
* `noFallback` parameter is useful for alternate language links in the `head` section of the document (so that there are no unwanted links to the homepage).
|
|
5
|
+
*/
|
|
2
6
|
export declare function useGetTranslationUrl(): (locale: LocaleObject, noFallback?: boolean | undefined) => string;
|
|
@@ -6,7 +6,12 @@ var react_1 = require("react");
|
|
|
6
6
|
var data_fetching_1 = require("../../data-fetching");
|
|
7
7
|
var useCurrentCategory_1 = require("./useCurrentCategory");
|
|
8
8
|
var useCurrentStory_1 = require("./useCurrentStory");
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Determine correct URL for translated stories/categories with a fallback to homepage.
|
|
11
|
+
* E.g. if a story has a translation, the function will return the localized slug URL.
|
|
12
|
+
* If there is no translation for the story, it will return the index page URL (`/`),
|
|
13
|
+
* or empty string, if `noFallback` is set to `true` (this is useful for alternate locale links).
|
|
14
|
+
*/
|
|
10
15
|
function getTranslationUrl(locale, path, currentCategory, currentStory, noFallback) {
|
|
11
16
|
if (currentCategory) {
|
|
12
17
|
if ((0, data_fetching_1.getCategoryHasTranslation)(currentCategory, locale)) {
|
|
@@ -33,6 +38,10 @@ function getTranslationUrl(locale, path, currentCategory, currentStory, noFallba
|
|
|
33
38
|
}
|
|
34
39
|
return path;
|
|
35
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
43
|
+
* `noFallback` parameter is useful for alternate language links in the `head` section of the document (so that there are no unwanted links to the homepage).
|
|
44
|
+
*/
|
|
36
45
|
function useGetTranslationUrl() {
|
|
37
46
|
var asPath = (0, router_1.useRouter)().asPath;
|
|
38
47
|
var currentCategory = (0, useCurrentCategory_1.useCurrentCategory)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AACxC,+BAAoC;AAEpC,qDAAgF;AAGhF,2DAA0D;AAC1D,qDAAoD;AAEpD
|
|
1
|
+
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AACxC,+BAAoC;AAEpC,qDAAgF;AAGhF,2DAA0D;AAC1D,qDAAoD;AAEpD;;;;;GAKG;AACH,SAAS,iBAAiB,CACtB,MAAoB,EACpB,IAAY,EACZ,eAA0B,EAC1B,YAA4B,EAC5B,UAAoB;IAEpB,IAAI,eAAe,EAAE;QACjB,IAAI,IAAA,yCAAyB,EAAC,eAAe,EAAE,MAAM,CAAC,EAAE;YACpD,OAAO,IAAA,8BAAc,EAAC,eAAe,EAAE,MAAM,CAAC,CAAC;SAClD;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,IAAM,UAAU,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAE7C,IAAI,YAAY,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE;QAC5D,IAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,IAAI,CAClD,UAAC,EAAW;gBAAT,OAAO,aAAA;YAAO,OAAA,OAAO,CAAC,MAAM,KAAK,UAAU;QAA7B,CAA6B,CACjD,CAAC;QACF,IAAI,eAAe,EAAE;YACjB,OAAO,WAAI,eAAe,CAAC,IAAI,CAAE,CAAC;SACrC;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB;IACxB,IAAA,MAAM,GAAK,IAAA,kBAAS,GAAE,OAAhB,CAAiB;IAC/B,IAAM,eAAe,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAC7C,IAAM,YAAY,GAAG,IAAA,iCAAe,GAAE,CAAC;IAEvC,OAAO,IAAA,mBAAW,EACd,UAAC,MAAoB,EAAE,UAAoB;QACvC,OAAA,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,CAAC;IAA5E,CAA4E,EAChF,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,CAAC,CAC1C,CAAC;AACN,CAAC;AAVD,oDAUC"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
2
2
|
import type { NewsroomContextProps } from './newsroom-context';
|
|
3
3
|
export interface ServerSidePageProps {
|
|
4
|
+
/**
|
|
5
|
+
* Indicates whether the locale requested by the Next application was correctly resolved to an active newsroom locale.
|
|
6
|
+
* This is used by `processRequest` method to redirect to the default locale if the property is `false`.
|
|
7
|
+
*/
|
|
4
8
|
localeResolved: boolean;
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* These are the props returned by the `processRequest` method that are meant to be passed to your `_app` to be injected into the `NewsroomContextProvider`.
|
|
12
|
+
*/
|
|
6
13
|
export interface PageProps {
|
|
7
14
|
newsroomContextProps: NewsroomContextProps;
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Categories in Algolia index are stored in a simplified format, with `slug` and `name` properties already saved in the correct locale for the story search result.
|
|
18
|
+
*/
|
|
9
19
|
export interface AlgoliaCategoryRef {
|
|
10
20
|
id: number;
|
|
11
21
|
name: string;
|
|
12
22
|
slug: string;
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Stories in Algolia index are stored in a simplified format, with only minimal subset of fields.
|
|
26
|
+
*/
|
|
14
27
|
export declare type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> & Pick<ExtraStoryFields, 'thumbnail_image'> & {
|
|
15
28
|
content_text: string;
|
|
16
29
|
updated_at: number;
|
package/package.json
CHANGED
|
@@ -8,6 +8,10 @@ interface Options {
|
|
|
8
8
|
story?: Story;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Use this function in your `getServerSideProps` page methods to retrieve the data necessary for the NewsroomContextProvider and `processRequest` function.
|
|
13
|
+
* See README for usage examples.
|
|
14
|
+
*/
|
|
11
15
|
export async function getNewsroomServerSideProps(
|
|
12
16
|
context: GetServerSidePropsContext,
|
|
13
17
|
options: Options = {},
|
|
@@ -4,6 +4,15 @@ import { getShortestLocaleCode } from '../data-fetching';
|
|
|
4
4
|
import { getRedirectToCanonicalLocale, LocaleObject } from '../intl';
|
|
5
5
|
import type { PageProps, ServerSidePageProps } from '../types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* This function combines the props returned from `getNewsroomServerSideProps` and your optional custom props for the page.
|
|
9
|
+
* It also handles locale redirects, if `canonicalUrl` parameter is provided.
|
|
10
|
+
* See README for usage examples.
|
|
11
|
+
*
|
|
12
|
+
* @param context Next.js context passed to the `getServerSideProps` method of the page
|
|
13
|
+
* @param props Object containing the return of `getNewsroomServerSideProps` and your optional custom props.
|
|
14
|
+
* @param canonicalUrl Optional: a canonical URL for the current page without locale part. If provided, locale redirects will be handled by the function.
|
|
15
|
+
*/
|
|
7
16
|
export function processRequest<Props>(
|
|
8
17
|
context: GetServerSidePropsContext,
|
|
9
18
|
props: Props & PageProps & ServerSidePageProps,
|
|
@@ -49,14 +49,18 @@ export class PrezlyApi {
|
|
|
49
49
|
|
|
50
50
|
private readonly newsroomUuid: Newsroom['uuid'];
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
private readonly themeUuid: string | undefined;
|
|
53
|
+
|
|
54
|
+
constructor(accessToken: string, newsroomUuid: Newsroom['uuid'], themeUuid?: string) {
|
|
53
55
|
const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
|
|
54
56
|
this.sdk = new PrezlySDK({
|
|
55
57
|
accessToken,
|
|
56
58
|
baseUrl,
|
|
59
|
+
// This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
|
|
57
60
|
headers: { 'X-Convert-v1-To-v3': 'true' },
|
|
58
61
|
});
|
|
59
62
|
this.newsroomUuid = newsroomUuid;
|
|
63
|
+
this.themeUuid = themeUuid;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
getStory(uuid: string) {
|
|
@@ -77,6 +81,9 @@ export class PrezlyApi {
|
|
|
77
81
|
return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
|
|
86
|
+
*/
|
|
80
87
|
async getAllStories(order: SortOrder = DEFAULT_SORT_ORDER) {
|
|
81
88
|
const sortOrder = getSortByPublishedDate(order);
|
|
82
89
|
const newsroom = await this.getNewsroom();
|
|
@@ -195,8 +202,15 @@ export class PrezlyApi {
|
|
|
195
202
|
return this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
|
|
196
203
|
}
|
|
197
204
|
|
|
205
|
+
/**
|
|
206
|
+
* In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
|
|
207
|
+
*/
|
|
198
208
|
async getThemePreset() {
|
|
199
|
-
|
|
209
|
+
if (this.themeUuid) {
|
|
210
|
+
return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return null;
|
|
200
214
|
}
|
|
201
215
|
|
|
202
216
|
async getNewsroomServerSideProps(
|
|
@@ -10,7 +10,7 @@ export function getPrezlyApi(req?: IncomingMessage): PrezlyApi {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// `getEnvVariables` handles both cases for envs parsing - .env and request headers
|
|
13
|
-
const { PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID } = getEnvVariables(req);
|
|
13
|
+
const { PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID } = getEnvVariables(req);
|
|
14
14
|
|
|
15
15
|
if (!PREZLY_ACCESS_TOKEN) {
|
|
16
16
|
throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
|
|
@@ -20,5 +20,5 @@ export function getPrezlyApi(req?: IncomingMessage): PrezlyApi {
|
|
|
20
20
|
throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID);
|
|
23
|
+
return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
|
|
24
24
|
}
|
|
@@ -2,10 +2,16 @@ import type { NewsroomLanguageSettings, Story } from '@prezly/sdk';
|
|
|
2
2
|
|
|
3
3
|
import { DUMMY_DEFAULT_LOCALE, LocaleObject } from '../../intl';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @returns Language set as default in the Newsroom Settings.
|
|
7
|
+
*/
|
|
5
8
|
export function getDefaultLanguage(languages: NewsroomLanguageSettings[]) {
|
|
6
9
|
return languages.find(({ is_default }) => is_default) || languages[0];
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @returns Only languages having at least one published story
|
|
14
|
+
*/
|
|
9
15
|
export function getUsedLanguages(languages: NewsroomLanguageSettings[]) {
|
|
10
16
|
return languages.filter((language) => language.public_stories_count > 0);
|
|
11
17
|
}
|
|
@@ -110,6 +116,9 @@ export function getLanguageFromStory(languages: NewsroomLanguageSettings[], stor
|
|
|
110
116
|
return languages.find(({ code }) => code === storyLocaleCode);
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Extracts company information for the selected locale
|
|
121
|
+
*/
|
|
113
122
|
export function getCompanyInformation(languages: NewsroomLanguageSettings[], locale: LocaleObject) {
|
|
114
123
|
const currentLanguage =
|
|
115
124
|
getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ASSETS_URL } from './constants';
|
|
2
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
|
+
*/
|
|
3
7
|
export function getAssetsUrl(uuid: string) {
|
|
4
8
|
return `${ASSETS_URL}/${uuid}/`;
|
|
5
9
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ASSETS_URL } from './constants';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* This method constructs a URL to download all images in the Gallery as a single archive.
|
|
5
|
+
*
|
|
6
|
+
* @param uuid Gallery UUID
|
|
7
|
+
* @param title Filename for the saved archive. Usually it is the Gallery title.
|
|
8
|
+
* @returns URL to an archive containing all of the images in the Gallery.
|
|
9
|
+
*/
|
|
3
10
|
export function getUploadcareGroupUrl(uuid: string, title: string) {
|
|
4
11
|
return `${ASSETS_URL}/${uuid}/archive/zip/${encodeURI(title)}.zip`;
|
|
5
12
|
}
|
package/src/intl/lang.ts
CHANGED
|
@@ -9,14 +9,16 @@ function isOnlyCulture(culture: CultureRef, languages: NewsroomLanguageSettings[
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
+
* @returns the display name of the locale in its native language
|
|
13
|
+
*
|
|
12
14
|
* If there's only one culture used in a specific language,
|
|
13
15
|
* we strip the culture name completely.
|
|
14
16
|
*
|
|
15
17
|
* Examples:
|
|
16
18
|
* - English (Global), Spanish (Spain)
|
|
17
|
-
*
|
|
19
|
+
* - -> English, Spanish
|
|
18
20
|
* - English (Global), English (UK), Spanish (Spain)
|
|
19
|
-
*
|
|
21
|
+
* - -> English (Global), English (UK), Spanish
|
|
20
22
|
*/
|
|
21
23
|
export function getLanguageDisplayName(
|
|
22
24
|
language: NewsroomLanguageSettings,
|
package/src/intl/locale.ts
CHANGED
|
@@ -5,8 +5,13 @@ import { stringify } from 'querystring';
|
|
|
5
5
|
import { LocaleObject } from './localeObject';
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_LOCALE = 'en';
|
|
8
|
+
// We use pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
|
|
8
9
|
export const DUMMY_DEFAULT_LOCALE = 'qps-ploc';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* This a list of locales that Prezly has translations for. Each code represents a language file in the `@prezly/themes-intl-messages` package.
|
|
13
|
+
* See https://github.com/prezly/themes-intl-messages for more info.
|
|
14
|
+
*/
|
|
10
15
|
const SUPPORTED_LOCALES = [
|
|
11
16
|
'af',
|
|
12
17
|
'ar',
|
|
@@ -56,6 +61,10 @@ const SUPPORTED_LOCALES = [
|
|
|
56
61
|
'zh-TW',
|
|
57
62
|
];
|
|
58
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Use this function to determine which translations file you should load from `@prezly/themes-intl-mesages` package.
|
|
66
|
+
* See https://github.com/prezly/theme-nextjs-bea/blob/main/utils/lang.ts for a usage example.
|
|
67
|
+
*/
|
|
59
68
|
export function getSupportedLocaleIsoCode(locale: LocaleObject): string {
|
|
60
69
|
const localeIsoCode = locale.toHyphenCode();
|
|
61
70
|
|
package/src/intl/localeConfig.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This list is pulled from the main Prezly application. The underscores are replaced with dashes.
|
|
3
|
+
* Together with permutation performed lower in the code,
|
|
4
|
+
* the exported list represents all of the possible locale codes that Next.js theme application might accept.
|
|
5
|
+
*/
|
|
2
6
|
const supportedLocales = [
|
|
3
7
|
'af-ZA',
|
|
4
8
|
'ar',
|
|
@@ -105,7 +109,7 @@ const supportedLocales = [
|
|
|
105
109
|
|
|
106
110
|
const lowercaseLocales = supportedLocales.map((l) => l.toLowerCase());
|
|
107
111
|
|
|
108
|
-
// Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes)
|
|
112
|
+
// Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes and neutral language codes)
|
|
109
113
|
const lowercaseLocalPermutations = Array.from(
|
|
110
114
|
new Set([
|
|
111
115
|
...lowercaseLocales,
|
package/src/intl/localeObject.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import localeConfig from './localeConfig';
|
|
2
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
|
+
*/
|
|
3
8
|
export class LocaleObject {
|
|
4
9
|
/**
|
|
5
10
|
* Hyphen-separated locale code.
|
|
@@ -39,24 +44,39 @@ export class LocaleObject {
|
|
|
39
44
|
return new LocaleObject(foundCode);
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @returns Code formatted into hyphen format: `nl-BE`, `en-US`, `fr`, `fil`
|
|
49
|
+
*/
|
|
42
50
|
public toHyphenCode(): string {
|
|
43
51
|
return this.localeCode;
|
|
44
52
|
}
|
|
45
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @returns Code formatted into underscore format, as expected by Prezly API: `nl_BE`, `en_US`, `fr`, `fil`
|
|
56
|
+
*/
|
|
46
57
|
public toUnderscoreCode(): string {
|
|
47
58
|
return this.localeCode.replace('-', '_');
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @returns Code formatted to a URL-friendly lowercase slug format: `nl-be`, `en-us`, `fr`, `fil`
|
|
63
|
+
*/
|
|
50
64
|
public toUrlSlug(): string {
|
|
51
65
|
return this.localeCode.toLowerCase();
|
|
52
66
|
}
|
|
53
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @returns Only the language part of the code without culture/region part: `nl`, `en`, `fr`
|
|
70
|
+
*/
|
|
54
71
|
public toNeutralLanguageCode(): string {
|
|
55
72
|
const [language] = this.localeCode.split('-');
|
|
56
73
|
|
|
57
74
|
return language;
|
|
58
75
|
}
|
|
59
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @returns Only the culture/regtion part without the language part: `be`, `us`, `fr`
|
|
79
|
+
*/
|
|
60
80
|
public toRegionCode(): string {
|
|
61
81
|
const [language, region] = this.localeCode.split('-');
|
|
62
82
|
|
|
@@ -67,6 +87,9 @@ export class LocaleObject {
|
|
|
67
87
|
return region.toUpperCase();
|
|
68
88
|
}
|
|
69
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Check if two LocaleObject instances are representing the same locale code.
|
|
92
|
+
*/
|
|
70
93
|
public isEqual(anotherLocale: LocaleObject) {
|
|
71
94
|
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
72
95
|
}
|
|
@@ -14,15 +14,48 @@ import type { AlgoliaSettings } from '../data-fetching';
|
|
|
14
14
|
import { DEFAULT_LOCALE, LocaleObject } from '../intl';
|
|
15
15
|
|
|
16
16
|
export interface NewsroomContextType {
|
|
17
|
+
/**
|
|
18
|
+
* Basic newsroom information: newsroom logos, settings, etc.
|
|
19
|
+
*/
|
|
17
20
|
newsroom: Newsroom;
|
|
21
|
+
/**
|
|
22
|
+
* Contact information of the newsroom in the default language, usually displayed in the "About" section
|
|
23
|
+
*/
|
|
18
24
|
companyInformation: NewsroomCompanyInformation;
|
|
25
|
+
/**
|
|
26
|
+
* List of all categories enabled on the newsroom
|
|
27
|
+
*/
|
|
19
28
|
categories: Category[];
|
|
29
|
+
/**
|
|
30
|
+
* Optional: Contacts set up to be displayed on the newsroom home page.
|
|
31
|
+
* Will only be loaded if `loadHomepageContacts` option of `getNewsroomServerSideProps` is set to `true`.
|
|
32
|
+
*/
|
|
20
33
|
contacts?: NewsroomContact[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional: Refers to a currently selected category when navigated to `/category/[slug]` page.
|
|
36
|
+
*/
|
|
21
37
|
currentCategory?: Category;
|
|
38
|
+
/**
|
|
39
|
+
* Optional: Refers to a currently selected story when navigated to `/[slug]` page.
|
|
40
|
+
*/
|
|
22
41
|
currentStory?: ExtendedStory;
|
|
42
|
+
/**
|
|
43
|
+
* List of currently enabled newsroom languages, as well as company information translated for each language
|
|
44
|
+
*/
|
|
23
45
|
languages: NewsroomLanguageSettings[];
|
|
46
|
+
/**
|
|
47
|
+
* Currently chosen locale
|
|
48
|
+
*/
|
|
24
49
|
locale: LocaleObject;
|
|
25
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Theme settings as set in the Prezly app.
|
|
52
|
+
* You need to provide `PREZLY_THEME_UUID` in environment variables in order for the preset to be loaded.
|
|
53
|
+
* Only applicable to themes hosted on the Prezly infrastructure.
|
|
54
|
+
*/
|
|
55
|
+
themePreset: NewsroomThemePreset | null;
|
|
56
|
+
/**
|
|
57
|
+
* Environment variables required for Algolia search to work.
|
|
58
|
+
*/
|
|
26
59
|
algoliaSettings: AlgoliaSettings;
|
|
27
60
|
}
|
|
28
61
|
|
|
@@ -32,6 +65,10 @@ export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'
|
|
|
32
65
|
|
|
33
66
|
export const NewsroomContext = createContext<NewsroomContextType | undefined>(undefined);
|
|
34
67
|
|
|
68
|
+
/**
|
|
69
|
+
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
70
|
+
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
71
|
+
*/
|
|
35
72
|
export function NewsroomContextProvider({
|
|
36
73
|
categories,
|
|
37
74
|
contacts,
|
|
@@ -7,7 +7,12 @@ import { LocaleObject } from '../../intl';
|
|
|
7
7
|
import { useCurrentLocale } from './useCurrentLocale';
|
|
8
8
|
import { useLanguages } from './useLanguages';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Determines correct locale slug for the link (trying to shorten the locale code if possible).
|
|
12
|
+
* E.g. if newsroom has a single locale for Dutch (`nl_BE`), it will be shortened to `nl`.
|
|
13
|
+
* If there are more than one locale with the same language part, a full locale code will be used instead.
|
|
14
|
+
* `false` means that a default locale should be used (no locale in URL required).
|
|
15
|
+
*/
|
|
11
16
|
function getLinkLocaleSlug(
|
|
12
17
|
languages: NewsroomLanguageSettings[],
|
|
13
18
|
locale: LocaleObject,
|
|
@@ -8,7 +8,12 @@ import type { LocaleObject } from '../../intl';
|
|
|
8
8
|
import { useCurrentCategory } from './useCurrentCategory';
|
|
9
9
|
import { useCurrentStory } from './useCurrentStory';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Determine correct URL for translated stories/categories with a fallback to homepage.
|
|
13
|
+
* E.g. if a story has a translation, the function will return the localized slug URL.
|
|
14
|
+
* If there is no translation for the story, it will return the index page URL (`/`),
|
|
15
|
+
* or empty string, if `noFallback` is set to `true` (this is useful for alternate locale links).
|
|
16
|
+
*/
|
|
12
17
|
function getTranslationUrl(
|
|
13
18
|
locale: LocaleObject,
|
|
14
19
|
path: string,
|
|
@@ -48,6 +53,10 @@ function getTranslationUrl(
|
|
|
48
53
|
return path;
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
/**
|
|
57
|
+
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
58
|
+
* `noFallback` parameter is useful for alternate language links in the `head` section of the document (so that there are no unwanted links to the homepage).
|
|
59
|
+
*/
|
|
51
60
|
export function useGetTranslationUrl() {
|
|
52
61
|
const { asPath } = useRouter();
|
|
53
62
|
const currentCategory = useCurrentCategory();
|