@prezly/theme-kit-nextjs 1.2.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +2 -0
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/processRequest.d.ts +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +3 -2
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.d.ts +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +3 -3
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/queries.d.ts +5 -5
- package/build/data-fetching/api/queries.js +22 -16
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/getLocalizedCategoryData.d.ts +2 -2
- package/build/data-fetching/getNewsroomLogoUrl.js +3 -2
- package/build/data-fetching/getNewsroomLogoUrl.js.map +1 -1
- package/build/data-fetching/getPrivacyPortalUrl.d.ts +2 -2
- package/build/data-fetching/getPrivacyPortalUrl.js.map +1 -1
- package/build/data-fetching/getStoryPublicationDate.d.ts +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.d.ts +2 -2
- package/build/data-fetching/lib/getAlgoliaSettings.js +3 -3
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.d.ts +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +7 -7
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/intl/lang.d.ts +1 -1
- package/build/intl/locale.d.ts +1 -1
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.js +1 -0
- package/build/intl/localeConfig.js.map +1 -1
- package/build/newsroom-context/context.d.ts +2 -2
- package/build/newsroom-context/context.js +2 -2
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +2 -2
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.d.ts +1 -1
- package/build/newsroom-context/hooks/useCategories.js +2 -2
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.d.ts +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +2 -2
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.d.ts +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.js +2 -2
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +2 -2
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.d.ts +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.js +2 -2
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +1 -1
- package/build/newsroom-context/hooks/useLanguages.d.ts +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +2 -2
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.d.ts +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +2 -2
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.d.ts +2 -2
- package/build/newsroom-context/hooks/useNewsroomContext.js +2 -2
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/types.d.ts +1 -1
- package/package.json +2 -10
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +3 -1
- package/src/adapter-nextjs/processRequest.ts +1 -1
- package/src/data-fetching/api/PrezlyApi.ts +3 -2
- package/src/data-fetching/api/getPrezlyApi.ts +3 -3
- package/src/data-fetching/api/queries.ts +25 -18
- package/src/data-fetching/getLocalizedCategoryData.ts +2 -2
- package/src/data-fetching/getNewsroomLogoUrl.ts +3 -4
- package/src/data-fetching/getPrivacyPortalUrl.ts +5 -2
- package/src/data-fetching/getStoryPublicationDate.tsx +1 -1
- package/src/data-fetching/lib/getAlgoliaSettings.ts +4 -4
- package/src/data-fetching/lib/getEnvVariables.ts +7 -7
- package/src/intl/lang.ts +1 -1
- package/src/intl/locale.ts +2 -1
- package/src/intl/localeConfig.js +1 -0
- package/src/newsroom-context/context.tsx +5 -4
- package/src/newsroom-context/hooks/useAlgoliaSettings.ts +2 -2
- package/src/newsroom-context/hooks/useCategories.ts +2 -2
- package/src/newsroom-context/hooks/useCompanyInformation.ts +2 -2
- package/src/newsroom-context/hooks/useCurrentCategory.ts +2 -2
- package/src/newsroom-context/hooks/useCurrentLocale.ts +2 -2
- package/src/newsroom-context/hooks/useCurrentStory.ts +2 -2
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +1 -1
- package/src/newsroom-context/hooks/useLanguages.ts +2 -2
- package/src/newsroom-context/hooks/useNewsroom.ts +2 -2
- package/src/newsroom-context/hooks/useNewsroomContext.ts +4 -3
- package/src/types.ts +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLanguages = void 0;
|
|
4
4
|
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
-
|
|
5
|
+
function useLanguages() {
|
|
6
6
|
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.languages;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
exports.useLanguages = useLanguages;
|
|
10
10
|
//# sourceMappingURL=useLanguages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useLanguages.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;
|
|
1
|
+
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useLanguages.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAE1D,SAAgB,YAAY;IACxB,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,SAAS,CAAC;AAC7B,CAAC;AAJD,oCAIC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function useNewsroom(): import("@prezly/sdk").Newsroom;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useNewsroom = void 0;
|
|
4
4
|
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
-
|
|
5
|
+
function useNewsroom() {
|
|
6
6
|
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.newsroom;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
exports.useNewsroom = useNewsroom;
|
|
10
10
|
//# sourceMappingURL=useNewsroom.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNewsroom.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroom.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;
|
|
1
|
+
{"version":3,"file":"useNewsroom.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroom.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAE1D,SAAgB,WAAW;IACvB,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC5B,CAAC;AAJD,kCAIC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NewsroomContextType } from '../context';
|
|
2
|
-
export declare
|
|
1
|
+
import type { NewsroomContextType } from '../context';
|
|
2
|
+
export declare function useNewsroomContext(): NewsroomContextType;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useNewsroomContext = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
5
|
var context_1 = require("../context");
|
|
6
|
-
|
|
6
|
+
function useNewsroomContext() {
|
|
7
7
|
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
8
8
|
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
9
9
|
var newsroomContext = (0, react_1.useContext)(context_1.NewsroomContext);
|
|
@@ -11,6 +11,6 @@ var useNewsroomContext = function () {
|
|
|
11
11
|
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
12
12
|
}
|
|
13
13
|
return newsroomContext;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
exports.useNewsroomContext = useNewsroomContext;
|
|
16
16
|
//# sourceMappingURL=useNewsroomContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;
|
|
1
|
+
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAGnC,sCAA6C;AAE7C,SAAgB,kBAAkB;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;AATD,gDASC"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
2
|
-
import { NewsroomContextProps } from './newsroom-context';
|
|
2
|
+
import type { NewsroomContextProps } from './newsroom-context';
|
|
3
3
|
export interface ServerSidePageProps {
|
|
4
4
|
localeResolved: boolean;
|
|
5
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/theme-kit-nextjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.3",
|
|
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",
|
|
@@ -52,20 +52,12 @@
|
|
|
52
52
|
"parse-data-url": "^4.0.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@prezly/eslint-config": "^4.0.0",
|
|
55
56
|
"@types/node": "^17.0.13",
|
|
56
57
|
"@types/parse-data-url": "^3.0.0",
|
|
57
58
|
"@types/react": "^17.0.38",
|
|
58
59
|
"@types/react-dom": "^17.0.11",
|
|
59
60
|
"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",
|
|
69
61
|
"np": "^7.6.0",
|
|
70
62
|
"prettier": "^2.5.1",
|
|
71
63
|
"rimraf": "^3.0.2",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { Story } from '@prezly/sdk';
|
|
1
2
|
import type { GetServerSidePropsContext } from 'next';
|
|
2
3
|
|
|
3
4
|
import { getPrezlyApi } from '../data-fetching';
|
|
4
5
|
|
|
5
6
|
interface Options {
|
|
6
7
|
loadHomepageContacts?: boolean;
|
|
8
|
+
story?: Story;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export async function getNewsroomServerSideProps(
|
|
@@ -13,7 +15,7 @@ export async function getNewsroomServerSideProps(
|
|
|
13
15
|
const { req: request, locale } = context;
|
|
14
16
|
|
|
15
17
|
const api = getPrezlyApi(request);
|
|
16
|
-
const serverSideProps = await api.getNewsroomServerSideProps(request, locale);
|
|
18
|
+
const serverSideProps = await api.getNewsroomServerSideProps(request, locale, options.story);
|
|
17
19
|
|
|
18
20
|
if (options.loadHomepageContacts) {
|
|
19
21
|
serverSideProps.newsroomContextProps.contacts = await api.getNewsroomContacts();
|
|
@@ -2,7 +2,7 @@ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
|
2
2
|
|
|
3
3
|
import { getShortestLocaleCode } from '../data-fetching';
|
|
4
4
|
import { getRedirectToCanonicalLocale, LocaleObject } from '../intl';
|
|
5
|
-
import { PageProps, ServerSidePageProps } from '../types';
|
|
5
|
+
import type { PageProps, ServerSidePageProps } from '../types';
|
|
6
6
|
|
|
7
7
|
export function processRequest<Props>(
|
|
8
8
|
context: GetServerSidePropsContext,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type {
|
|
2
2
|
Category,
|
|
3
3
|
ExtraStoryFields,
|
|
4
4
|
Newsroom,
|
|
5
5
|
NewsroomLanguageSettings,
|
|
6
6
|
Story,
|
|
7
7
|
} from '@prezly/sdk';
|
|
8
|
+
import PrezlySDK from '@prezly/sdk';
|
|
8
9
|
import type { IncomingMessage } from 'http';
|
|
9
10
|
|
|
10
11
|
import { LocaleObject } from '../../intl';
|
|
11
|
-
import { PageProps, ServerSidePageProps } from '../../types';
|
|
12
|
+
import type { PageProps, ServerSidePageProps } from '../../types';
|
|
12
13
|
import { DEFAULT_PAGE_SIZE } from '../constants';
|
|
13
14
|
import { getAlgoliaSettings } from '../lib/getAlgoliaSettings';
|
|
14
15
|
|
|
@@ -4,8 +4,8 @@ import { getEnvVariables } from '../lib/getEnvVariables';
|
|
|
4
4
|
|
|
5
5
|
import { PrezlyApi } from './PrezlyApi';
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
if (
|
|
7
|
+
export function getPrezlyApi(req?: IncomingMessage): PrezlyApi {
|
|
8
|
+
if (typeof window !== 'undefined') {
|
|
9
9
|
throw new Error('"getPrezlyApi" should only be used on back-end side.');
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -21,4 +21,4 @@ export const getPrezlyApi = (req?: IncomingMessage): PrezlyApi => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID);
|
|
24
|
-
}
|
|
24
|
+
}
|
|
@@ -8,15 +8,17 @@ const publishedAndPublic = [
|
|
|
8
8
|
{ visibility: { $in: ['public'] } },
|
|
9
9
|
];
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
export function getSlugQuery(newsroomUuid: string, slug: string) {
|
|
12
|
+
return {
|
|
13
|
+
$and: [
|
|
14
|
+
{ 'newsroom.uuid': { $in: [newsroomUuid] } },
|
|
15
|
+
{ slug: { $eq: slug } },
|
|
16
|
+
...publishedAndAccessible,
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getStoriesQuery(newsroomUuid: string, categoryId?: number, localeCode?: string) {
|
|
20
22
|
const query: any = {
|
|
21
23
|
$and: [...publishedAndPublic, { 'newsroom.uuid': { $in: [newsroomUuid] } }],
|
|
22
24
|
};
|
|
@@ -30,15 +32,20 @@ export const getStoriesQuery = (newsroomUuid: string, categoryId?: number, local
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
return query;
|
|
33
|
-
}
|
|
35
|
+
}
|
|
34
36
|
|
|
35
|
-
export
|
|
36
|
-
order === 'desc' ? '-published_at' : 'published_at';
|
|
37
|
+
export function getSortByPublishedDate(order: 'asc' | 'desc') {
|
|
38
|
+
return order === 'desc' ? '-published_at' : 'published_at';
|
|
39
|
+
}
|
|
37
40
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
+
export function getGalleriesQuery() {
|
|
42
|
+
return {
|
|
43
|
+
$and: [{ status: { $eq: 'public' } }, { images_number: { $gt: 0 } }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
41
46
|
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
}
|
|
47
|
+
export function getContactsQuery() {
|
|
48
|
+
return {
|
|
49
|
+
$and: [{ is_featured: { $eq: true } }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Category } from '@prezly/sdk';
|
|
2
2
|
|
|
3
|
-
import { LocaleObject } from '../intl';
|
|
4
|
-
import { AlgoliaCategoryRef } from '../types';
|
|
3
|
+
import type { LocaleObject } from '../intl';
|
|
4
|
+
import type { AlgoliaCategoryRef } from '../types';
|
|
5
5
|
|
|
6
6
|
function isAlgoliaCategory(
|
|
7
7
|
category: Category | AlgoliaCategoryRef,
|
|
@@ -11,10 +11,9 @@ export function getNewsroomLogoUrl(newsroom: Newsroom): string {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function getNewsroomFaviconUrl(newsroom: Newsroom, previewSize = 400): string {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)}-/preview/${previewSize}x${previewSize}/-/quality/best/`;
|
|
14
|
+
const image = newsroom.icon || newsroom.square_logo;
|
|
15
|
+
if (image) {
|
|
16
|
+
return `${getAssetsUrl(image.uuid)}-/preview/${previewSize}x${previewSize}/-/quality/best/`;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
return '';
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Newsroom } from '@prezly/sdk';
|
|
2
2
|
|
|
3
|
-
import { LocaleObject } from '../intl';
|
|
3
|
+
import type { LocaleObject } from '../intl';
|
|
4
4
|
|
|
5
|
-
type PrivacyPortalUrlOptions = {
|
|
5
|
+
type PrivacyPortalUrlOptions = {
|
|
6
|
+
email?: string;
|
|
7
|
+
action?: 'data-request' | 'subscribe' | 'unsubscribe';
|
|
8
|
+
};
|
|
6
9
|
|
|
7
10
|
export function getPrivacyPortalUrl(
|
|
8
11
|
newsroom: Newsroom,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'http';
|
|
2
2
|
|
|
3
|
-
import { AlgoliaSettings } from '../types';
|
|
3
|
+
import type { AlgoliaSettings } from '../types';
|
|
4
4
|
|
|
5
5
|
import { getEnvVariables } from './getEnvVariables';
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
if (
|
|
7
|
+
export function getAlgoliaSettings(req?: IncomingMessage): AlgoliaSettings {
|
|
8
|
+
if (typeof window !== 'undefined') {
|
|
9
9
|
throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -26,4 +26,4 @@ export const getAlgoliaSettings = (req?: IncomingMessage): AlgoliaSettings => {
|
|
|
26
26
|
ALGOLIA_APP_ID,
|
|
27
27
|
ALGOLIA_INDEX,
|
|
28
28
|
};
|
|
29
|
-
}
|
|
29
|
+
}
|
|
@@ -3,7 +3,7 @@ import parseDataUrl from 'parse-data-url';
|
|
|
3
3
|
|
|
4
4
|
import type { PrezlyEnv } from '../types';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function decodeJson(json: string): Record<string, any> {
|
|
7
7
|
try {
|
|
8
8
|
const decoded = JSON.parse(json);
|
|
9
9
|
if (decoded && typeof decoded === 'object') {
|
|
@@ -13,9 +13,9 @@ const decodeJson = (json: string): Record<string, any> => {
|
|
|
13
13
|
// passthru
|
|
14
14
|
}
|
|
15
15
|
return {};
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
function decodeHttpEnv(header: string): Record<string, any> {
|
|
19
19
|
if (header.startsWith('data:')) {
|
|
20
20
|
const parsed = parseDataUrl(header);
|
|
21
21
|
if (parsed && parsed.contentType === 'application/json') {
|
|
@@ -25,10 +25,10 @@ const decodeHttpEnv = (header: string): Record<string, any> => {
|
|
|
25
25
|
return {}; // unsupported data-uri
|
|
26
26
|
}
|
|
27
27
|
return decodeJson(header);
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
export
|
|
31
|
-
if (
|
|
30
|
+
export function getEnvVariables(req?: IncomingMessage): PrezlyEnv {
|
|
31
|
+
if (typeof window !== 'undefined') {
|
|
32
32
|
throw new Error('"getEnvVariables" should only be used on back-end side.');
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -41,4 +41,4 @@ export const getEnvVariables = (req?: IncomingMessage): PrezlyEnv => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
return { ...process.env };
|
|
44
|
-
}
|
|
44
|
+
}
|
package/src/intl/lang.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CultureRef, NewsroomLanguageSettings } from '@prezly/sdk';
|
|
1
|
+
import type { CultureRef, NewsroomLanguageSettings } from '@prezly/sdk';
|
|
2
2
|
|
|
3
3
|
function isOnlyCulture(culture: CultureRef, languages: NewsroomLanguageSettings[]): boolean {
|
|
4
4
|
const numberOfLanguages = languages.filter(
|
package/src/intl/locale.ts
CHANGED
package/src/intl/localeConfig.js
CHANGED
|
@@ -7,7 +7,8 @@ import type {
|
|
|
7
7
|
NewsroomLanguageSettings,
|
|
8
8
|
NewsroomThemePreset,
|
|
9
9
|
} from '@prezly/sdk';
|
|
10
|
-
import {
|
|
10
|
+
import type { PropsWithChildren } from 'react';
|
|
11
|
+
import { createContext, useMemo } from 'react';
|
|
11
12
|
|
|
12
13
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
13
14
|
import { DEFAULT_LOCALE, LocaleObject } from '../intl';
|
|
@@ -31,7 +32,7 @@ export interface NewsroomContextProps extends Omit<NewsroomContextType, 'locale'
|
|
|
31
32
|
|
|
32
33
|
export const NewsroomContext = createContext<NewsroomContextType | undefined>(undefined);
|
|
33
34
|
|
|
34
|
-
export
|
|
35
|
+
export function NewsroomContextProvider({
|
|
35
36
|
categories,
|
|
36
37
|
contacts,
|
|
37
38
|
newsroom,
|
|
@@ -43,7 +44,7 @@ export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> =
|
|
|
43
44
|
themePreset,
|
|
44
45
|
algoliaSettings,
|
|
45
46
|
children,
|
|
46
|
-
})
|
|
47
|
+
}: PropsWithChildren<NewsroomContextProps>) {
|
|
47
48
|
const locale = useMemo(
|
|
48
49
|
() => LocaleObject.fromAnyCode(localeCode || DEFAULT_LOCALE),
|
|
49
50
|
[localeCode],
|
|
@@ -67,4 +68,4 @@ export const NewsroomContextProvider: FunctionComponent<NewsroomContextProps> =
|
|
|
67
68
|
{children}
|
|
68
69
|
</NewsroomContext.Provider>
|
|
69
70
|
);
|
|
70
|
-
}
|
|
71
|
+
}
|
|
@@ -3,7 +3,7 @@ import { useRouter } from 'next/router';
|
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
4
|
|
|
5
5
|
import { getCategoryHasTranslation, getCategoryUrl } from '../../data-fetching';
|
|
6
|
-
import { LocaleObject } from '../../intl';
|
|
6
|
+
import type { LocaleObject } from '../../intl';
|
|
7
7
|
|
|
8
8
|
import { useCurrentCategory } from './useCurrentCategory';
|
|
9
9
|
import { useCurrentStory } from './useCurrentStory';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { NewsroomContextType } from '../context';
|
|
4
|
+
import { NewsroomContext } from '../context';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export function useNewsroomContext() {
|
|
6
7
|
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
7
8
|
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
8
9
|
const newsroomContext: NewsroomContextType | undefined = useContext(NewsroomContext);
|
|
@@ -11,4 +12,4 @@ export const useNewsroomContext = () => {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
return newsroomContext;
|
|
14
|
-
}
|
|
15
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TODO: Re-arrange the types to make them isolated to respective libs where possible
|
|
2
2
|
import type { CultureRef, ExtraStoryFields, Story } from '@prezly/sdk';
|
|
3
3
|
|
|
4
|
-
import { NewsroomContextProps } from './newsroom-context';
|
|
4
|
+
import type { NewsroomContextProps } from './newsroom-context';
|
|
5
5
|
|
|
6
6
|
export interface ServerSidePageProps {
|
|
7
7
|
localeResolved: boolean;
|