@prezly/theme-kit-nextjs 1.1.4 → 1.1.5-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 +36 -64
- package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +9 -0
- package/build/adapter-nextjs/{getBasePageProps.js → getNewsroomServerSideProps.js} +9 -9
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -0
- package/build/adapter-nextjs/index.d.ts +1 -1
- package/build/adapter-nextjs/index.js +1 -1
- package/build/adapter-nextjs/index.js.map +1 -1
- package/build/adapter-nextjs/processRequest.d.ts +2 -2
- package/build/adapter-nextjs/processRequest.js +27 -14
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +2 -2
- package/build/data-fetching/api/PrezlyApi.js +11 -11
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/intl/locale.d.ts +1 -2
- package/build/intl/locale.js +1 -2
- package/build/intl/locale.js.map +1 -1
- package/build/newsroom-context/context.d.ts +5 -7
- package/build/newsroom-context/context.js +15 -23
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.d.ts +2 -2
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/newsroom-context/index.d.ts +1 -1
- package/build/newsroom-context/index.js.map +1 -1
- package/build/types.d.ts +6 -20
- package/package.json +21 -4
- package/src/adapter-nextjs/{getBasePageProps.ts → getNewsroomServerSideProps.ts} +6 -6
- package/src/adapter-nextjs/index.ts +1 -1
- package/src/adapter-nextjs/processRequest.ts +33 -12
- package/src/data-fetching/api/PrezlyApi.ts +12 -13
- package/src/intl/locale.ts +1 -4
- package/src/newsroom-context/context.tsx +5 -8
- package/src/newsroom-context/hooks/useNewsroomContext.ts +2 -2
- package/src/newsroom-context/index.ts +1 -1
- package/src/types.ts +9 -32
- package/build/adapter-nextjs/getBasePageProps.d.ts +0 -9
- package/build/adapter-nextjs/getBasePageProps.js.map +0 -1
package/README.md
CHANGED
|
@@ -87,48 +87,24 @@ module.exports = {
|
|
|
87
87
|
|
|
88
88
|
### pages/_app.tsx
|
|
89
89
|
|
|
90
|
-
In order to provide all the necessary data to the entire application,
|
|
90
|
+
In order to provide all the necessary data to the entire application, this library exports the `NewsroomContextProvider` component, which accepts props retrieved by our data-fetching methods (see next section). These props contain data that would be required to display common components like navigation, language picker, boilerplate, etc.
|
|
91
91
|
|
|
92
|
-
```
|
|
93
|
-
import {
|
|
94
|
-
import { AppProps } from 'next/app';
|
|
92
|
+
```tsx
|
|
93
|
+
import { NewsroomContextProvider, PageProps } from '@prezly/theme-kit-nextjs';
|
|
94
|
+
import type { AppProps } from 'next/app';
|
|
95
95
|
|
|
96
96
|
type AnyPageProps = Record<string, any>;
|
|
97
97
|
|
|
98
98
|
function App({ Component, pageProps }: AppProps<AnyPageProps>) {
|
|
99
|
-
const {
|
|
100
|
-
categories,
|
|
101
|
-
contacts,
|
|
102
|
-
newsroom,
|
|
103
|
-
companyInformation,
|
|
104
|
-
languages,
|
|
105
|
-
localeCode,
|
|
106
|
-
themePreset,
|
|
107
|
-
algoliaSettings,
|
|
108
|
-
selectedCategory,
|
|
109
|
-
selectedStory,
|
|
110
|
-
hasError,
|
|
111
|
-
...customPageProps
|
|
112
|
-
} = pageProps as BasePageProps & AnyPageProps;
|
|
99
|
+
const { newsroomContextProps, ...customPageProps } = pageProps as PageProps & AnyPageProps;
|
|
113
100
|
|
|
101
|
+
// eslint-disable react/jsx-props-no-spreading
|
|
114
102
|
return (
|
|
115
|
-
<NewsroomContextProvider
|
|
116
|
-
categories={categories}
|
|
117
|
-
contacts={contacts}
|
|
118
|
-
newsroom={newsroom}
|
|
119
|
-
companyInformation={companyInformation}
|
|
120
|
-
languages={languages}
|
|
121
|
-
localeCode={localeCode}
|
|
122
|
-
themePreset={themePreset}
|
|
123
|
-
selectedCategory={selectedCategory}
|
|
124
|
-
selectedStory={selectedStory}
|
|
125
|
-
algoliaSettings={algoliaSettings}
|
|
126
|
-
hasError={hasError}
|
|
127
|
-
>
|
|
128
|
-
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
|
|
103
|
+
<NewsroomContextProvider {...newsroomContextProps}>
|
|
129
104
|
<Component {...customPageProps} />
|
|
130
105
|
</NewsroomContextProvider>
|
|
131
106
|
);
|
|
107
|
+
// eslint-enable react/jsx-props-no-spreading
|
|
132
108
|
}
|
|
133
109
|
|
|
134
110
|
export default App;
|
|
@@ -138,64 +114,60 @@ export default App;
|
|
|
138
114
|
|
|
139
115
|
Every page requires a bit of boilerplate code to set up.
|
|
140
116
|
|
|
141
|
-
```
|
|
142
|
-
import {
|
|
143
|
-
import { GetServerSideProps } from 'next';
|
|
117
|
+
```tsx
|
|
118
|
+
import { getNewsroomServerSideProps, processRequest } from '@prezly/theme-kit-nextjs';
|
|
119
|
+
import type { GetServerSideProps } from 'next';
|
|
144
120
|
import type { FunctionComponent } from 'react';
|
|
145
121
|
|
|
146
|
-
interface Props
|
|
147
|
-
|
|
122
|
+
interface Props {
|
|
123
|
+
myProp: string;
|
|
148
124
|
}
|
|
149
125
|
|
|
150
|
-
const Page: FunctionComponent<Props> = () =>
|
|
126
|
+
const Page: FunctionComponent<Props> = ({ myProp }) => <p>{myProp}</p>;
|
|
151
127
|
|
|
152
128
|
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
|
|
153
|
-
const { api,
|
|
129
|
+
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
154
130
|
|
|
155
131
|
/* Your logic to get additional props for this page */
|
|
156
132
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
133
|
+
return processRequest(
|
|
134
|
+
context,
|
|
135
|
+
{
|
|
136
|
+
...serverSideProps,
|
|
137
|
+
myProp: 'My Custom Prop',
|
|
138
|
+
},
|
|
139
|
+
'/',
|
|
140
|
+
);
|
|
161
141
|
};
|
|
162
142
|
|
|
163
143
|
export default Page;
|
|
164
144
|
```
|
|
165
145
|
|
|
166
|
-
|
|
167
|
-
#### Here's a breakdown of what's happening:
|
|
168
|
-
|
|
169
|
-
**Prop types**
|
|
170
|
-
```ts
|
|
171
|
-
interface Props extends BasePageProps {
|
|
172
|
-
/* Additional props for this page */
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
Every page props should extend `BasePageProps` type, since they are required for `NewsroomContextProvider` added previously.
|
|
176
|
-
These props contain data that would be required to display common components like navigation, language picker, boilerplate, etc.
|
|
177
|
-
|
|
178
146
|
**Page display component**
|
|
179
|
-
```
|
|
180
|
-
const Page: FunctionComponent<Props> = () =>
|
|
147
|
+
```tsx
|
|
148
|
+
const Page: FunctionComponent<Props> = ({ myProp }) => <p>{myProp}</p>;
|
|
181
149
|
```
|
|
182
|
-
Since all of the common data is loaded into the `NewsroomContextProvider`, you don't need to handle any of those in your display components. So the Page component should just handle rendering the provided data.
|
|
150
|
+
Since all of the common data is loaded into the `NewsroomContextProvider`, you don't need to handle any of those in your display components. So the Page component should just handle rendering the provided data. You can still use context hooks to access the newsroom data.
|
|
183
151
|
|
|
184
152
|
**Data fetching**
|
|
185
153
|
```ts
|
|
186
|
-
const { api,
|
|
154
|
+
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
187
155
|
```
|
|
188
156
|
This function fetches all the required base props and exposes the `PrezlyApi` instance, which you can use to fetch additional content like stories or categories.
|
|
189
157
|
|
|
190
158
|
```ts
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
159
|
+
return processRequest(
|
|
160
|
+
context,
|
|
161
|
+
{
|
|
162
|
+
...serverSideProps,
|
|
163
|
+
myProp: 'My Custom Prop',
|
|
164
|
+
},
|
|
165
|
+
'/',
|
|
166
|
+
);
|
|
195
167
|
```
|
|
196
168
|
This function returns the combined base props and your additional props, with some extra logic in between to handle locale URLs.
|
|
197
169
|
|
|
198
|
-
The third argument is
|
|
170
|
+
The third argument is needed to properly handle locale redirects. It should contain the URL for the current page without locale prefixes (like `/`, `/media`, `/category/${category.slug}`. If omitted, the redirect logic will not be executing.
|
|
199
171
|
|
|
200
172
|
----
|
|
201
173
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GetServerSidePropsContext } from 'next';
|
|
2
|
+
interface Options {
|
|
3
|
+
loadHomepageContacts?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function getNewsroomServerSideProps(context: GetServerSidePropsContext, options?: Options): Promise<{
|
|
6
|
+
api: import("../data-fetching/api/PrezlyApi").PrezlyApi;
|
|
7
|
+
serverSideProps: import("..").PageProps & import("..").ServerSidePageProps;
|
|
8
|
+
}>;
|
|
9
|
+
export {};
|
|
@@ -36,30 +36,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.getNewsroomServerSideProps = void 0;
|
|
40
40
|
var data_fetching_1 = require("../data-fetching");
|
|
41
|
-
function
|
|
41
|
+
function getNewsroomServerSideProps(context, options) {
|
|
42
42
|
if (options === void 0) { options = {}; }
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var request, locale, api,
|
|
44
|
+
var request, locale, api, serverSideProps, _a;
|
|
45
45
|
return __generator(this, function (_b) {
|
|
46
46
|
switch (_b.label) {
|
|
47
47
|
case 0:
|
|
48
48
|
request = context.req, locale = context.locale;
|
|
49
49
|
api = (0, data_fetching_1.getPrezlyApi)(request);
|
|
50
|
-
return [4 /*yield*/, api.
|
|
50
|
+
return [4 /*yield*/, api.getNewsroomServerSideProps(request, locale)];
|
|
51
51
|
case 1:
|
|
52
|
-
|
|
52
|
+
serverSideProps = _b.sent();
|
|
53
53
|
if (!options.loadHomepageContacts) return [3 /*break*/, 3];
|
|
54
|
-
_a =
|
|
54
|
+
_a = serverSideProps.newsroomContextProps;
|
|
55
55
|
return [4 /*yield*/, api.getNewsroomContacts()];
|
|
56
56
|
case 2:
|
|
57
57
|
_a.contacts = _b.sent();
|
|
58
58
|
_b.label = 3;
|
|
59
|
-
case 3: return [2 /*return*/, { api: api,
|
|
59
|
+
case 3: return [2 /*return*/, { api: api, serverSideProps: serverSideProps }];
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
exports.
|
|
65
|
-
//# sourceMappingURL=
|
|
64
|
+
exports.getNewsroomServerSideProps = getNewsroomServerSideProps;
|
|
65
|
+
//# sourceMappingURL=getNewsroomServerSideProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNewsroomServerSideProps.js","sourceRoot":"","sources":["../../src/adapter-nextjs/getNewsroomServerSideProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAAgD;AAMhD,SAAsB,0BAA0B,CAC5C,OAAkC,EAClC,OAAqB;IAArB,wBAAA,EAAA,YAAqB;;;;;;oBAER,OAAO,GAAa,OAAO,IAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;oBAEnC,GAAG,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,CAAC;oBACV,qBAAM,GAAG,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;oBAAvE,eAAe,GAAG,SAAqD;yBAEzE,OAAO,CAAC,oBAAoB,EAA5B,wBAA4B;oBAC5B,KAAA,eAAe,CAAC,oBAAoB,CAAA;oBAAY,qBAAM,GAAG,CAAC,mBAAmB,EAAE,EAAA;;oBAA/E,GAAqC,QAAQ,GAAG,SAA+B,CAAC;;wBAGpF,sBAAO,EAAE,GAAG,KAAA,EAAE,eAAe,iBAAA,EAAE,EAAC;;;;CACnC;AAdD,gEAcC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './getNewsroomServerSideProps';
|
|
2
2
|
export * from './processRequest';
|
|
@@ -10,6 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./
|
|
13
|
+
__exportStar(require("./getNewsroomServerSideProps"), exports);
|
|
14
14
|
__exportStar(require("./processRequest"), exports);
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapter-nextjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapter-nextjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA6C;AAC7C,mDAAiC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
-
import {
|
|
3
|
-
export declare function processRequest<Props
|
|
2
|
+
import { PageProps, ServerSidePageProps } from '../types';
|
|
3
|
+
export declare function processRequest<Props>(context: GetServerSidePropsContext, props: Props & PageProps & ServerSidePageProps, canonicalUrl?: string): GetServerSidePropsResult<Props>;
|
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
11
|
+
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.processRequest = void 0;
|
|
15
|
+
var data_fetching_1 = require("../data-fetching");
|
|
15
16
|
var intl_1 = require("../intl");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
function processRequest(context, props, canonicalUrl) {
|
|
26
|
+
var nextLocale = context.locale, query = context.query;
|
|
27
|
+
var _a = extractServerSideProps(props), pageProps = _a.pageProps, serverSideProps = _a.serverSideProps;
|
|
28
|
+
if (!serverSideProps.localeResolved) {
|
|
19
29
|
return { notFound: true };
|
|
20
30
|
}
|
|
21
31
|
if (canonicalUrl) {
|
|
22
|
-
var
|
|
32
|
+
var _b = pageProps.newsroomContextProps, languages = _b.languages, localeCode = _b.localeCode;
|
|
33
|
+
var currentLocale = intl_1.LocaleObject.fromAnyCode(localeCode);
|
|
34
|
+
var shortestLocaleCode = (0, data_fetching_1.getShortestLocaleCode)(languages, currentLocale);
|
|
35
|
+
var redirect = (0, intl_1.getRedirectToCanonicalLocale)(shortestLocaleCode, nextLocale, canonicalUrl, query);
|
|
23
36
|
if (redirect) {
|
|
24
37
|
return { redirect: redirect };
|
|
25
38
|
}
|
|
26
39
|
}
|
|
27
40
|
return {
|
|
28
|
-
props:
|
|
41
|
+
props: pageProps,
|
|
29
42
|
};
|
|
30
43
|
}
|
|
31
44
|
exports.processRequest = processRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,kDAAyD;AACzD,gCAAqE;AAGrE,iDAAiD;AACjD,SAAS,sBAAsB,CAAQ,KAAkC;IAI7D,IAAA,cAAc,GAAmB,KAAK,eAAxB,EAAK,SAAS,UAAK,KAAK,EAAxC,kBAAgC,CAAF,CAAW;IAE/C,OAAO;QACH,SAAS,EAAE,SAA6B;QACxC,eAAe,EAAE,EAAE,cAAc,gBAAA,EAAE;KACtC,CAAC;AACN,CAAC;AAED,SAAgB,cAAc,CAC1B,OAAkC,EAClC,KAA8C,EAC9C,YAAqB;IAEb,IAAQ,UAAU,GAAY,OAAO,OAAnB,EAAE,KAAK,GAAK,OAAO,MAAZ,CAAa;IAExC,IAAA,KAAiC,sBAAsB,CAAC,KAAK,CAAC,EAA5D,SAAS,eAAA,EAAE,eAAe,qBAAkC,CAAC;IAErE,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE;QACjC,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,SAAS;KACnB,CAAC;AACN,CAAC;AAhCD,wCAgCC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import PrezlySDK, { Category, ExtraStoryFields, Newsroom, NewsroomLanguageSettings, Story } from '@prezly/sdk';
|
|
3
3
|
import type { IncomingMessage } from 'http';
|
|
4
|
-
import {
|
|
4
|
+
import { PageProps, ServerSidePageProps } from '../../types';
|
|
5
5
|
declare type SortOrder = 'desc' | 'asc';
|
|
6
6
|
interface GetStoriesOptions {
|
|
7
7
|
page?: number;
|
|
@@ -38,6 +38,6 @@ export declare class PrezlyApi {
|
|
|
38
38
|
getGalleries({ page, pageSize }: GetGalleriesOptions): Promise<import("@prezly/sdk/dist/Sdk/NewsroomGalleries/types").NewsroomGalleriesListResponse>;
|
|
39
39
|
getGallery(uuid: string): Promise<import("@prezly/sdk").NewsroomGallery>;
|
|
40
40
|
getThemePreset(): Promise<import("@prezly/sdk").NewsroomThemePreset>;
|
|
41
|
-
|
|
41
|
+
getNewsroomServerSideProps(request: IncomingMessage | undefined, nextLocaleIsoCode?: string, story?: Story): Promise<PageProps & ServerSidePageProps>;
|
|
42
42
|
}
|
|
43
43
|
export {};
|
|
@@ -262,9 +262,9 @@ var PrezlyApi = /** @class */ (function () {
|
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
264
|
};
|
|
265
|
-
PrezlyApi.prototype.
|
|
265
|
+
PrezlyApi.prototype.getNewsroomServerSideProps = function (request, nextLocaleIsoCode, story) {
|
|
266
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
-
var _a, newsroom, languages, categories, themePreset, currentLanguage, defaultLanguage, localeCode, locale,
|
|
267
|
+
var _a, newsroom, languages, categories, themePreset, currentLanguage, defaultLanguage, localeCode, locale, companyInformation, algoliaSettings;
|
|
268
268
|
return __generator(this, function (_b) {
|
|
269
269
|
switch (_b.label) {
|
|
270
270
|
case 0: return [4 /*yield*/, Promise.all([
|
|
@@ -281,19 +281,19 @@ var PrezlyApi = /** @class */ (function () {
|
|
|
281
281
|
defaultLanguage = (0, languages_1.getDefaultLanguage)(languages);
|
|
282
282
|
localeCode = (currentLanguage || defaultLanguage).code;
|
|
283
283
|
locale = intl_1.LocaleObject.fromAnyCode(localeCode);
|
|
284
|
-
shortestLocaleCode = (0, languages_1.getShortestLocaleCode)(languages, locale);
|
|
285
284
|
companyInformation = (0, languages_1.getCompanyInformation)(languages, locale);
|
|
286
285
|
algoliaSettings = (0, getAlgoliaSettings_1.getAlgoliaSettings)(request);
|
|
287
286
|
return [2 /*return*/, {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
287
|
+
newsroomContextProps: {
|
|
288
|
+
newsroom: newsroom,
|
|
289
|
+
companyInformation: companyInformation,
|
|
290
|
+
categories: categories,
|
|
291
|
+
languages: languages,
|
|
292
|
+
localeCode: localeCode,
|
|
293
|
+
themePreset: themePreset,
|
|
294
|
+
algoliaSettings: algoliaSettings,
|
|
295
|
+
},
|
|
294
296
|
localeResolved: Boolean(currentLanguage),
|
|
295
|
-
themePreset: themePreset,
|
|
296
|
-
algoliaSettings: algoliaSettings,
|
|
297
297
|
}];
|
|
298
298
|
}
|
|
299
299
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrezlyApi.js","sourceRoot":"","sources":["../../../src/data-fetching/api/PrezlyApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAMqB;AAGrB,mCAA0C;AAE1C,0CAAiD;AACjD,gEAA+D;AAE/D,
|
|
1
|
+
{"version":3,"file":"PrezlyApi.js","sourceRoot":"","sources":["../../../src/data-fetching/api/PrezlyApi.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QAAQ,QAAA,EAAE,SAAS,QAAA,EAAE,UAAU,QAAA,EAAE,WAAW,QAAA;wBAO7C,eAAe,GAAG,KAAK;4BACzB,CAAC,CAAC,IAAA,gCAAoB,EAAC,SAAS,EAAE,KAAK,CAAC;4BACxC,CAAC,CAAC,IAAA,4CAAgC,EAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;wBAC/D,eAAe,GAAG,IAAA,8BAAkB,EAAC,SAAS,CAAC,CAAC;wBAExC,UAAU,GAAK,CAAA,eAAe,IAAI,eAAe,CAAA,KAAvC,CAAwC;wBAC1D,MAAM,GAAG,mBAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;wBAG9C,kBAAkB,GAAG,IAAA,iCAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;wBAE9D,eAAe,GAAG,IAAA,uCAAkB,EAAC,OAAO,CAAC,CAAC;wBAEpD,sBAAO;gCACH,oBAAoB,EAAE;oCAClB,QAAQ,UAAA;oCACR,kBAAkB,oBAAA;oCAClB,UAAU,YAAA;oCACV,SAAS,WAAA;oCACT,UAAU,YAAA;oCACV,WAAW,aAAA;oCACX,eAAe,iBAAA;iCAClB;gCACD,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC;6BAC3C,EAAC;;;;KACL;IACL,gBAAC;AAAD,CAAC,AAjMD,IAiMC;AAjMY,8BAAS"}
|
package/build/intl/locale.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Redirect } from 'next';
|
|
3
3
|
import { ParsedUrlQuery } from 'querystring';
|
|
4
|
-
import { BasePageProps } from '../types';
|
|
5
4
|
import { LocaleObject } from './localeObject';
|
|
6
5
|
export declare const DEFAULT_LOCALE = "en";
|
|
7
6
|
export declare const DUMMY_DEFAULT_LOCALE = "qps-ploc";
|
|
8
7
|
export declare function getSupportedLocaleIsoCode(locale: LocaleObject): string;
|
|
9
|
-
export declare function getRedirectToCanonicalLocale(
|
|
8
|
+
export declare function getRedirectToCanonicalLocale(shortestLocaleCode: string | false, nextLocaleIsoCode: string | undefined, redirectPath: string, query?: ParsedUrlQuery): Redirect | undefined;
|
|
10
9
|
export declare function getLocaleDirection(locale: LocaleObject): 'ltr' | 'rtl';
|
package/build/intl/locale.js
CHANGED
|
@@ -67,8 +67,7 @@ function getSupportedLocaleIsoCode(locale) {
|
|
|
67
67
|
return exports.DEFAULT_LOCALE;
|
|
68
68
|
}
|
|
69
69
|
exports.getSupportedLocaleIsoCode = getSupportedLocaleIsoCode;
|
|
70
|
-
function getRedirectToCanonicalLocale(
|
|
71
|
-
var shortestLocaleCode = basePageProps.shortestLocaleCode;
|
|
70
|
+
function getRedirectToCanonicalLocale(shortestLocaleCode, nextLocaleIsoCode, redirectPath, query) {
|
|
72
71
|
var shortestLocaleSlug = shortestLocaleCode
|
|
73
72
|
? localeObject_1.LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
|
|
74
73
|
: shortestLocaleCode;
|
package/build/intl/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AACA,2CAAwD;
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AACA,2CAAwD;AAExD,+CAA8C;AAEjC,QAAA,cAAc,GAAG,IAAI,CAAC;AACtB,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAE/C,IAAM,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,I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AC,CAAC,WAAI,YAAY,CAAE,CAAC,CAAC,CAAC,YAAY,CAAC;QAEtF,IAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,WAAI,IAAA,uBAAS,EAAC,KAAK,CAAC,CAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAErD,OAAO;YACH,WAAW,EAAE,kBAAkB;gBAC3B,CAAC,CAAC,WAAI,kBAAkB,SAAG,YAAY,SAAG,QAAQ,CAAE;gBACpD,CAAC,CAAC,UAAG,YAAY,SAAG,QAAQ,CAAE;YAClC,SAAS,EAAE,KAAK;SACnB,CAAC;KACL;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AA7BD,oEA6BC;AAED,SAAgB,kBAAkB,CAAC,MAAoB;IACnD,IAAM,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,8 +1,8 @@
|
|
|
1
1
|
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset } from '@prezly/sdk';
|
|
2
|
-
import
|
|
2
|
+
import { FunctionComponent } from 'react';
|
|
3
3
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
4
|
import { LocaleObject } from '../intl';
|
|
5
|
-
export interface
|
|
5
|
+
export interface NewsroomContextType {
|
|
6
6
|
newsroom: Newsroom;
|
|
7
7
|
companyInformation: NewsroomCompanyInformation;
|
|
8
8
|
categories: Category[];
|
|
@@ -11,13 +11,11 @@ export interface INewsroomContext {
|
|
|
11
11
|
selectedStory?: ExtendedStory;
|
|
12
12
|
languages: NewsroomLanguageSettings[];
|
|
13
13
|
locale: LocaleObject;
|
|
14
|
-
hasError?: boolean;
|
|
15
14
|
themePreset: NewsroomThemePreset;
|
|
16
15
|
algoliaSettings: AlgoliaSettings;
|
|
17
16
|
}
|
|
18
|
-
interface
|
|
17
|
+
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
19
18
|
localeCode: string;
|
|
20
19
|
}
|
|
21
|
-
export declare const NewsroomContext:
|
|
22
|
-
export declare const NewsroomContextProvider: FunctionComponent<
|
|
23
|
-
export {};
|
|
20
|
+
export declare const NewsroomContext: import("react").Context<NewsroomContextType | undefined>;
|
|
21
|
+
export declare const NewsroomContextProvider: FunctionComponent<NewsroomContextProps>;
|
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
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);
|
|
20
12
|
};
|
|
21
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
14
|
exports.NewsroomContextProvider = exports.NewsroomContext = void 0;
|
|
23
|
-
var
|
|
15
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
var react_1 = require("react");
|
|
24
17
|
var intl_1 = require("../intl");
|
|
25
18
|
exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
26
19
|
var NewsroomContextProvider = function (_a) {
|
|
27
|
-
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, selectedCategory = _a.selectedCategory, selectedStory = _a.selectedStory, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode,
|
|
20
|
+
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, selectedCategory = _a.selectedCategory, selectedStory = _a.selectedStory, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode, themePreset = _a.themePreset, algoliaSettings = _a.algoliaSettings, children = _a.children;
|
|
28
21
|
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
29
|
-
return (
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(exports.NewsroomContext.Provider, __assign({ value: {
|
|
30
23
|
categories: categories,
|
|
31
24
|
contacts: contacts,
|
|
32
25
|
newsroom: newsroom,
|
|
@@ -35,10 +28,9 @@ var NewsroomContextProvider = function (_a) {
|
|
|
35
28
|
companyInformation: companyInformation,
|
|
36
29
|
languages: languages,
|
|
37
30
|
locale: locale,
|
|
38
|
-
hasError: hasError,
|
|
39
31
|
themePreset: themePreset,
|
|
40
32
|
algoliaSettings: algoliaSettings,
|
|
41
|
-
} }, children));
|
|
33
|
+
} }, { children: children }), void 0));
|
|
42
34
|
};
|
|
43
35
|
exports.NewsroomContextProvider = NewsroomContextProvider;
|
|
44
36
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":"
|
|
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,gBAAgB,sBAAA,EAChB,aAAa,mBAAA,EACb,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,gBAAgB,kBAAA;YAChB,aAAa,eAAA;YACb,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,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const useNewsroomContext: () =>
|
|
1
|
+
import { NewsroomContextType } from '../context';
|
|
2
|
+
export declare const useNewsroomContext: () => NewsroomContextType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAEnC,
|
|
1
|
+
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAEnC,sCAAkE;AAE3D,IAAM,kBAAkB,GAAG;IAC9B,mGAAmG;IACnG,iFAAiF;IACjF,IAAM,eAAe,GAAoC,IAAA,kBAAU,EAAC,yBAAe,CAAC,CAAC;IACrF,IAAI,CAAC,eAAe,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;KAC3F;IAED,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { NewsroomContext, NewsroomContextProvider } from './context';
|
|
1
|
+
export { NewsroomContext, NewsroomContextProvider, NewsroomContextProps } from './context';
|
|
2
2
|
export * from './hooks';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/newsroom-context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/newsroom-context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,qCAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,kHAAA,uBAAuB,OAAA;AACjD,0CAAwB"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
export interface
|
|
4
|
-
newsroom: Newsroom;
|
|
5
|
-
companyInformation: NewsroomCompanyInformation;
|
|
6
|
-
categories: Category[];
|
|
7
|
-
languages: NewsroomLanguageSettings[];
|
|
8
|
-
localeCode: string;
|
|
9
|
-
/**
|
|
10
|
-
* `false` means it's the default locale
|
|
11
|
-
*/
|
|
12
|
-
shortestLocaleCode: string | false;
|
|
1
|
+
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
2
|
+
import { NewsroomContextProps } from './newsroom-context';
|
|
3
|
+
export interface ServerSidePageProps {
|
|
13
4
|
localeResolved: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
contacts?: NewsroomContact[];
|
|
18
|
-
isTrackingEnabled?: boolean;
|
|
19
|
-
selectedCategory?: Category;
|
|
20
|
-
selectedStory?: ExtendedStory;
|
|
5
|
+
}
|
|
6
|
+
export interface PageProps {
|
|
7
|
+
newsroomContextProps: NewsroomContextProps;
|
|
21
8
|
}
|
|
22
9
|
export interface AlgoliaCategoryRef {
|
|
23
10
|
id: number;
|
|
@@ -31,4 +18,3 @@ export declare type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subt
|
|
|
31
18
|
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
32
19
|
categories: AlgoliaCategoryRef[];
|
|
33
20
|
};
|
|
34
|
-
export declare type Translations = Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/theme-kit-nextjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5-0",
|
|
4
4
|
"description": "Data layer and utility library for developing Prezly themes with NextJS",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,12 +29,18 @@
|
|
|
29
29
|
"homepage": "https://github.com/prezly/theme-kit-nextjs#readme",
|
|
30
30
|
"scripts": {
|
|
31
31
|
"clean": "rimraf build/ node_modules/",
|
|
32
|
-
"typecheck": "tsc --noEmit --incremental --project .",
|
|
33
32
|
"prebuild": "npm run clean && npm install",
|
|
34
33
|
"build": "tsc --project .",
|
|
35
34
|
"test": "echo \"Tests? maybe next time ;)\" && exit 0",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
35
|
+
"typecheck": "tsc --noEmit --incremental --project .",
|
|
36
|
+
"lint": "eslint src",
|
|
37
|
+
"lint:fix": "npm run lint -- --fix",
|
|
38
|
+
"prettier": "prettier --check './**/*.(js|ts|tsx|css)'",
|
|
39
|
+
"prettier:fix": "npm run prettier -- --write --no-list-different",
|
|
40
|
+
"check": "npm run lint && npm run typecheck",
|
|
41
|
+
"prerelease": "npm run check && npm run build",
|
|
42
|
+
"release": "np",
|
|
43
|
+
"release:preview": "npm run prerelease && np prerelease --any-branch --no-release-draft --tag=preview"
|
|
38
44
|
},
|
|
39
45
|
"peerDependencies": {
|
|
40
46
|
"next": "^12.x",
|
|
@@ -50,7 +56,18 @@
|
|
|
50
56
|
"@types/parse-data-url": "^3.0.0",
|
|
51
57
|
"@types/react": "^17.0.38",
|
|
52
58
|
"@types/react-dom": "^17.0.11",
|
|
59
|
+
"eslint": "^8.8.0",
|
|
60
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
61
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
62
|
+
"eslint-config-prettier": "^8.3.0",
|
|
63
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
64
|
+
"eslint-plugin-import": "^2.25.4",
|
|
65
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
66
|
+
"eslint-plugin-react": "^7.28.0",
|
|
67
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
68
|
+
"eslint-plugin-sort-export-all": "^1.2.1",
|
|
53
69
|
"np": "^7.6.0",
|
|
70
|
+
"prettier": "^2.5.1",
|
|
54
71
|
"rimraf": "^3.0.2",
|
|
55
72
|
"typescript": "^4.5.5"
|
|
56
73
|
},
|
|
@@ -2,22 +2,22 @@ import type { GetServerSidePropsContext } from 'next';
|
|
|
2
2
|
|
|
3
3
|
import { getPrezlyApi } from '../data-fetching';
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface Options {
|
|
6
6
|
loadHomepageContacts?: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export async function
|
|
9
|
+
export async function getNewsroomServerSideProps(
|
|
10
10
|
context: GetServerSidePropsContext,
|
|
11
|
-
options:
|
|
11
|
+
options: Options = {},
|
|
12
12
|
) {
|
|
13
13
|
const { req: request, locale } = context;
|
|
14
14
|
|
|
15
15
|
const api = getPrezlyApi(request);
|
|
16
|
-
const
|
|
16
|
+
const serverSideProps = await api.getNewsroomServerSideProps(request, locale);
|
|
17
17
|
|
|
18
18
|
if (options.loadHomepageContacts) {
|
|
19
|
-
|
|
19
|
+
serverSideProps.newsroomContextProps.contacts = await api.getNewsroomContacts();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
return { api,
|
|
22
|
+
return { api, serverSideProps };
|
|
23
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './getNewsroomServerSideProps';
|
|
2
2
|
export * from './processRequest';
|
|
@@ -1,31 +1,52 @@
|
|
|
1
1
|
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getShortestLocaleCode } from '../data-fetching';
|
|
4
|
+
import { getRedirectToCanonicalLocale, LocaleObject } from '../intl';
|
|
5
|
+
import { PageProps, ServerSidePageProps } from '../types';
|
|
5
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
|
+
export function processRequest<Props>(
|
|
7
21
|
context: GetServerSidePropsContext,
|
|
8
|
-
|
|
22
|
+
props: Props & PageProps & ServerSidePageProps,
|
|
9
23
|
canonicalUrl?: string,
|
|
10
|
-
customProps?: Omit<Props, keyof BasePageProps>,
|
|
11
24
|
): GetServerSidePropsResult<Props> {
|
|
12
|
-
const { locale, query } = context;
|
|
25
|
+
const { locale: nextLocale, query } = context;
|
|
26
|
+
|
|
27
|
+
const { pageProps, serverSideProps } = extractServerSideProps(props);
|
|
13
28
|
|
|
14
|
-
if (!
|
|
29
|
+
if (!serverSideProps.localeResolved) {
|
|
15
30
|
return { notFound: true };
|
|
16
31
|
}
|
|
17
32
|
|
|
18
33
|
if (canonicalUrl) {
|
|
19
|
-
const
|
|
34
|
+
const { languages, localeCode } = pageProps.newsroomContextProps;
|
|
35
|
+
const currentLocale = LocaleObject.fromAnyCode(localeCode);
|
|
36
|
+
const shortestLocaleCode = getShortestLocaleCode(languages, currentLocale);
|
|
37
|
+
|
|
38
|
+
const redirect = getRedirectToCanonicalLocale(
|
|
39
|
+
shortestLocaleCode,
|
|
40
|
+
nextLocale,
|
|
41
|
+
canonicalUrl,
|
|
42
|
+
query,
|
|
43
|
+
);
|
|
20
44
|
if (redirect) {
|
|
21
45
|
return { redirect };
|
|
22
46
|
}
|
|
23
47
|
}
|
|
24
48
|
|
|
25
49
|
return {
|
|
26
|
-
props:
|
|
27
|
-
...basePageProps,
|
|
28
|
-
...customProps,
|
|
29
|
-
} as Props,
|
|
50
|
+
props: pageProps,
|
|
30
51
|
};
|
|
31
52
|
}
|
|
@@ -8,7 +8,7 @@ import PrezlySDK, {
|
|
|
8
8
|
import type { IncomingMessage } from 'http';
|
|
9
9
|
|
|
10
10
|
import { LocaleObject } from '../../intl';
|
|
11
|
-
import {
|
|
11
|
+
import { PageProps, ServerSidePageProps } from '../../types';
|
|
12
12
|
import { DEFAULT_PAGE_SIZE } from '../constants';
|
|
13
13
|
import { getAlgoliaSettings } from '../lib/getAlgoliaSettings';
|
|
14
14
|
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
getDefaultLanguage,
|
|
18
18
|
getLanguageFromNextLocaleIsoCode,
|
|
19
19
|
getLanguageFromStory,
|
|
20
|
-
getShortestLocaleCode,
|
|
21
20
|
} from './languages';
|
|
22
21
|
import {
|
|
23
22
|
getContactsQuery,
|
|
@@ -199,11 +198,11 @@ export class PrezlyApi {
|
|
|
199
198
|
return this.sdk.newsroomThemes.getActive(this.newsroomUuid);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
|
-
async
|
|
201
|
+
async getNewsroomServerSideProps(
|
|
203
202
|
request: IncomingMessage | undefined,
|
|
204
203
|
nextLocaleIsoCode?: string,
|
|
205
204
|
story?: Story,
|
|
206
|
-
): Promise<
|
|
205
|
+
): Promise<PageProps & ServerSidePageProps> {
|
|
207
206
|
const [newsroom, languages, categories, themePreset] = await Promise.all([
|
|
208
207
|
this.getNewsroom(),
|
|
209
208
|
this.getNewsroomLanguages(),
|
|
@@ -218,7 +217,6 @@ export class PrezlyApi {
|
|
|
218
217
|
|
|
219
218
|
const { code: localeCode } = currentLanguage || defaultLanguage;
|
|
220
219
|
const locale = LocaleObject.fromAnyCode(localeCode);
|
|
221
|
-
const shortestLocaleCode = getShortestLocaleCode(languages, locale);
|
|
222
220
|
|
|
223
221
|
// TODO: if no information given for current language, show boilerplate from default language
|
|
224
222
|
const companyInformation = getCompanyInformation(languages, locale);
|
|
@@ -226,15 +224,16 @@ export class PrezlyApi {
|
|
|
226
224
|
const algoliaSettings = getAlgoliaSettings(request);
|
|
227
225
|
|
|
228
226
|
return {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
newsroomContextProps: {
|
|
228
|
+
newsroom,
|
|
229
|
+
companyInformation,
|
|
230
|
+
categories,
|
|
231
|
+
languages,
|
|
232
|
+
localeCode,
|
|
233
|
+
themePreset,
|
|
234
|
+
algoliaSettings,
|
|
235
|
+
},
|
|
235
236
|
localeResolved: Boolean(currentLanguage),
|
|
236
|
-
themePreset,
|
|
237
|
-
algoliaSettings,
|
|
238
237
|
};
|
|
239
238
|
}
|
|
240
239
|
}
|
package/src/intl/locale.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Redirect } from 'next';
|
|
2
2
|
import { ParsedUrlQuery, stringify } from 'querystring';
|
|
3
3
|
|
|
4
|
-
import { BasePageProps } from '../types';
|
|
5
|
-
|
|
6
4
|
import { LocaleObject } from './localeObject';
|
|
7
5
|
|
|
8
6
|
export const DEFAULT_LOCALE = 'en';
|
|
@@ -76,12 +74,11 @@ export function getSupportedLocaleIsoCode(locale: LocaleObject): string {
|
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
export function getRedirectToCanonicalLocale(
|
|
79
|
-
|
|
77
|
+
shortestLocaleCode: string | false,
|
|
80
78
|
nextLocaleIsoCode: string | undefined,
|
|
81
79
|
redirectPath: string,
|
|
82
80
|
query?: ParsedUrlQuery,
|
|
83
81
|
): Redirect | undefined {
|
|
84
|
-
const { shortestLocaleCode } = basePageProps;
|
|
85
82
|
const shortestLocaleSlug = shortestLocaleCode
|
|
86
83
|
? LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
|
|
87
84
|
: shortestLocaleCode;
|
|
@@ -7,12 +7,12 @@ import type {
|
|
|
7
7
|
NewsroomLanguageSettings,
|
|
8
8
|
NewsroomThemePreset,
|
|
9
9
|
} from '@prezly/sdk';
|
|
10
|
-
import
|
|
10
|
+
import { createContext, FunctionComponent, useMemo } from 'react';
|
|
11
11
|
|
|
12
12
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
13
13
|
import { DEFAULT_LOCALE, LocaleObject } from '../intl';
|
|
14
14
|
|
|
15
|
-
export interface
|
|
15
|
+
export interface NewsroomContextType {
|
|
16
16
|
newsroom: Newsroom;
|
|
17
17
|
companyInformation: NewsroomCompanyInformation;
|
|
18
18
|
categories: Category[];
|
|
@@ -21,18 +21,17 @@ export interface INewsroomContext {
|
|
|
21
21
|
selectedStory?: ExtendedStory;
|
|
22
22
|
languages: NewsroomLanguageSettings[];
|
|
23
23
|
locale: LocaleObject;
|
|
24
|
-
hasError?: boolean;
|
|
25
24
|
themePreset: NewsroomThemePreset;
|
|
26
25
|
algoliaSettings: AlgoliaSettings;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
interface
|
|
28
|
+
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
30
29
|
localeCode: string;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
export const NewsroomContext = createContext<
|
|
32
|
+
export const NewsroomContext = createContext<NewsroomContextType | undefined>(undefined);
|
|
34
33
|
|
|
35
|
-
export const NewsroomContextProvider: FunctionComponent<
|
|
34
|
+
export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> = ({
|
|
36
35
|
categories,
|
|
37
36
|
contacts,
|
|
38
37
|
newsroom,
|
|
@@ -41,7 +40,6 @@ export const NewsroomContextProvider: FunctionComponent<Props> = ({
|
|
|
41
40
|
companyInformation,
|
|
42
41
|
languages,
|
|
43
42
|
localeCode,
|
|
44
|
-
hasError,
|
|
45
43
|
themePreset,
|
|
46
44
|
algoliaSettings,
|
|
47
45
|
children,
|
|
@@ -62,7 +60,6 @@ export const NewsroomContextProvider: FunctionComponent<Props> = ({
|
|
|
62
60
|
companyInformation,
|
|
63
61
|
languages,
|
|
64
62
|
locale,
|
|
65
|
-
hasError,
|
|
66
63
|
themePreset,
|
|
67
64
|
algoliaSettings,
|
|
68
65
|
}}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NewsroomContext, NewsroomContextType } from '../context';
|
|
4
4
|
|
|
5
5
|
export const useNewsroomContext = () => {
|
|
6
6
|
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
7
7
|
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
8
|
-
const newsroomContext:
|
|
8
|
+
const newsroomContext: NewsroomContextType | undefined = useContext(NewsroomContext);
|
|
9
9
|
if (!newsroomContext) {
|
|
10
10
|
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
11
11
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { NewsroomContext, NewsroomContextProvider } from './context';
|
|
1
|
+
export { NewsroomContext, NewsroomContextProvider, NewsroomContextProps } from './context';
|
|
2
2
|
export * from './hooks';
|
package/src/types.ts
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
// TODO: Re-arrange the types to make them isolated to respective libs where possible
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
Category,
|
|
5
|
-
CultureRef,
|
|
6
|
-
ExtendedStory,
|
|
7
|
-
ExtraStoryFields,
|
|
8
|
-
Newsroom,
|
|
9
|
-
NewsroomCompanyInformation,
|
|
10
|
-
NewsroomContact,
|
|
11
|
-
NewsroomLanguageSettings,
|
|
12
|
-
NewsroomThemePreset,
|
|
13
|
-
Story,
|
|
14
|
-
} from '@prezly/sdk';
|
|
2
|
+
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
15
3
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
categories: Category[];
|
|
20
|
-
languages: NewsroomLanguageSettings[];
|
|
21
|
-
localeCode: string;
|
|
22
|
-
/**
|
|
23
|
-
* `false` means it's the default locale
|
|
24
|
-
*/
|
|
25
|
-
shortestLocaleCode: string | false;
|
|
4
|
+
import { NewsroomContextProps } from './newsroom-context';
|
|
5
|
+
|
|
6
|
+
export interface ServerSidePageProps {
|
|
26
7
|
localeResolved: boolean;
|
|
27
|
-
themePreset: NewsroomThemePreset;
|
|
28
|
-
algoliaSettings: AlgoliaSettings;
|
|
29
|
-
translations?: Translations;
|
|
30
|
-
contacts?: NewsroomContact[];
|
|
31
|
-
isTrackingEnabled?: boolean;
|
|
32
|
-
selectedCategory?: Category;
|
|
33
|
-
selectedStory?: ExtendedStory;
|
|
34
8
|
}
|
|
9
|
+
|
|
10
|
+
export interface PageProps {
|
|
11
|
+
newsroomContextProps: NewsroomContextProps;
|
|
12
|
+
}
|
|
13
|
+
|
|
35
14
|
export interface AlgoliaCategoryRef {
|
|
36
15
|
id: number;
|
|
37
16
|
name: string;
|
|
@@ -46,5 +25,3 @@ export type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> &
|
|
|
46
25
|
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
47
26
|
categories: AlgoliaCategoryRef[];
|
|
48
27
|
};
|
|
49
|
-
|
|
50
|
-
export type Translations = Record<string, string>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { GetServerSidePropsContext } from 'next';
|
|
2
|
-
interface BasePagePropsOptions {
|
|
3
|
-
loadHomepageContacts?: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare function getBasePageProps(context: GetServerSidePropsContext, options?: BasePagePropsOptions): Promise<{
|
|
6
|
-
api: import("../data-fetching/api/PrezlyApi").PrezlyApi;
|
|
7
|
-
basePageProps: import("..").BasePageProps;
|
|
8
|
-
}>;
|
|
9
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBasePageProps.js","sourceRoot":"","sources":["../../src/adapter-nextjs/getBasePageProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAAgD;AAMhD,SAAsB,gBAAgB,CAClC,OAAkC,EAClC,OAAkC;IAAlC,wBAAA,EAAA,YAAkC;;;;;;oBAErB,OAAO,GAAa,OAAO,IAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;oBAEnC,GAAG,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,CAAC;oBACZ,qBAAM,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;oBAA3D,aAAa,GAAG,SAA2C;yBAE7D,OAAO,CAAC,oBAAoB,EAA5B,wBAA4B;oBAC5B,KAAA,aAAa,CAAA;oBAAY,qBAAM,GAAG,CAAC,mBAAmB,EAAE,EAAA;;oBAAxD,GAAc,QAAQ,GAAG,SAA+B,CAAC;;wBAG7D,sBAAO,EAAE,GAAG,KAAA,EAAE,aAAa,eAAA,EAAE,EAAC;;;;CACjC;AAdD,4CAcC"}
|