@prezly/theme-kit-nextjs 1.1.1 → 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 +167 -3
- 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/data-fetching/api/queries.js +2 -2
- package/build/data-fetching/api/queries.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 +7 -12
- package/build/newsroom-context/context.js +16 -24
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.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/hooks/useSelectedStory.d.ts +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/data-fetching/api/queries.ts +2 -2
- package/src/intl/locale.ts +1 -4
- package/src/newsroom-context/context.tsx +12 -15
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +2 -2
- package/src/newsroom-context/hooks/useNewsroomContext.ts +2 -2
- package/src/newsroom-context/index.ts +1 -1
- package/src/types.ts +9 -31
- package/build/adapter-nextjs/getBasePageProps.d.ts +0 -9
- package/build/adapter-nextjs/getBasePageProps.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# NextJS Prezly Theme Kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
This library is a collection of data-fetching functions, hooks and utility functions to abstract some of the under-the-hood logic used by Prezly newsrooms and help developers create themes with [Next.JS] much faster with little boilerplate required.
|
|
7
|
+
|
|
8
|
+
The package is built with [Typescript] on top of [Prezly SDK].
|
|
4
9
|
|
|
5
10
|
## Adding the library to your NextJS theme
|
|
6
11
|
|
|
@@ -12,8 +17,8 @@ npm install --save @prezly/theme-kit-nextjs
|
|
|
12
17
|
|
|
13
18
|
#### peerDependencies
|
|
14
19
|
|
|
15
|
-
This library is intended to be used with
|
|
16
|
-
If you're starting from scratch, use [
|
|
20
|
+
This library is intended to be used with [Next.JS] applications, so it requires `next`, `react` and `react-dom` to work. These should already be installed if you have an existing NextJS app.
|
|
21
|
+
If you're starting from scratch, use [create-next-app] to quick-start the project.
|
|
17
22
|
|
|
18
23
|
To keep things fresh, we require at least NextJS 12 and React 17.
|
|
19
24
|
|
|
@@ -23,6 +28,165 @@ npm install --save next react react-dom
|
|
|
23
28
|
npm install --save-dev @types/react @types/react-dom
|
|
24
29
|
```
|
|
25
30
|
|
|
31
|
+
### .env
|
|
32
|
+
|
|
33
|
+
Prezly themes use two ways of getting base environment variables:
|
|
34
|
+
- Getting variables straight from `.env` file
|
|
35
|
+
- Extracting variables from HTTP headers (when hosted on the Prezly infrastructure)
|
|
36
|
+
|
|
37
|
+
For local development, and for self-hosted themes, you can only use the former option. Add these two variables to your `.env` file:
|
|
38
|
+
```
|
|
39
|
+
PREZLY_ACCESS_TOKEN=your access token
|
|
40
|
+
PREZLY_NEWSROOM_UUID=your newsroom UUID
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If you don't have these credentials, you can use one of our [testing newsrooms credentials](https://github.com/prezly/theme-nextjs-starter#testingtoken).
|
|
44
|
+
|
|
45
|
+
### next.config.js
|
|
46
|
+
|
|
47
|
+
In a base setup, you don't have to make any changes to your config.
|
|
48
|
+
Depending on your use-case, you might need to make some additions to your base config.
|
|
49
|
+
|
|
50
|
+
#### Using next/image to display images served from Prezly
|
|
51
|
+
|
|
52
|
+
We provide `@prezly/uploadcare-image` package to conviniently display images inside Prezly content, and this is the recommended way to display images in your theme.
|
|
53
|
+
However, if you need to use the default `next/image` component, you will need to add our CDN url to image domains settings:
|
|
54
|
+
```js
|
|
55
|
+
module.exports = {
|
|
56
|
+
/* ...your next config... */
|
|
57
|
+
images: {
|
|
58
|
+
domains: ['cdn.uc.assets.prezly.com'],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Multi-language support
|
|
64
|
+
|
|
65
|
+
If you want to support multi-language in your theme, you'll need to make additional changes to the file:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
const { DUMMY_DEFAULT_LOCALE } = require('@prezly/theme-kit-nextjs');
|
|
69
|
+
const locales = require('@prezly/theme-kit-nextjs/build/intl/localeConfig');
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
/* ...your next config... */
|
|
73
|
+
|
|
74
|
+
i18n: {
|
|
75
|
+
// These are all the locales you want to support in
|
|
76
|
+
// your application
|
|
77
|
+
locales: [...locales, DUMMY_DEFAULT_LOCALE],
|
|
78
|
+
// This is the default locale you want to be used when visiting
|
|
79
|
+
// a non-locale prefixed path e.g. `/media`
|
|
80
|
+
// We use Pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
|
|
81
|
+
defaultLocale: DUMMY_DEFAULT_LOCALE,
|
|
82
|
+
// Default locale detection is disabled, since the locales would be determined by Prezly API
|
|
83
|
+
localeDetection: false,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### pages/_app.tsx
|
|
89
|
+
|
|
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
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { NewsroomContextProvider, PageProps } from '@prezly/theme-kit-nextjs';
|
|
94
|
+
import type { AppProps } from 'next/app';
|
|
95
|
+
|
|
96
|
+
type AnyPageProps = Record<string, any>;
|
|
97
|
+
|
|
98
|
+
function App({ Component, pageProps }: AppProps<AnyPageProps>) {
|
|
99
|
+
const { newsroomContextProps, ...customPageProps } = pageProps as PageProps & AnyPageProps;
|
|
100
|
+
|
|
101
|
+
// eslint-disable react/jsx-props-no-spreading
|
|
102
|
+
return (
|
|
103
|
+
<NewsroomContextProvider {...newsroomContextProps}>
|
|
104
|
+
<Component {...customPageProps} />
|
|
105
|
+
</NewsroomContextProvider>
|
|
106
|
+
);
|
|
107
|
+
// eslint-enable react/jsx-props-no-spreading
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default App;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Page files (Server-side rendering)
|
|
114
|
+
|
|
115
|
+
Every page requires a bit of boilerplate code to set up.
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { getNewsroomServerSideProps, processRequest } from '@prezly/theme-kit-nextjs';
|
|
119
|
+
import type { GetServerSideProps } from 'next';
|
|
120
|
+
import type { FunctionComponent } from 'react';
|
|
121
|
+
|
|
122
|
+
interface Props {
|
|
123
|
+
myProp: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const Page: FunctionComponent<Props> = ({ myProp }) => <p>{myProp}</p>;
|
|
127
|
+
|
|
128
|
+
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
|
|
129
|
+
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
130
|
+
|
|
131
|
+
/* Your logic to get additional props for this page */
|
|
132
|
+
|
|
133
|
+
return processRequest(
|
|
134
|
+
context,
|
|
135
|
+
{
|
|
136
|
+
...serverSideProps,
|
|
137
|
+
myProp: 'My Custom Prop',
|
|
138
|
+
},
|
|
139
|
+
'/',
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export default Page;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Page display component**
|
|
147
|
+
```tsx
|
|
148
|
+
const Page: FunctionComponent<Props> = ({ myProp }) => <p>{myProp}</p>;
|
|
149
|
+
```
|
|
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.
|
|
151
|
+
|
|
152
|
+
**Data fetching**
|
|
153
|
+
```ts
|
|
154
|
+
const { api, serverSideProps } = await getNewsroomServerSideProps(context);
|
|
155
|
+
```
|
|
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.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
return processRequest(
|
|
160
|
+
context,
|
|
161
|
+
{
|
|
162
|
+
...serverSideProps,
|
|
163
|
+
myProp: 'My Custom Prop',
|
|
164
|
+
},
|
|
165
|
+
'/',
|
|
166
|
+
);
|
|
167
|
+
```
|
|
168
|
+
This function returns the combined base props and your additional props, with some extra logic in between to handle locale URLs.
|
|
169
|
+
|
|
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.
|
|
171
|
+
|
|
172
|
+
----
|
|
173
|
+
|
|
174
|
+
## What's next
|
|
175
|
+
|
|
176
|
+
This kit is just a collection of building blocks, so it doesn't really force any page structure or guidelines on how to render the content.
|
|
177
|
+
You can learn more on how this kit can be used by checking the code of Prezly's themes:
|
|
178
|
+
- [Theme Starter](https://github.com/prezly/theme-nextjs-starter) - this is a bare-bones application created to demonstrate how to display the fetched content and recommended page structure
|
|
179
|
+
- [Bea Theme](https://github.com/prezly/theme-nextjs-bea) - this is our new fully-fledged theme available to all Prezly customers. It has lots of stuff on top, both in styling and in data logic.
|
|
180
|
+
|
|
181
|
+
You can also learn more about Prezly API by checking out typings in [Prezly SDK] package, and referring to the [Prezly API Docs]
|
|
182
|
+
|
|
26
183
|
----
|
|
27
184
|
|
|
28
185
|
Brought to you by [Prezly](https://www.prezly.com/?utm_source=github&utm_campaign=@prezly/theme-kit-nextjs).
|
|
186
|
+
|
|
187
|
+
[create-next-app]: https://nextjs.org/docs/api-reference/create-next-app
|
|
188
|
+
[Next.JS]: https://nextjs.org
|
|
189
|
+
[Prezly SDK]: https://www.npmjs.com/package/@prezly/sdk
|
|
190
|
+
[Prezly API Docs]: https://developers.prezly.com/docs/api
|
|
191
|
+
[Typescript]: https://www.typescriptlang.org
|
|
192
|
+
[Prezly Content React Renderer]: https://www.npmjs.com/package/@prezly/content-renderer-react-js
|
|
@@ -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.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAMqB;AAGrB,mCAA0C;AAE1C,0CAAiD;AACjD,gEAA+D;AAE/D,yCAKqB;AACrB,qCAMmB;AAEnB,IAAM,kBAAkB,GAAc,MAAM,CAAC;AAiB7C;IAKI,mBAAY,WAAmB,EAAE,YAA8B;QAA/D,iBAQC;;QA2HD,kBAAa,GAA8C,UAAC,OAAO;YAC/D,OAAA,KAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAAhC,CAAgC,CAAC;QAnIjC,IAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,qBAAqB,mCAAI,SAAS,CAAC;QAC/D,IAAI,CAAC,GAAG,GAAG,IAAI,aAAS,CAAC;YACrB,WAAW,aAAA;YACX,OAAO,S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CACH,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"}
|
|
@@ -27,8 +27,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.getContactsQuery = exports.getGalleriesQuery = exports.getSortByPublishedDate = exports.getStoriesQuery = exports.getSlugQuery = void 0;
|
|
29
29
|
var publishedAndAccessible = [
|
|
30
|
-
{ lifecycle_status: { $in: ['published'] } },
|
|
31
|
-
{ visibility: { $in: ['public', 'private'] } },
|
|
30
|
+
{ lifecycle_status: { $in: ['published', 'embargo'] } },
|
|
31
|
+
{ visibility: { $in: ['public', 'private', 'embargo'] } },
|
|
32
32
|
];
|
|
33
33
|
var publishedAndPublic = [
|
|
34
34
|
{ lifecycle_status: { $in: ['published'] } },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/data-fetching/api/queries.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,sBAAsB,GAAG;IAC3B,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/data-fetching/api/queries.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,sBAAsB,GAAG;IAC3B,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE;IACvD,E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,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc;AAAnD,CAAmD,CAAC;AAD3C,QAAA,sBAAsB,0BACqB;AAEjD,IAAM,iBAAiB,GAAG,cAAM,OAAA,CAAC;IACpC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;CACvE,CAAC,EAFqC,CAErC,CAAC;AAFU,QAAA,iBAAiB,qBAE3B;AAEI,IAAM,gBAAgB,GAAG,cAAM,OAAA,CAAC;IACnC,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;CACzC,CAAC,EAFoC,CAEpC,CAAC;AAFU,QAAA,gBAAgB,oBAE1B"}
|
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,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,OAAO;CACV,CAAC;AAEF,SAAgB,yBAAyB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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,26 +1,21 @@
|
|
|
1
|
-
import type { Category, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset
|
|
2
|
-
import
|
|
1
|
+
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset } from '@prezly/sdk';
|
|
2
|
+
import { FunctionComponent } from 'react';
|
|
3
3
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
4
|
import { LocaleObject } from '../intl';
|
|
5
|
-
|
|
6
|
-
export interface INewsroomContext {
|
|
5
|
+
export interface NewsroomContextType {
|
|
7
6
|
newsroom: Newsroom;
|
|
8
7
|
companyInformation: NewsroomCompanyInformation;
|
|
9
8
|
categories: Category[];
|
|
10
9
|
contacts?: NewsroomContact[];
|
|
11
10
|
selectedCategory?: Category;
|
|
12
|
-
selectedStory?:
|
|
11
|
+
selectedStory?: ExtendedStory;
|
|
13
12
|
languages: NewsroomLanguageSettings[];
|
|
14
13
|
locale: LocaleObject;
|
|
15
|
-
hasError?: boolean;
|
|
16
14
|
themePreset: NewsroomThemePreset;
|
|
17
15
|
algoliaSettings: AlgoliaSettings;
|
|
18
16
|
}
|
|
19
|
-
interface
|
|
20
|
-
isTrackingEnabled?: boolean;
|
|
17
|
+
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
21
18
|
localeCode: string;
|
|
22
|
-
translations?: Translations;
|
|
23
19
|
}
|
|
24
|
-
export declare const NewsroomContext:
|
|
25
|
-
export declare const NewsroomContextProvider: FunctionComponent<
|
|
26
|
-
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,
|
|
28
|
-
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode ||
|
|
29
|
-
return (
|
|
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;
|
|
21
|
+
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AACxC,+BAAoC;AAEpC,qDAAgF;AAGhF,6DAA4D;AAC5D,uDAAsD;AAEtD,sFAAsF;AACtF,SAAS,iBAAiB,CACtB,MAAoB,EACpB,IAAY,EACZ,gBAA2B,EAC3B,
|
|
1
|
+
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AACxC,+BAAo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C,MAAM,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAC5C,CAAC;AACN,CAAC;AAVD,oDAUC"}
|
|
@@ -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 +1 @@
|
|
|
1
|
-
export declare const useSelectedStory: () => import("@prezly/sdk").
|
|
1
|
+
export declare const useSelectedStory: () => import("@prezly/sdk").ExtendedStory | undefined;
|
|
@@ -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?: Story;
|
|
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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const publishedAndAccessible = [
|
|
2
|
-
{ lifecycle_status: { $in: ['published'] } },
|
|
3
|
-
{ visibility: { $in: ['public', 'private'] } },
|
|
2
|
+
{ lifecycle_status: { $in: ['published', 'embargo'] } },
|
|
3
|
+
{ visibility: { $in: ['public', 'private', 'embargo'] } },
|
|
4
4
|
];
|
|
5
5
|
|
|
6
6
|
const publishedAndPublic = [
|
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;
|
|
@@ -1,41 +1,37 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Category,
|
|
3
|
+
ExtendedStory,
|
|
3
4
|
Newsroom,
|
|
4
5
|
NewsroomCompanyInformation,
|
|
5
6
|
NewsroomContact,
|
|
6
7
|
NewsroomLanguageSettings,
|
|
7
8
|
NewsroomThemePreset,
|
|
8
|
-
Story,
|
|
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
|
-
import { LocaleObject } from '../intl';
|
|
14
|
-
import { Translations } from '../types';
|
|
13
|
+
import { DEFAULT_LOCALE, LocaleObject } from '../intl';
|
|
15
14
|
|
|
16
|
-
export interface
|
|
15
|
+
export interface NewsroomContextType {
|
|
17
16
|
newsroom: Newsroom;
|
|
18
17
|
companyInformation: NewsroomCompanyInformation;
|
|
19
18
|
categories: Category[];
|
|
20
19
|
contacts?: NewsroomContact[];
|
|
21
20
|
selectedCategory?: Category;
|
|
22
|
-
selectedStory?:
|
|
21
|
+
selectedStory?: ExtendedStory;
|
|
23
22
|
languages: NewsroomLanguageSettings[];
|
|
24
23
|
locale: LocaleObject;
|
|
25
|
-
hasError?: boolean;
|
|
26
24
|
themePreset: NewsroomThemePreset;
|
|
27
25
|
algoliaSettings: AlgoliaSettings;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
interface
|
|
31
|
-
isTrackingEnabled?: boolean;
|
|
28
|
+
export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'> {
|
|
32
29
|
localeCode: string;
|
|
33
|
-
translations?: Translations;
|
|
34
30
|
}
|
|
35
31
|
|
|
36
|
-
export const NewsroomContext = createContext<
|
|
32
|
+
export const NewsroomContext = createContext<NewsroomContextType | undefined>(undefined);
|
|
37
33
|
|
|
38
|
-
export const NewsroomContextProvider: FunctionComponent<
|
|
34
|
+
export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> = ({
|
|
39
35
|
categories,
|
|
40
36
|
contacts,
|
|
41
37
|
newsroom,
|
|
@@ -44,12 +40,14 @@ export const NewsroomContextProvider: FunctionComponent<Props> = ({
|
|
|
44
40
|
companyInformation,
|
|
45
41
|
languages,
|
|
46
42
|
localeCode,
|
|
47
|
-
hasError,
|
|
48
43
|
themePreset,
|
|
49
44
|
algoliaSettings,
|
|
50
45
|
children,
|
|
51
46
|
}) => {
|
|
52
|
-
const locale = useMemo(
|
|
47
|
+
const locale = useMemo(
|
|
48
|
+
() => LocaleObject.fromAnyCode(localeCode || DEFAULT_LOCALE),
|
|
49
|
+
[localeCode],
|
|
50
|
+
);
|
|
53
51
|
|
|
54
52
|
return (
|
|
55
53
|
<NewsroomContext.Provider
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import type { Category,
|
|
1
|
+
import type { Category, ExtendedStory } from '@prezly/sdk';
|
|
2
2
|
import { useRouter } from 'next/router';
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
4
|
|
|
@@ -13,7 +13,7 @@ function getTranslationUrl(
|
|
|
13
13
|
locale: LocaleObject,
|
|
14
14
|
path: string,
|
|
15
15
|
selectedCategory?: Category,
|
|
16
|
-
selectedStory?:
|
|
16
|
+
selectedStory?: ExtendedStory,
|
|
17
17
|
noFallback?: boolean,
|
|
18
18
|
) {
|
|
19
19
|
if (selectedCategory) {
|
|
@@ -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,36 +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
|
-
ExtraStoryFields,
|
|
7
|
-
Newsroom,
|
|
8
|
-
NewsroomCompanyInformation,
|
|
9
|
-
NewsroomContact,
|
|
10
|
-
NewsroomLanguageSettings,
|
|
11
|
-
NewsroomThemePreset,
|
|
12
|
-
Story,
|
|
13
|
-
} from '@prezly/sdk';
|
|
2
|
+
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
14
3
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
categories: Category[];
|
|
19
|
-
languages: NewsroomLanguageSettings[];
|
|
20
|
-
localeCode: string;
|
|
21
|
-
/**
|
|
22
|
-
* `false` means it's the default locale
|
|
23
|
-
*/
|
|
24
|
-
shortestLocaleCode: string | false;
|
|
4
|
+
import { NewsroomContextProps } from './newsroom-context';
|
|
5
|
+
|
|
6
|
+
export interface ServerSidePageProps {
|
|
25
7
|
localeResolved: boolean;
|
|
26
|
-
themePreset: NewsroomThemePreset;
|
|
27
|
-
algoliaSettings: AlgoliaSettings;
|
|
28
|
-
translations?: Translations;
|
|
29
|
-
contacts?: NewsroomContact[];
|
|
30
|
-
isTrackingEnabled?: boolean;
|
|
31
|
-
selectedCategory?: Category;
|
|
32
|
-
selectedStory?: Story;
|
|
33
8
|
}
|
|
9
|
+
|
|
10
|
+
export interface PageProps {
|
|
11
|
+
newsroomContextProps: NewsroomContextProps;
|
|
12
|
+
}
|
|
13
|
+
|
|
34
14
|
export interface AlgoliaCategoryRef {
|
|
35
15
|
id: number;
|
|
36
16
|
name: string;
|
|
@@ -45,5 +25,3 @@ export type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> &
|
|
|
45
25
|
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
46
26
|
categories: AlgoliaCategoryRef[];
|
|
47
27
|
};
|
|
48
|
-
|
|
49
|
-
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"}
|