@prezly/theme-kit-nextjs 1.1.5-0 → 1.1.5-1
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 +2 -2
- package/build/adapter-nextjs/processRequest.js +3 -11
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/newsroom-context/context.d.ts +2 -2
- package/build/newsroom-context/context.js +3 -3
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/index.d.ts +2 -2
- package/build/newsroom-context/hooks/index.js +2 -2
- package/build/newsroom-context/hooks/index.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.d.ts +1 -0
- package/build/newsroom-context/hooks/useCurrentCategory.js +10 -0
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -0
- package/build/newsroom-context/hooks/useCurrentStory.d.ts +1 -0
- package/build/newsroom-context/hooks/{useSelectedStory.js → useCurrentStory.js} +5 -5
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -0
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +12 -12
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter-nextjs/processRequest.ts +3 -16
- package/src/newsroom-context/context.tsx +6 -6
- package/src/newsroom-context/hooks/index.ts +2 -2
- package/src/newsroom-context/hooks/{useSelectedCategory.ts → useCurrentCategory.ts} +2 -2
- package/src/newsroom-context/hooks/{useSelectedStory.ts → useCurrentStory.ts} +2 -2
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +13 -13
- package/build/newsroom-context/hooks/useSelectedCategory.d.ts +0 -1
- package/build/newsroom-context/hooks/useSelectedCategory.js +0 -10
- package/build/newsroom-context/hooks/useSelectedCategory.js.map +0 -1
- package/build/newsroom-context/hooks/useSelectedStory.d.ts +0 -1
- package/build/newsroom-context/hooks/useSelectedStory.js.map +0 -1
package/README.md
CHANGED
|
@@ -98,13 +98,13 @@ type AnyPageProps = Record<string, any>;
|
|
|
98
98
|
function App({ Component, pageProps }: AppProps<AnyPageProps>) {
|
|
99
99
|
const { newsroomContextProps, ...customPageProps } = pageProps as PageProps & AnyPageProps;
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
102
102
|
return (
|
|
103
103
|
<NewsroomContextProvider {...newsroomContextProps}>
|
|
104
104
|
<Component {...customPageProps} />
|
|
105
105
|
</NewsroomContextProvider>
|
|
106
106
|
);
|
|
107
|
-
|
|
107
|
+
/* eslint-enable react/jsx-props-no-spreading */
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
export default App;
|
|
@@ -14,22 +14,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.processRequest = void 0;
|
|
15
15
|
var data_fetching_1 = require("../data-fetching");
|
|
16
16
|
var intl_1 = require("../intl");
|
|
17
|
-
// TODO: Try to make the typings even more robust
|
|
18
|
-
function extractServerSideProps(props) {
|
|
19
|
-
var localeResolved = props.localeResolved, pageProps = __rest(props, ["localeResolved"]);
|
|
20
|
-
return {
|
|
21
|
-
pageProps: pageProps,
|
|
22
|
-
serverSideProps: { localeResolved: localeResolved },
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
17
|
function processRequest(context, props, canonicalUrl) {
|
|
26
18
|
var nextLocale = context.locale, query = context.query;
|
|
27
|
-
var
|
|
28
|
-
if (!
|
|
19
|
+
var localeResolved = props.localeResolved, pageProps = __rest(props, ["localeResolved"]);
|
|
20
|
+
if (!localeResolved) {
|
|
29
21
|
return { notFound: true };
|
|
30
22
|
}
|
|
31
23
|
if (canonicalUrl) {
|
|
32
|
-
var
|
|
24
|
+
var _a = pageProps.newsroomContextProps, languages = _a.languages, localeCode = _a.localeCode;
|
|
33
25
|
var currentLocale = intl_1.LocaleObject.fromAnyCode(localeCode);
|
|
34
26
|
var shortestLocaleCode = (0, data_fetching_1.getShortestLocaleCode)(languages, currentLocale);
|
|
35
27
|
var redirect = (0, intl_1.getRedirectToCanonicalLocale)(shortestLocaleCode, nextLocale, canonicalUrl, query);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,kDAAyD;AACzD,gCAAqE;AAGrE,
|
|
1
|
+
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,kDAAyD;AACzD,gCAAqE;AAGrE,SAAgB,cAAc,CAC1B,OAAkC,EAClC,KAA8C,EAC9C,YAAqB;IAEb,IAAQ,UAAU,GAAY,OAAO,OAAnB,EAAE,KAAK,GAAK,OAAO,MAAZ,CAAa;IAEtC,IAAA,cAAc,GAAmB,KAAK,eAAxB,EAAK,SAAS,UAAK,KAAK,EAAxC,kBAAgC,CAAF,CAAW;IAE/C,IAAI,CAAC,cAAc,EAAE;QACjB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;KAC7B;IAED,IAAI,YAAY,EAAE;QACR,IAAA,KAA4B,SAAS,CAAC,oBAAoB,EAAxD,SAAS,eAAA,EAAE,UAAU,gBAAmC,CAAC;QACjE,IAAM,aAAa,GAAG,mBAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAM,kBAAkB,GAAG,IAAA,qCAAqB,EAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAE3E,IAAM,QAAQ,GAAG,IAAA,mCAA4B,EACzC,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAC;QACF,IAAI,QAAQ,EAAE;YACV,OAAO,EAAE,QAAQ,UAAA,EAAE,CAAC;SACvB;KACJ;IAED,OAAO;QACH,KAAK,EAAE,SAA8B;KACxC,CAAC;AACN,CAAC;AAhCD,wCAgCC"}
|
|
@@ -7,8 +7,8 @@ export interface NewsroomContextType {
|
|
|
7
7
|
companyInformation: NewsroomCompanyInformation;
|
|
8
8
|
categories: Category[];
|
|
9
9
|
contacts?: NewsroomContact[];
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
currentCategory?: Category;
|
|
11
|
+
currentStory?: ExtendedStory;
|
|
12
12
|
languages: NewsroomLanguageSettings[];
|
|
13
13
|
locale: LocaleObject;
|
|
14
14
|
themePreset: NewsroomThemePreset;
|
|
@@ -17,14 +17,14 @@ var react_1 = require("react");
|
|
|
17
17
|
var intl_1 = require("../intl");
|
|
18
18
|
exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
19
19
|
var NewsroomContextProvider = function (_a) {
|
|
20
|
-
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom,
|
|
20
|
+
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
21
|
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
22
22
|
return ((0, jsx_runtime_1.jsx)(exports.NewsroomContext.Provider, __assign({ value: {
|
|
23
23
|
categories: categories,
|
|
24
24
|
contacts: contacts,
|
|
25
25
|
newsroom: newsroom,
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
currentCategory: currentCategory,
|
|
27
|
+
currentStory: currentStory,
|
|
28
28
|
companyInformation: companyInformation,
|
|
29
29
|
languages: languages,
|
|
30
30
|
locale: locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,+BAAkE;AAGlE,gCAAuD;AAmB1C,QAAA,eAAe,GAAG,IAAA,qBAAa,EAAkC,SAAS,CAAC,CAAC;AAElF,IAAM,uBAAuB,GAA4C,UAAC,EAYhF;QAXG,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,+BAAkE;AAGlE,gCAAuD;AAmB1C,QAAA,eAAe,GAAG,IAAA,qBAAa,EAAkC,SAAS,CAAC,CAAC;AAElF,IAAM,uBAAuB,GAA4C,UAAC,EAYhF;QAXG,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,CAAC;AApCW,QAAA,uBAAuB,2BAoClC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from './useAlgoliaSettings';
|
|
2
2
|
export * from './useCategories';
|
|
3
3
|
export * from './useCompanyInformation';
|
|
4
|
+
export * from './useCurrentCategory';
|
|
4
5
|
export * from './useCurrentLocale';
|
|
6
|
+
export * from './useCurrentStory';
|
|
5
7
|
export * from './useGetLinkLocaleSlug';
|
|
6
8
|
export * from './useGetTranslationUrl';
|
|
7
9
|
export * from './useLanguages';
|
|
8
10
|
export * from './useNewsroom';
|
|
9
11
|
export * from './useNewsroomContext';
|
|
10
|
-
export * from './useSelectedCategory';
|
|
11
|
-
export * from './useSelectedStory';
|
|
@@ -13,12 +13,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
__exportStar(require("./useAlgoliaSettings"), exports);
|
|
14
14
|
__exportStar(require("./useCategories"), exports);
|
|
15
15
|
__exportStar(require("./useCompanyInformation"), exports);
|
|
16
|
+
__exportStar(require("./useCurrentCategory"), exports);
|
|
16
17
|
__exportStar(require("./useCurrentLocale"), exports);
|
|
18
|
+
__exportStar(require("./useCurrentStory"), exports);
|
|
17
19
|
__exportStar(require("./useGetLinkLocaleSlug"), exports);
|
|
18
20
|
__exportStar(require("./useGetTranslationUrl"), exports);
|
|
19
21
|
__exportStar(require("./useLanguages"), exports);
|
|
20
22
|
__exportStar(require("./useNewsroom"), exports);
|
|
21
23
|
__exportStar(require("./useNewsroomContext"), exports);
|
|
22
|
-
__exportStar(require("./useSelectedCategory"), exports);
|
|
23
|
-
__exportStar(require("./useSelectedStory"), exports);
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,kDAAgC;AAChC,0DAAwC;AACxC,qDAAmC;AACnC,yDAAuC;AACvC,yDAAuC;AACvC,iDAA+B;AAC/B,gDAA8B;AAC9B,uDAAqC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,yDAAuC;AACvC,yDAAuC;AACvC,iDAA+B;AAC/B,gDAA8B;AAC9B,uDAAqC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCurrentCategory: () => import("@prezly/sdk").Category | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCurrentCategory = void 0;
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useCurrentCategory = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
|
+
return context.currentCategory;
|
|
8
|
+
};
|
|
9
|
+
exports.useCurrentCategory = useCurrentCategory;
|
|
10
|
+
//# sourceMappingURL=useCurrentCategory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentCategory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCurrentCategory.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,kBAAkB,GAAG;IAC9B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,eAAe,CAAC;AACnC,CAAC,CAAC;AAJW,QAAA,kBAAkB,sBAI7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCurrentStory: () => import("@prezly/sdk").ExtendedStory | undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useCurrentStory = void 0;
|
|
4
4
|
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
-
var
|
|
5
|
+
var useCurrentStory = function () {
|
|
6
6
|
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
|
-
return context.
|
|
7
|
+
return context.currentStory;
|
|
8
8
|
};
|
|
9
|
-
exports.
|
|
10
|
-
//# sourceMappingURL=
|
|
9
|
+
exports.useCurrentStory = useCurrentStory;
|
|
10
|
+
//# sourceMappingURL=useCurrentStory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentStory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCurrentStory.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,eAAe,GAAG;IAC3B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,YAAY,CAAC;AAChC,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B"}
|
|
@@ -4,13 +4,13 @@ exports.useGetTranslationUrl = void 0;
|
|
|
4
4
|
var router_1 = require("next/router");
|
|
5
5
|
var react_1 = require("react");
|
|
6
6
|
var data_fetching_1 = require("../../data-fetching");
|
|
7
|
-
var
|
|
8
|
-
var
|
|
7
|
+
var useCurrentCategory_1 = require("./useCurrentCategory");
|
|
8
|
+
var useCurrentStory_1 = require("./useCurrentStory");
|
|
9
9
|
// Determine correct URL for translated stories/categories with a fallback to homepage
|
|
10
|
-
function getTranslationUrl(locale, path,
|
|
11
|
-
if (
|
|
12
|
-
if ((0, data_fetching_1.getCategoryHasTranslation)(
|
|
13
|
-
return (0, data_fetching_1.getCategoryUrl)(
|
|
10
|
+
function getTranslationUrl(locale, path, currentCategory, currentStory, noFallback) {
|
|
11
|
+
if (currentCategory) {
|
|
12
|
+
if ((0, data_fetching_1.getCategoryHasTranslation)(currentCategory, locale)) {
|
|
13
|
+
return (0, data_fetching_1.getCategoryUrl)(currentCategory, locale);
|
|
14
14
|
}
|
|
15
15
|
if (noFallback) {
|
|
16
16
|
return '';
|
|
@@ -18,8 +18,8 @@ function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFall
|
|
|
18
18
|
return '/';
|
|
19
19
|
}
|
|
20
20
|
var localeCode = locale.toUnderscoreCode();
|
|
21
|
-
if (
|
|
22
|
-
var translatedStory =
|
|
21
|
+
if (currentStory && currentStory.culture.locale !== localeCode) {
|
|
22
|
+
var translatedStory = currentStory.translations.find(function (_a) {
|
|
23
23
|
var culture = _a.culture;
|
|
24
24
|
return culture.locale === localeCode;
|
|
25
25
|
});
|
|
@@ -35,11 +35,11 @@ function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFall
|
|
|
35
35
|
}
|
|
36
36
|
function useGetTranslationUrl() {
|
|
37
37
|
var asPath = (0, router_1.useRouter)().asPath;
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var currentCategory = (0, useCurrentCategory_1.useCurrentCategory)();
|
|
39
|
+
var currentStory = (0, useCurrentStory_1.useCurrentStory)();
|
|
40
40
|
return (0, react_1.useCallback)(function (locale, noFallback) {
|
|
41
|
-
return getTranslationUrl(locale, asPath,
|
|
42
|
-
}, [asPath,
|
|
41
|
+
return getTranslationUrl(locale, asPath, currentCategory, currentStory, noFallback);
|
|
42
|
+
}, [asPath, currentCategory, currentStory]);
|
|
43
43
|
}
|
|
44
44
|
exports.useGetTranslationUrl = useGetTranslationUrl;
|
|
45
45
|
//# sourceMappingURL=useGetTranslationUrl.js.map
|
|
@@ -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,
|
|
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,sFAAsF;AACtF,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,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/package.json
CHANGED
|
@@ -4,19 +4,6 @@ import { getShortestLocaleCode } from '../data-fetching';
|
|
|
4
4
|
import { getRedirectToCanonicalLocale, LocaleObject } from '../intl';
|
|
5
5
|
import { PageProps, ServerSidePageProps } from '../types';
|
|
6
6
|
|
|
7
|
-
// TODO: Try to make the typings even more robust
|
|
8
|
-
function extractServerSideProps<Props>(props: Props & ServerSidePageProps): {
|
|
9
|
-
pageProps: Props;
|
|
10
|
-
serverSideProps: ServerSidePageProps;
|
|
11
|
-
} {
|
|
12
|
-
const { localeResolved, ...pageProps } = props;
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
pageProps: pageProps as unknown as Props,
|
|
16
|
-
serverSideProps: { localeResolved },
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
7
|
export function processRequest<Props>(
|
|
21
8
|
context: GetServerSidePropsContext,
|
|
22
9
|
props: Props & PageProps & ServerSidePageProps,
|
|
@@ -24,9 +11,9 @@ export function processRequest<Props>(
|
|
|
24
11
|
): GetServerSidePropsResult<Props> {
|
|
25
12
|
const { locale: nextLocale, query } = context;
|
|
26
13
|
|
|
27
|
-
const {
|
|
14
|
+
const { localeResolved, ...pageProps } = props;
|
|
28
15
|
|
|
29
|
-
if (!
|
|
16
|
+
if (!localeResolved) {
|
|
30
17
|
return { notFound: true };
|
|
31
18
|
}
|
|
32
19
|
|
|
@@ -47,6 +34,6 @@ export function processRequest<Props>(
|
|
|
47
34
|
}
|
|
48
35
|
|
|
49
36
|
return {
|
|
50
|
-
props: pageProps,
|
|
37
|
+
props: pageProps as Props & PageProps,
|
|
51
38
|
};
|
|
52
39
|
}
|
|
@@ -17,8 +17,8 @@ export interface NewsroomContextType {
|
|
|
17
17
|
companyInformation: NewsroomCompanyInformation;
|
|
18
18
|
categories: Category[];
|
|
19
19
|
contacts?: NewsroomContact[];
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
currentCategory?: Category;
|
|
21
|
+
currentStory?: ExtendedStory;
|
|
22
22
|
languages: NewsroomLanguageSettings[];
|
|
23
23
|
locale: LocaleObject;
|
|
24
24
|
themePreset: NewsroomThemePreset;
|
|
@@ -35,8 +35,8 @@ export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> =
|
|
|
35
35
|
categories,
|
|
36
36
|
contacts,
|
|
37
37
|
newsroom,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
currentCategory,
|
|
39
|
+
currentStory,
|
|
40
40
|
companyInformation,
|
|
41
41
|
languages,
|
|
42
42
|
localeCode,
|
|
@@ -55,8 +55,8 @@ export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> =
|
|
|
55
55
|
categories,
|
|
56
56
|
contacts,
|
|
57
57
|
newsroom,
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
currentCategory,
|
|
59
|
+
currentStory,
|
|
60
60
|
companyInformation,
|
|
61
61
|
languages,
|
|
62
62
|
locale,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from './useAlgoliaSettings';
|
|
2
2
|
export * from './useCategories';
|
|
3
3
|
export * from './useCompanyInformation';
|
|
4
|
+
export * from './useCurrentCategory';
|
|
4
5
|
export * from './useCurrentLocale';
|
|
6
|
+
export * from './useCurrentStory';
|
|
5
7
|
export * from './useGetLinkLocaleSlug';
|
|
6
8
|
export * from './useGetTranslationUrl';
|
|
7
9
|
export * from './useLanguages';
|
|
8
10
|
export * from './useNewsroom';
|
|
9
11
|
export * from './useNewsroomContext';
|
|
10
|
-
export * from './useSelectedCategory';
|
|
11
|
-
export * from './useSelectedStory';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useNewsroomContext } from './useNewsroomContext';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const useCurrentCategory = () => {
|
|
4
4
|
const context = useNewsroomContext();
|
|
5
5
|
|
|
6
|
-
return context.
|
|
6
|
+
return context.currentCategory;
|
|
7
7
|
};
|
|
@@ -5,20 +5,20 @@ import { useCallback } from 'react';
|
|
|
5
5
|
import { getCategoryHasTranslation, getCategoryUrl } from '../../data-fetching';
|
|
6
6
|
import { LocaleObject } from '../../intl';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { useCurrentCategory } from './useCurrentCategory';
|
|
9
|
+
import { useCurrentStory } from './useCurrentStory';
|
|
10
10
|
|
|
11
11
|
// Determine correct URL for translated stories/categories with a fallback to homepage
|
|
12
12
|
function getTranslationUrl(
|
|
13
13
|
locale: LocaleObject,
|
|
14
14
|
path: string,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
currentCategory?: Category,
|
|
16
|
+
currentStory?: ExtendedStory,
|
|
17
17
|
noFallback?: boolean,
|
|
18
18
|
) {
|
|
19
|
-
if (
|
|
20
|
-
if (getCategoryHasTranslation(
|
|
21
|
-
return getCategoryUrl(
|
|
19
|
+
if (currentCategory) {
|
|
20
|
+
if (getCategoryHasTranslation(currentCategory, locale)) {
|
|
21
|
+
return getCategoryUrl(currentCategory, locale);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (noFallback) {
|
|
@@ -30,8 +30,8 @@ function getTranslationUrl(
|
|
|
30
30
|
|
|
31
31
|
const localeCode = locale.toUnderscoreCode();
|
|
32
32
|
|
|
33
|
-
if (
|
|
34
|
-
const translatedStory =
|
|
33
|
+
if (currentStory && currentStory.culture.locale !== localeCode) {
|
|
34
|
+
const translatedStory = currentStory.translations.find(
|
|
35
35
|
({ culture }) => culture.locale === localeCode,
|
|
36
36
|
);
|
|
37
37
|
if (translatedStory) {
|
|
@@ -50,12 +50,12 @@ function getTranslationUrl(
|
|
|
50
50
|
|
|
51
51
|
export function useGetTranslationUrl() {
|
|
52
52
|
const { asPath } = useRouter();
|
|
53
|
-
const
|
|
54
|
-
const
|
|
53
|
+
const currentCategory = useCurrentCategory();
|
|
54
|
+
const currentStory = useCurrentStory();
|
|
55
55
|
|
|
56
56
|
return useCallback(
|
|
57
57
|
(locale: LocaleObject, noFallback?: boolean) =>
|
|
58
|
-
getTranslationUrl(locale, asPath,
|
|
59
|
-
[asPath,
|
|
58
|
+
getTranslationUrl(locale, asPath, currentCategory, currentStory, noFallback),
|
|
59
|
+
[asPath, currentCategory, currentStory],
|
|
60
60
|
);
|
|
61
61
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useSelectedCategory: () => import("@prezly/sdk").Category | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSelectedCategory = void 0;
|
|
4
|
-
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
-
var useSelectedCategory = function () {
|
|
6
|
-
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
|
-
return context.selectedCategory;
|
|
8
|
-
};
|
|
9
|
-
exports.useSelectedCategory = useSelectedCategory;
|
|
10
|
-
//# sourceMappingURL=useSelectedCategory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectedCategory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedCategory.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,mBAAmB,GAAG;IAC/B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,gBAAgB,CAAC;AACpC,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useSelectedStory: () => import("@prezly/sdk").ExtendedStory | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectedStory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedStory.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,gBAAgB,GAAG;IAC5B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,aAAa,CAAC;AACjC,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
|