@prezly/theme-kit-nextjs 1.0.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/LICENSE +21 -0
- package/README.md +28 -0
- package/build/adapter-nextjs/getBasePageProps.d.ts +9 -0
- package/build/adapter-nextjs/getBasePageProps.js +11 -0
- package/build/adapter-nextjs/getBasePageProps.js.map +1 -0
- package/build/adapter-nextjs/index.d.ts +2 -0
- package/build/adapter-nextjs/index.js +3 -0
- package/build/adapter-nextjs/index.js.map +1 -0
- package/build/adapter-nextjs/processRequest.d.ts +3 -0
- package/build/adapter-nextjs/processRequest.js +20 -0
- package/build/adapter-nextjs/processRequest.js.map +1 -0
- package/build/data-fetching/api/PrezlyApi.d.ts +43 -0
- package/build/data-fetching/api/PrezlyApi.js +139 -0
- package/build/data-fetching/api/PrezlyApi.js.map +1 -0
- package/build/data-fetching/api/getPrezlyApi.d.ts +4 -0
- package/build/data-fetching/api/getPrezlyApi.js +17 -0
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -0
- package/build/data-fetching/api/index.d.ts +2 -0
- package/build/data-fetching/api/index.js +3 -0
- package/build/data-fetching/api/index.js.map +1 -0
- package/build/data-fetching/api/languages.d.ts +18 -0
- package/build/data-fetching/api/languages.js +117 -0
- package/build/data-fetching/api/languages.js.map +1 -0
- package/build/data-fetching/api/queries.d.ts +45 -0
- package/build/data-fetching/api/queries.js +35 -0
- package/build/data-fetching/api/queries.js.map +1 -0
- package/build/data-fetching/constants.d.ts +2 -0
- package/build/data-fetching/constants.js +3 -0
- package/build/data-fetching/constants.js.map +1 -0
- package/build/data-fetching/getAssetsUrl.d.ts +1 -0
- package/build/data-fetching/getAssetsUrl.js +5 -0
- package/build/data-fetching/getAssetsUrl.js.map +1 -0
- package/build/data-fetching/getLocalizedCategoryData.d.ts +10 -0
- package/build/data-fetching/getLocalizedCategoryData.js +31 -0
- package/build/data-fetching/getLocalizedCategoryData.js.map +1 -0
- package/build/data-fetching/getNewsroomLogoUrl.d.ts +3 -0
- package/build/data-fetching/getNewsroomLogoUrl.js +14 -0
- package/build/data-fetching/getNewsroomLogoUrl.js.map +1 -0
- package/build/data-fetching/getPrivacyPortalUrl.d.ts +8 -0
- package/build/data-fetching/getPrivacyPortalUrl.js +9 -0
- package/build/data-fetching/getPrivacyPortalUrl.js.map +1 -0
- package/build/data-fetching/getStoryPublicationDate.d.ts +3 -0
- package/build/data-fetching/getStoryPublicationDate.jsx +10 -0
- package/build/data-fetching/getStoryPublicationDate.jsx.map +1 -0
- package/build/data-fetching/getUploadcareGroupUrl.d.ts +1 -0
- package/build/data-fetching/getUploadcareGroupUrl.js +5 -0
- package/build/data-fetching/getUploadcareGroupUrl.js.map +1 -0
- package/build/data-fetching/index.d.ts +9 -0
- package/build/data-fetching/index.js +10 -0
- package/build/data-fetching/index.js.map +1 -0
- package/build/data-fetching/lib/getAlgoliaSettings.d.ts +4 -0
- package/build/data-fetching/lib/getAlgoliaSettings.js +18 -0
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -0
- package/build/data-fetching/lib/getEnvVariables.d.ts +4 -0
- package/build/data-fetching/lib/getEnvVariables.js +37 -0
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -0
- package/build/data-fetching/types.d.ts +11 -0
- package/build/data-fetching/types.js +2 -0
- package/build/data-fetching/types.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/intl/index.d.ts +4 -0
- package/build/intl/index.js +5 -0
- package/build/intl/index.js.map +1 -0
- package/build/intl/lang.d.ts +12 -0
- package/build/intl/lang.js +25 -0
- package/build/intl/lang.js.map +1 -0
- package/build/intl/locale.d.ts +10 -0
- package/build/intl/locale.js +93 -0
- package/build/intl/locale.js.map +1 -0
- package/build/intl/localeConfig.d.ts +2 -0
- package/build/intl/localeConfig.js +113 -0
- package/build/intl/localeConfig.js.map +1 -0
- package/build/intl/localeObject.d.ts +22 -0
- package/build/intl/localeObject.js +59 -0
- package/build/intl/localeObject.js.map +1 -0
- package/build/newsroom-context/context.d.ts +26 -0
- package/build/newsroom-context/context.jsx +22 -0
- package/build/newsroom-context/context.jsx.map +1 -0
- package/build/newsroom-context/hooks/index.d.ts +11 -0
- package/build/newsroom-context/hooks/index.js +12 -0
- package/build/newsroom-context/hooks/index.js.map +1 -0
- package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -0
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +6 -0
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -0
- package/build/newsroom-context/hooks/useCategories.d.ts +1 -0
- package/build/newsroom-context/hooks/useCategories.js +6 -0
- package/build/newsroom-context/hooks/useCategories.js.map +1 -0
- package/build/newsroom-context/hooks/useCompanyInformation.d.ts +1 -0
- package/build/newsroom-context/hooks/useCompanyInformation.js +6 -0
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -0
- package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -0
- package/build/newsroom-context/hooks/useCurrentLocale.js +6 -0
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -0
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.d.ts +2 -0
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +21 -0
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -0
- package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +2 -0
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +36 -0
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -0
- package/build/newsroom-context/hooks/useLanguages.d.ts +1 -0
- package/build/newsroom-context/hooks/useLanguages.js +6 -0
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -0
- package/build/newsroom-context/hooks/useNewsroom.d.ts +1 -0
- package/build/newsroom-context/hooks/useNewsroom.js +6 -0
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -0
- package/build/newsroom-context/hooks/useNewsroomContext.d.ts +2 -0
- package/build/newsroom-context/hooks/useNewsroomContext.js +12 -0
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -0
- package/build/newsroom-context/hooks/useSelectedCategory.d.ts +1 -0
- package/build/newsroom-context/hooks/useSelectedCategory.js +6 -0
- package/build/newsroom-context/hooks/useSelectedCategory.js.map +1 -0
- package/build/newsroom-context/hooks/useSelectedStory.d.ts +1 -0
- package/build/newsroom-context/hooks/useSelectedStory.js +6 -0
- package/build/newsroom-context/hooks/useSelectedStory.js.map +1 -0
- package/build/newsroom-context/index.d.ts +2 -0
- package/build/newsroom-context/index.js +3 -0
- package/build/newsroom-context/index.js.map +1 -0
- package/build/types.d.ts +38 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +60 -0
- package/src/@types/global.d.ts +7 -0
- package/src/adapter-nextjs/getBasePageProps.ts +23 -0
- package/src/adapter-nextjs/index.ts +2 -0
- package/src/adapter-nextjs/processRequest.ts +31 -0
- package/src/data-fetching/api/PrezlyApi.ts +240 -0
- package/src/data-fetching/api/getPrezlyApi.ts +24 -0
- package/src/data-fetching/api/index.ts +2 -0
- package/src/data-fetching/api/languages.ts +172 -0
- package/src/data-fetching/api/queries.ts +44 -0
- package/src/data-fetching/constants.ts +2 -0
- package/src/data-fetching/getAssetsUrl.ts +5 -0
- package/src/data-fetching/getLocalizedCategoryData.ts +47 -0
- package/src/data-fetching/getNewsroomLogoUrl.ts +21 -0
- package/src/data-fetching/getPrivacyPortalUrl.ts +22 -0
- package/src/data-fetching/getStoryPublicationDate.tsx +15 -0
- package/src/data-fetching/getUploadcareGroupUrl.ts +5 -0
- package/src/data-fetching/index.ts +9 -0
- package/src/data-fetching/lib/getAlgoliaSettings.ts +29 -0
- package/src/data-fetching/lib/getEnvVariables.ts +44 -0
- package/src/data-fetching/types.ts +12 -0
- package/src/index.ts +5 -0
- package/src/intl/index.ts +4 -0
- package/src/intl/lang.ts +36 -0
- package/src/intl/locale.ts +118 -0
- package/src/intl/localeConfig.js +116 -0
- package/src/intl/localeObject.ts +73 -0
- package/src/newsroom-context/context.tsx +73 -0
- package/src/newsroom-context/hooks/index.ts +11 -0
- package/src/newsroom-context/hooks/useAlgoliaSettings.ts +7 -0
- package/src/newsroom-context/hooks/useCategories.ts +7 -0
- package/src/newsroom-context/hooks/useCompanyInformation.ts +7 -0
- package/src/newsroom-context/hooks/useCurrentLocale.ts +7 -0
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +33 -0
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +61 -0
- package/src/newsroom-context/hooks/useLanguages.ts +7 -0
- package/src/newsroom-context/hooks/useNewsroom.ts +7 -0
- package/src/newsroom-context/hooks/useNewsroomContext.ts +14 -0
- package/src/newsroom-context/hooks/useSelectedCategory.ts +7 -0
- package/src/newsroom-context/hooks/useSelectedStory.ts +7 -0
- package/src/newsroom-context/index.ts +2 -0
- package/src/types.ts +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,MAAM,OAAO,YAAY;IACrB;;;OAGG;IACK,UAAU,CAAS;IAE3B,YAAoB,UAAkB;QAClC,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAED,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChE;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CAAC,UAAkB;QACxC,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,sCAAsC,aAAa,GAAG,CAAC,CAAC;SAC3E;QAED,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAEM,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAEM,gBAAgB;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAEM,qBAAqB;QACxB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEM,YAAY;QACf,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEtD,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;IAEM,OAAO,CAAC,aAA2B;QACtC,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;IAC5D,CAAC;CACJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Category, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset, Story } from '@prezly/sdk';
|
|
2
|
+
import { FunctionComponent } from 'react';
|
|
3
|
+
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
|
+
import { LocaleObject } from '../intl';
|
|
5
|
+
import { Translations } from '../types';
|
|
6
|
+
export interface INewsroomContext {
|
|
7
|
+
newsroom: Newsroom;
|
|
8
|
+
companyInformation: NewsroomCompanyInformation;
|
|
9
|
+
categories: Category[];
|
|
10
|
+
contacts?: NewsroomContact[];
|
|
11
|
+
selectedCategory?: Category;
|
|
12
|
+
selectedStory?: Story;
|
|
13
|
+
languages: NewsroomLanguageSettings[];
|
|
14
|
+
locale: LocaleObject;
|
|
15
|
+
hasError?: boolean;
|
|
16
|
+
themePreset: NewsroomThemePreset;
|
|
17
|
+
algoliaSettings: AlgoliaSettings;
|
|
18
|
+
}
|
|
19
|
+
interface Props extends Omit<INewsroomContext, 'locale'> {
|
|
20
|
+
isTrackingEnabled?: boolean;
|
|
21
|
+
localeCode: string;
|
|
22
|
+
translations?: Translations;
|
|
23
|
+
}
|
|
24
|
+
export declare const NewsroomContext: import("react").Context<INewsroomContext | undefined>;
|
|
25
|
+
export declare const NewsroomContextProvider: FunctionComponent<Props>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext, useMemo } from 'react';
|
|
2
|
+
import { LocaleObject } from '../intl';
|
|
3
|
+
export const NewsroomContext = createContext(undefined);
|
|
4
|
+
export const NewsroomContextProvider = ({ categories, contacts, newsroom, selectedCategory, selectedStory, companyInformation, languages, localeCode, hasError, themePreset, algoliaSettings, children, }) => {
|
|
5
|
+
const locale = useMemo(() => LocaleObject.fromAnyCode(localeCode || 'en'), [localeCode]);
|
|
6
|
+
return (<NewsroomContext.Provider value={{
|
|
7
|
+
categories,
|
|
8
|
+
contacts,
|
|
9
|
+
newsroom,
|
|
10
|
+
selectedCategory,
|
|
11
|
+
selectedStory,
|
|
12
|
+
companyInformation,
|
|
13
|
+
languages,
|
|
14
|
+
locale,
|
|
15
|
+
hasError,
|
|
16
|
+
themePreset,
|
|
17
|
+
algoliaSettings,
|
|
18
|
+
}}>
|
|
19
|
+
{children}
|
|
20
|
+
</NewsroomContext.Provider>);
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=context.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.jsx","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAqB,OAAO,EAAE,MAAM,OAAO,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAuBvC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAEtF,MAAM,CAAC,MAAM,uBAAuB,GAA6B,CAAC,EAC9D,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,QAAQ,EACR,WAAW,EACX,eAAe,EACf,QAAQ,GACX,EAAE,EAAE;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,UAAU,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEzF,OAAO,CACH,CAAC,eAAe,CAAC,QAAQ,CACrB,KAAK,CAAC,CAAC;YACH,UAAU;YACV,QAAQ;YACR,QAAQ;YACR,gBAAgB;YAChB,aAAa;YACb,kBAAkB;YAClB,SAAS;YACT,MAAM;YACN,QAAQ;YACR,WAAW;YACX,eAAe;SAClB,CAAC,CAEF;YAAA,CAAC,QAAQ,CACb;QAAA,EAAE,eAAe,CAAC,QAAQ,CAAC,CAC9B,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './useAlgoliaSettings';
|
|
2
|
+
export * from './useCategories';
|
|
3
|
+
export * from './useCompanyInformation';
|
|
4
|
+
export * from './useCurrentLocale';
|
|
5
|
+
export * from './useGetLinkLocaleSlug';
|
|
6
|
+
export * from './useGetTranslationUrl';
|
|
7
|
+
export * from './useLanguages';
|
|
8
|
+
export * from './useNewsroom';
|
|
9
|
+
export * from './useNewsroomContext';
|
|
10
|
+
export * from './useSelectedCategory';
|
|
11
|
+
export * from './useSelectedStory';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './useAlgoliaSettings';
|
|
2
|
+
export * from './useCategories';
|
|
3
|
+
export * from './useCompanyInformation';
|
|
4
|
+
export * from './useCurrentLocale';
|
|
5
|
+
export * from './useGetLinkLocaleSlug';
|
|
6
|
+
export * from './useGetTranslationUrl';
|
|
7
|
+
export * from './useLanguages';
|
|
8
|
+
export * from './useNewsroom';
|
|
9
|
+
export * from './useNewsroomContext';
|
|
10
|
+
export * from './useSelectedCategory';
|
|
11
|
+
export * from './useSelectedStory';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAlgoliaSettings: () => import("../..").AlgoliaSettings;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAlgoliaSettings.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useAlgoliaSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,eAAe,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCategories: () => import("@prezly/sdk").Category[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCategories.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCategories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,UAAU,CAAC;AAC9B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCompanyInformation: () => import("@prezly/sdk").NewsroomCompanyInformation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCompanyInformation.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCompanyInformation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,kBAAkB,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCurrentLocale: () => import("../..").LocaleObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentLocale.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCurrentLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { getShortestLocaleCode } from '../../data-fetching';
|
|
3
|
+
import { LocaleObject } from '../../intl';
|
|
4
|
+
import { useCurrentLocale } from './useCurrentLocale';
|
|
5
|
+
import { useLanguages } from './useLanguages';
|
|
6
|
+
// Determine correct locale slug for the link (trying to shorten the locale code if possible)
|
|
7
|
+
function getLinkLocaleSlug(languages, locale) {
|
|
8
|
+
const shortestLocaleCode = getShortestLocaleCode(languages, locale);
|
|
9
|
+
// When navigating to default language, we don't append the locale to the URL.
|
|
10
|
+
if (!shortestLocaleCode) {
|
|
11
|
+
return shortestLocaleCode;
|
|
12
|
+
}
|
|
13
|
+
return LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug();
|
|
14
|
+
}
|
|
15
|
+
export function useGetLinkLocaleSlug() {
|
|
16
|
+
const currentLocale = useCurrentLocale();
|
|
17
|
+
const languages = useLanguages();
|
|
18
|
+
// The `locale` parameter is mainly used for Language Dropdown
|
|
19
|
+
return useCallback((locale) => getLinkLocaleSlug(languages, locale || currentLocale), [languages, currentLocale]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=useGetLinkLocaleSlug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetLinkLocaleSlug.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetLinkLocaleSlug.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,6FAA6F;AAC7F,SAAS,iBAAiB,CACtB,SAAqC,EACrC,MAAoB;IAEpB,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACpE,8EAA8E;IAC9E,IAAI,CAAC,kBAAkB,EAAE;QACrB,OAAO,kBAAkB,CAAC;KAC7B;IAED,OAAO,YAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,oBAAoB;IAChC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IAEjC,8DAA8D;IAC9D,OAAO,WAAW,CACd,CAAC,MAAqB,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,IAAI,aAAa,CAAC,EAChF,CAAC,SAAS,EAAE,aAAa,CAAC,CAC7B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useRouter } from 'next/router';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { getCategoryHasTranslation, getCategoryUrl } from '../../data-fetching';
|
|
4
|
+
import { useSelectedCategory } from './useSelectedCategory';
|
|
5
|
+
import { useSelectedStory } from './useSelectedStory';
|
|
6
|
+
// Determine correct URL for translated stories/categories with a fallback to homepage
|
|
7
|
+
function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFallback) {
|
|
8
|
+
if (selectedCategory) {
|
|
9
|
+
if (getCategoryHasTranslation(selectedCategory, locale)) {
|
|
10
|
+
return getCategoryUrl(selectedCategory, locale);
|
|
11
|
+
}
|
|
12
|
+
if (noFallback) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
return '/';
|
|
16
|
+
}
|
|
17
|
+
const localeCode = locale.toUnderscoreCode();
|
|
18
|
+
if (selectedStory && selectedStory.culture.locale !== localeCode) {
|
|
19
|
+
const translatedStory = selectedStory.translations.find(({ culture }) => culture.locale === localeCode);
|
|
20
|
+
if (translatedStory) {
|
|
21
|
+
return `/${translatedStory.slug}`;
|
|
22
|
+
}
|
|
23
|
+
if (noFallback) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
return '/';
|
|
27
|
+
}
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
export function useGetTranslationUrl() {
|
|
31
|
+
const { asPath } = useRouter();
|
|
32
|
+
const selectedCategory = useSelectedCategory();
|
|
33
|
+
const selectedStory = useSelectedStory();
|
|
34
|
+
return useCallback((locale, noFallback) => getTranslationUrl(locale, asPath, selectedCategory, selectedStory, noFallback), [asPath, selectedCategory, selectedStory]);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useGetTranslationUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,sFAAsF;AACtF,SAAS,iBAAiB,CACtB,MAAoB,EACpB,IAAY,EACZ,gBAA2B,EAC3B,aAAqB,EACrB,UAAoB;IAEpB,IAAI,gBAAgB,EAAE;QAClB,IAAI,yBAAyB,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACrD,OAAO,cAAc,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;SACnD;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAE7C,IAAI,aAAa,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE;QAC9D,MAAM,eAAe,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,CACnD,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,CACjD,CAAC;QACF,IAAI,eAAe,EAAE;YACjB,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,CAAC;SACrC;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,oBAAoB;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;IAC/C,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IAEzC,OAAO,WAAW,CACd,CAAC,MAAoB,EAAE,UAAoB,EAAE,EAAE,CAC3C,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,CAAC,EAClF,CAAC,MAAM,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAC5C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLanguages: () => import("@prezly/sdk").NewsroomLanguageSettings[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useLanguages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC7B,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,SAAS,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useNewsroom: () => import("@prezly/sdk").Newsroom;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNewsroom.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { NewsroomContext } from '../context';
|
|
3
|
+
export const useNewsroomContext = () => {
|
|
4
|
+
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
5
|
+
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
6
|
+
const newsroomContext = useContext(NewsroomContext);
|
|
7
|
+
if (!newsroomContext) {
|
|
8
|
+
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
9
|
+
}
|
|
10
|
+
return newsroomContext;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useNewsroomContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAoB,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACnC,mGAAmG;IACnG,iFAAiF;IACjF,MAAM,eAAe,GAAiC,UAAU,CAAC,eAAe,CAAC,CAAC;IAClF,IAAI,CAAC,eAAe,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;KAC3F;IAED,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSelectedCategory: () => import("@prezly/sdk").Category | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSelectedCategory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedCategory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACpC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,gBAAgB,CAAC;AACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSelectedStory: () => import("@prezly/sdk").Story | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSelectedStory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedStory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IAErC,OAAO,OAAO,CAAC,aAAa,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/newsroom-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACrE,cAAc,SAAS,CAAC"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AlgoliaSettings } from './data-fetching';
|
|
2
|
+
import type { Category, CultureRef, ExtraStoryFields, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset, Story } from '@prezly/sdk';
|
|
3
|
+
export interface BasePageProps {
|
|
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;
|
|
13
|
+
localeResolved: boolean;
|
|
14
|
+
themePreset: NewsroomThemePreset;
|
|
15
|
+
algoliaSettings: AlgoliaSettings;
|
|
16
|
+
translations?: Translations;
|
|
17
|
+
contacts?: NewsroomContact[];
|
|
18
|
+
isTrackingEnabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface PaginationProps {
|
|
21
|
+
itemsTotal: number;
|
|
22
|
+
currentPage: number;
|
|
23
|
+
pageSize: number;
|
|
24
|
+
}
|
|
25
|
+
export declare type StoryWithImage = Story & Pick<ExtraStoryFields, 'thumbnail_image'>;
|
|
26
|
+
export interface AlgoliaCategoryRef {
|
|
27
|
+
id: number;
|
|
28
|
+
name: string;
|
|
29
|
+
slug: string;
|
|
30
|
+
}
|
|
31
|
+
export declare type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> & Pick<ExtraStoryFields, 'thumbnail_image'> & {
|
|
32
|
+
content_text: string;
|
|
33
|
+
updated_at: number;
|
|
34
|
+
published_at: number;
|
|
35
|
+
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
36
|
+
categories: AlgoliaCategoryRef[];
|
|
37
|
+
};
|
|
38
|
+
export declare type Translations = Record<string, string>;
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prezly/theme-kit-nextjs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Data layer and utility library for developing Prezly themes with NextJS",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build",
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">= 14.x",
|
|
13
|
+
"npm": ">= 7.x"
|
|
14
|
+
},
|
|
15
|
+
"devEngines": {
|
|
16
|
+
"node": ">= 14.x",
|
|
17
|
+
"npm": ">= 7.x"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/prezly/theme-kit-nextjs.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/prezly/theme-kit-nextjs/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/prezly/theme-kit-nextjs#readme",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"clean": "rimraf build/ node_modules/",
|
|
32
|
+
"typecheck": "tsc --noEmit --incremental --project .",
|
|
33
|
+
"prebuild": "npm run clean && npm install",
|
|
34
|
+
"build": "tsc --project .",
|
|
35
|
+
"test": "echo \"Tests? maybe next time ;)\" && exit 0",
|
|
36
|
+
"prerelease": "npm run typecheck && npm run build",
|
|
37
|
+
"release": "np"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"next": "^12.x",
|
|
41
|
+
"react": "^17.x",
|
|
42
|
+
"react-dom": "^17.x"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@prezly/sdk": "^6.11.0",
|
|
46
|
+
"parse-data-url": "^4.0.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^17.0.13",
|
|
50
|
+
"@types/parse-data-url": "^3.0.0",
|
|
51
|
+
"@types/react": "^17.0.38",
|
|
52
|
+
"@types/react-dom": "^17.0.11",
|
|
53
|
+
"np": "^7.6.0",
|
|
54
|
+
"rimraf": "^3.0.2",
|
|
55
|
+
"typescript": "^4.5.5"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GetServerSidePropsContext } from 'next';
|
|
2
|
+
|
|
3
|
+
import { getPrezlyApi } from '../data-fetching';
|
|
4
|
+
|
|
5
|
+
interface BasePagePropsOptions {
|
|
6
|
+
loadHomepageContacts?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function getBasePageProps(
|
|
10
|
+
context: GetServerSidePropsContext,
|
|
11
|
+
options: BasePagePropsOptions = {},
|
|
12
|
+
) {
|
|
13
|
+
const { req: request, locale } = context;
|
|
14
|
+
|
|
15
|
+
const api = getPrezlyApi(request);
|
|
16
|
+
const basePageProps = await api.getBasePageProps(request, locale);
|
|
17
|
+
|
|
18
|
+
if (options.loadHomepageContacts) {
|
|
19
|
+
basePageProps.contacts = await api.getNewsroomContacts();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { api, basePageProps };
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
+
|
|
3
|
+
import { getRedirectToCanonicalLocale } from '../intl';
|
|
4
|
+
import { BasePageProps } from '../types';
|
|
5
|
+
|
|
6
|
+
export function processRequest<Props extends BasePageProps>(
|
|
7
|
+
context: GetServerSidePropsContext,
|
|
8
|
+
basePageProps: BasePageProps,
|
|
9
|
+
canonicalUrl?: string,
|
|
10
|
+
customProps?: Omit<Props, keyof BasePageProps>,
|
|
11
|
+
): GetServerSidePropsResult<Props> {
|
|
12
|
+
const { locale, query } = context;
|
|
13
|
+
|
|
14
|
+
if (!basePageProps.localeResolved) {
|
|
15
|
+
return { notFound: true };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (canonicalUrl) {
|
|
19
|
+
const redirect = getRedirectToCanonicalLocale(basePageProps, locale, canonicalUrl, query);
|
|
20
|
+
if (redirect) {
|
|
21
|
+
return { redirect };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
props: {
|
|
27
|
+
...basePageProps,
|
|
28
|
+
...customProps,
|
|
29
|
+
} as Props,
|
|
30
|
+
};
|
|
31
|
+
}
|