@prezly/theme-kit-nextjs 1.18.1 → 2.0.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/build/adapter-nextjs/api-handlers/fetchGalleries.js +3 -7
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +3 -7
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/index.js +2 -7
- package/build/adapter-nextjs/api-handlers/index.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +3 -7
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +3 -7
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/index.js +6 -22
- package/build/adapter-nextjs/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.d.ts +2 -2
- package/build/adapter-nextjs/page-props/category.js +19 -25
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +13 -18
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +13 -19
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.d.ts +2 -2
- package/build/adapter-nextjs/page-props/home.js +13 -18
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/index.js +8 -41
- package/build/adapter-nextjs/page-props/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/lib/types.js +1 -2
- package/build/adapter-nextjs/page-props/search.js +10 -15
- package/build/adapter-nextjs/page-props/search.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +1 -5
- package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js +1 -5
- package/build/adapter-nextjs/page-props/sitemap/createPaths.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +7 -11
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/index.js +4 -24
- package/build/adapter-nextjs/page-props/sitemap/index.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
- package/build/adapter-nextjs/page-props/story.js +17 -23
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +7 -11
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +5 -9
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/adapter-nextjs/processStaticRequest.js +1 -5
- package/build/adapter-nextjs/processStaticRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +25 -29
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/index.js +2 -20
- package/build/components-nextjs/PageSeo/index.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +1 -5
- package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/types.js +1 -2
- package/build/components-nextjs/StorySeo/StorySeo.js +8 -12
- package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/components-nextjs/StorySeo/index.js +1 -5
- package/build/components-nextjs/StorySeo/index.js.map +1 -1
- package/build/components-nextjs/document.js +8 -35
- package/build/components-nextjs/document.js.map +1 -1
- package/build/components-nextjs/index.js +3 -9
- package/build/components-nextjs/index.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +4 -5
- package/build/data-fetching/api/PrezlyApi.js +39 -44
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +5 -9
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/index.js +1 -17
- package/build/data-fetching/api/index.js.map +1 -1
- package/build/data-fetching/api/queries.js +5 -13
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/index.js +3 -19
- package/build/data-fetching/index.js.map +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.js +3 -7
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +3 -10
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/data-fetching/lib/index.js +4 -11
- package/build/data-fetching/lib/index.js.map +1 -1
- package/build/data-fetching/lib/isSdkError.js +1 -5
- package/build/data-fetching/lib/isSdkError.js.map +1 -1
- package/build/data-fetching/lib/isUuid.js +1 -5
- package/build/data-fetching/lib/isUuid.js.map +1 -1
- package/build/data-fetching/types.js +1 -2
- package/build/index.js +9 -25
- package/build/index.js.map +1 -1
- package/build/infinite-loading/index.js +4 -24
- package/build/infinite-loading/index.js.map +1 -1
- package/build/infinite-loading/types.js +1 -2
- package/build/infinite-loading/useInfiniteGalleriesLoading.js +3 -7
- package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +9 -13
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.d.ts +2 -2
- package/build/infinite-loading/useInfiniteStoriesLoading.js +7 -11
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/index.d.ts +1 -1
- package/build/intl/index.js +4 -25
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.d.ts +1 -1
- package/build/intl/languages.js +23 -37
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.js +11 -17
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.d.ts +1 -2
- package/build/intl/localeConfig.js +3 -4
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeList.d.ts +4 -2
- package/build/intl/localeList.js +1 -2
- package/build/intl/localeList.js.map +1 -1
- package/build/intl/localeObject.js +3 -10
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.js +7 -11
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/index.js +11 -27
- package/build/newsroom-context/hooks/index.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +3 -7
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.js +3 -7
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +3 -7
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentCategory.js +3 -7
- package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +3 -7
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentStory.js +3 -7
- package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +10 -14
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +24 -31
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +3 -7
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +3 -7
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.js +4 -8
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/newsroom-context/index.js +2 -21
- package/build/newsroom-context/index.js.map +1 -1
- package/build/sentry/client.js +3 -7
- package/build/sentry/client.js.map +1 -1
- package/build/sentry/common.js +1 -5
- package/build/sentry/common.js.map +1 -1
- package/build/sentry/index.js +2 -7
- package/build/sentry/index.js.map +1 -1
- package/build/sentry/server.js +3 -7
- package/build/sentry/server.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -2
- package/build/utils/boilerplate.js +3 -9
- package/build/utils/boilerplate.js.map +1 -1
- package/build/utils/constants.js +3 -6
- package/build/utils/constants.js.map +1 -1
- package/build/utils/getAssetsUrl.js +3 -7
- package/build/utils/getAssetsUrl.js.map +1 -1
- package/build/utils/getDataRequestLink.js +3 -7
- package/build/utils/getDataRequestLink.js.map +1 -1
- package/build/utils/getLocalizedCategoryData.js +3 -9
- package/build/utils/getLocalizedCategoryData.js.map +1 -1
- package/build/utils/getNewsroomLogoUrl.js +5 -10
- package/build/utils/getNewsroomLogoUrl.js.map +1 -1
- package/build/utils/getPrivacyPortalUrl.js +1 -5
- package/build/utils/getPrivacyPortalUrl.js.map +1 -1
- package/build/utils/getStoryPublicationDate.js +1 -5
- package/build/utils/getStoryPublicationDate.js.map +1 -1
- package/build/utils/getUploadcareGroupUrl.js +3 -7
- package/build/utils/getUploadcareGroupUrl.js.map +1 -1
- package/build/utils/index.js +10 -26
- package/build/utils/index.js.map +1 -1
- package/build/utils/isEmbargoStory.js +1 -5
- package/build/utils/isEmbargoStory.js.map +1 -1
- package/package.json +17 -17
- package/src/@types/global.d.ts +0 -7
- package/src/__mocks__/languages.ts +0 -417
- package/src/__mocks__/story.ts +0 -351
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -26
- package/src/adapter-nextjs/api-handlers/index.ts +0 -2
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +0 -29
- package/src/adapter-nextjs/getNewsroomStaticProps.ts +0 -29
- package/src/adapter-nextjs/index.ts +0 -6
- package/src/adapter-nextjs/page-props/category.ts +0 -157
- package/src/adapter-nextjs/page-props/gallery.ts +0 -114
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +0 -89
- package/src/adapter-nextjs/page-props/home.ts +0 -113
- package/src/adapter-nextjs/page-props/index.ts +0 -26
- package/src/adapter-nextjs/page-props/lib/types.ts +0 -8
- package/src/adapter-nextjs/page-props/search.ts +0 -53
- package/src/adapter-nextjs/page-props/sitemap/SitemapBuilder.ts +0 -56
- package/src/adapter-nextjs/page-props/sitemap/createPaths.ts +0 -21
- package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +0 -43
- package/src/adapter-nextjs/page-props/sitemap/index.ts +0 -5
- package/src/adapter-nextjs/page-props/sitemap/types.ts +0 -5
- package/src/adapter-nextjs/page-props/story.ts +0 -94
- package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
- package/src/adapter-nextjs/processRequest.ts +0 -49
- package/src/adapter-nextjs/processStaticRequest.ts +0 -32
- package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -131
- package/src/components-nextjs/PageSeo/index.ts +0 -2
- package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
- package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
- package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -80
- package/src/components-nextjs/StorySeo/index.ts +0 -1
- package/src/components-nextjs/document.tsx +0 -38
- package/src/components-nextjs/index.ts +0 -3
- package/src/data-fetching/api/PrezlyApi.ts +0 -302
- package/src/data-fetching/api/getPrezlyApi.ts +0 -24
- package/src/data-fetching/api/index.ts +0 -1
- package/src/data-fetching/api/queries.ts +0 -51
- package/src/data-fetching/index.ts +0 -3
- package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
- package/src/data-fetching/lib/getEnvVariables.ts +0 -46
- package/src/data-fetching/lib/index.ts +0 -4
- package/src/data-fetching/lib/isSdkError.ts +0 -5
- package/src/data-fetching/lib/isUuid.ts +0 -5
- package/src/data-fetching/types.ts +0 -14
- package/src/index.ts +0 -9
- package/src/infinite-loading/index.ts +0 -4
- package/src/infinite-loading/types.ts +0 -5
- package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -53
- package/src/infinite-loading/useInfiniteLoading.ts +0 -66
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -81
- package/src/intl/index.ts +0 -4
- package/src/intl/languages.test.ts +0 -232
- package/src/intl/languages.ts +0 -233
- package/src/intl/locale.test.ts +0 -94
- package/src/intl/locale.ts +0 -140
- package/src/intl/localeConfig.js +0 -23
- package/src/intl/localeList.js +0 -110
- package/src/intl/localeObject.test.ts +0 -81
- package/src/intl/localeObject.ts +0 -99
- package/src/newsroom-context/context.tsx +0 -115
- package/src/newsroom-context/hooks/index.ts +0 -11
- package/src/newsroom-context/hooks/useAlgoliaSettings.ts +0 -7
- package/src/newsroom-context/hooks/useCategories.ts +0 -7
- package/src/newsroom-context/hooks/useCompanyInformation.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentCategory.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentLocale.ts +0 -7
- package/src/newsroom-context/hooks/useCurrentStory.ts +0 -7
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +0 -37
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -96
- package/src/newsroom-context/hooks/useLanguages.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroom.ts +0 -7
- package/src/newsroom-context/hooks/useNewsroomContext.ts +0 -15
- package/src/newsroom-context/index.ts +0 -2
- package/src/sentry/client.ts +0 -7
- package/src/sentry/common.ts +0 -27
- package/src/sentry/index.ts +0 -2
- package/src/sentry/server.ts +0 -7
- package/src/types.ts +0 -51
- package/src/utils/boilerplate.ts +0 -27
- package/src/utils/constants.ts +0 -3
- package/src/utils/getAssetsUrl.test.ts +0 -9
- package/src/utils/getAssetsUrl.ts +0 -9
- package/src/utils/getDataRequestLink.ts +0 -14
- package/src/utils/getLocalizedCategoryData.ts +0 -47
- package/src/utils/getNewsroomLogoUrl.ts +0 -22
- package/src/utils/getPrivacyPortalUrl.ts +0 -25
- package/src/utils/getStoryPublicationDate.tsx +0 -15
- package/src/utils/getUploadcareGroupUrl.ts +0 -13
- package/src/utils/index.ts +0 -10
- package/src/utils/isEmbargoStory.ts +0 -10
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
-
|
|
3
|
-
import { getRedirectToCanonicalLocale, getShortestLocaleCode, LocaleObject } from '../intl';
|
|
4
|
-
import type { PageProps, ServerSidePageProps } from '../types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This function combines the props returned from `getNewsroomServerSideProps` and your optional custom props for the page.
|
|
8
|
-
* It also handles locale redirects, if `canonicalUrl` parameter is provided.
|
|
9
|
-
* See README for usage examples.
|
|
10
|
-
*
|
|
11
|
-
* @param context Next.js context passed to the `getServerSideProps` method of the page
|
|
12
|
-
* @param props Object containing the return of `getNewsroomServerSideProps` and your optional custom props.
|
|
13
|
-
* @param canonicalUrl Optional: a canonical URL for the current page without locale part. If provided, locale redirects will be handled by the function.
|
|
14
|
-
*/
|
|
15
|
-
export function processRequest<Props>(
|
|
16
|
-
context: GetServerSidePropsContext,
|
|
17
|
-
props: Props & PageProps & ServerSidePageProps,
|
|
18
|
-
canonicalUrl?: string,
|
|
19
|
-
): GetServerSidePropsResult<Props> {
|
|
20
|
-
const { locale: nextLocale, query } = context;
|
|
21
|
-
|
|
22
|
-
const { localeResolved, ...pageProps } = props;
|
|
23
|
-
|
|
24
|
-
// If no locale was provided by Next, it most likely means that the theme is not supporting multi-language.
|
|
25
|
-
// In that case we won't show 404 page.
|
|
26
|
-
if (!localeResolved && nextLocale) {
|
|
27
|
-
return { notFound: true };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (canonicalUrl) {
|
|
31
|
-
const { languages, localeCode } = pageProps.newsroomContextProps;
|
|
32
|
-
const currentLocale = LocaleObject.fromAnyCode(localeCode);
|
|
33
|
-
const shortestLocaleCode = getShortestLocaleCode(languages, currentLocale);
|
|
34
|
-
|
|
35
|
-
const redirect = getRedirectToCanonicalLocale(
|
|
36
|
-
shortestLocaleCode,
|
|
37
|
-
nextLocale,
|
|
38
|
-
canonicalUrl,
|
|
39
|
-
query,
|
|
40
|
-
);
|
|
41
|
-
if (redirect) {
|
|
42
|
-
return { redirect };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
props: pageProps as Props & PageProps,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { GetStaticPropsContext, GetStaticPropsResult } from 'next';
|
|
2
|
-
|
|
3
|
-
import type { PageProps, ServerSidePageProps } from '../types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This function combines the props returned from `getNewsroomStaticProps` and your optional custom props for the page.
|
|
7
|
-
* See README for usage examples.
|
|
8
|
-
*
|
|
9
|
-
* @param context Next.js context passed to the `getStaticProps` method of the page
|
|
10
|
-
* @param props Object containing the return of `getNewsroomServerSideProps` and your optional custom props.
|
|
11
|
-
* @param revalidateTimeout Optional: timeout in seconds to use with Next ISR.
|
|
12
|
-
*/
|
|
13
|
-
export function processStaticRequest<Props>(
|
|
14
|
-
context: GetStaticPropsContext,
|
|
15
|
-
props: Props & PageProps & ServerSidePageProps,
|
|
16
|
-
revalidateTimeout?: number,
|
|
17
|
-
): GetStaticPropsResult<Props> {
|
|
18
|
-
const { locale: nextLocale } = context;
|
|
19
|
-
|
|
20
|
-
const { localeResolved, ...pageProps } = props;
|
|
21
|
-
|
|
22
|
-
// If no locale was provided by Next, it most likely means that the theme is not supporting multi-language.
|
|
23
|
-
// In that case we won't show 404 page.
|
|
24
|
-
if (!localeResolved && nextLocale) {
|
|
25
|
-
return { notFound: true };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
props: pageProps as Props & PageProps,
|
|
30
|
-
revalidate: revalidateTimeout,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { NextSeo } from 'next-seo';
|
|
2
|
-
import type { NextSeoProps } from 'next-seo';
|
|
3
|
-
import { useRouter } from 'next/router';
|
|
4
|
-
import { useMemo } from 'react';
|
|
5
|
-
|
|
6
|
-
import { getUsedLanguages, LocaleObject } from '../../intl';
|
|
7
|
-
import {
|
|
8
|
-
useCompanyInformation,
|
|
9
|
-
useCurrentLocale,
|
|
10
|
-
useCurrentStory,
|
|
11
|
-
useGetLinkLocaleSlug,
|
|
12
|
-
useGetTranslationUrl,
|
|
13
|
-
useLanguages,
|
|
14
|
-
useNewsroom,
|
|
15
|
-
} from '../../newsroom-context';
|
|
16
|
-
import { getNewsroomLogoUrl } from '../../utils';
|
|
17
|
-
|
|
18
|
-
import { getAbsoluteUrl } from './lib/getAbsoluteUrl';
|
|
19
|
-
import type { AlternateLanguageLink } from './lib/types';
|
|
20
|
-
|
|
21
|
-
type Props = NextSeoProps & {
|
|
22
|
-
imageUrl?: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* This component provides base page attributes for every Newsroom page.
|
|
27
|
-
* It depends on information from NewsroomContext, so the component should be placed inside the `NewsroomContextProvider`.
|
|
28
|
-
* You can pass additional props expected by NextSeo component to override any info that is provided by the NewsroomContext.
|
|
29
|
-
*/
|
|
30
|
-
export function PageSeo({
|
|
31
|
-
title,
|
|
32
|
-
description,
|
|
33
|
-
imageUrl,
|
|
34
|
-
canonical,
|
|
35
|
-
openGraph,
|
|
36
|
-
twitter,
|
|
37
|
-
...nextSeoProps
|
|
38
|
-
}: Props) {
|
|
39
|
-
const companyInformation = useCompanyInformation();
|
|
40
|
-
const newsroom = useNewsroom();
|
|
41
|
-
const currentLocale = useCurrentLocale();
|
|
42
|
-
const languages = useLanguages();
|
|
43
|
-
const getTranslationUrl = useGetTranslationUrl();
|
|
44
|
-
const getLinkLocaleSlug = useGetLinkLocaleSlug();
|
|
45
|
-
const currentStory = useCurrentStory();
|
|
46
|
-
const { asPath } = useRouter();
|
|
47
|
-
|
|
48
|
-
const pageTitle = title || companyInformation.name;
|
|
49
|
-
const pageDescription = description || companyInformation.about_plaintext;
|
|
50
|
-
const canonicalUrl =
|
|
51
|
-
canonical || getAbsoluteUrl(asPath, newsroom.url, getLinkLocaleSlug(currentLocale));
|
|
52
|
-
const siteName = companyInformation.name;
|
|
53
|
-
const logoUrl = imageUrl || getNewsroomLogoUrl(newsroom);
|
|
54
|
-
|
|
55
|
-
const alternateLanguageLinks: AlternateLanguageLink[] = useMemo(() => {
|
|
56
|
-
if (!languages.length) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const alternateLanguages = getUsedLanguages(languages).filter(
|
|
61
|
-
(language) => language.code !== currentLocale.toUnderscoreCode(),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
return alternateLanguages
|
|
65
|
-
.map((language) => {
|
|
66
|
-
const locale = LocaleObject.fromAnyCode(language.code);
|
|
67
|
-
|
|
68
|
-
const translationLink = getTranslationUrl(locale, true);
|
|
69
|
-
|
|
70
|
-
if (!translationLink) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
hrefLang: locale.toHyphenCode(),
|
|
76
|
-
href: getAbsoluteUrl(
|
|
77
|
-
translationLink,
|
|
78
|
-
newsroom.url,
|
|
79
|
-
currentStory && translationLink !== '/' ? false : getLinkLocaleSlug(locale),
|
|
80
|
-
),
|
|
81
|
-
};
|
|
82
|
-
})
|
|
83
|
-
.filter<AlternateLanguageLink>(Boolean as any);
|
|
84
|
-
}, [
|
|
85
|
-
currentLocale,
|
|
86
|
-
getLinkLocaleSlug,
|
|
87
|
-
getTranslationUrl,
|
|
88
|
-
languages,
|
|
89
|
-
newsroom.url,
|
|
90
|
-
currentStory,
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<NextSeo
|
|
95
|
-
title={pageTitle}
|
|
96
|
-
description={pageDescription}
|
|
97
|
-
canonical={canonicalUrl}
|
|
98
|
-
noindex={nextSeoProps.noindex ?? !newsroom.is_indexable}
|
|
99
|
-
nofollow={nextSeoProps.nofollow ?? !newsroom.is_indexable}
|
|
100
|
-
openGraph={{
|
|
101
|
-
url: canonicalUrl,
|
|
102
|
-
title: pageTitle,
|
|
103
|
-
description: pageDescription,
|
|
104
|
-
locale: currentLocale.toUnderscoreCode(),
|
|
105
|
-
images: [
|
|
106
|
-
{
|
|
107
|
-
url: logoUrl,
|
|
108
|
-
alt: pageTitle,
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
site_name: siteName,
|
|
112
|
-
...openGraph,
|
|
113
|
-
}}
|
|
114
|
-
twitter={{
|
|
115
|
-
site: siteName,
|
|
116
|
-
cardType: 'summary',
|
|
117
|
-
...twitter,
|
|
118
|
-
}}
|
|
119
|
-
additionalMetaTags={[{ name: 'twitter:image', content: logoUrl }]}
|
|
120
|
-
additionalLinkTags={[
|
|
121
|
-
{
|
|
122
|
-
rel: 'alternate',
|
|
123
|
-
type: 'application/rss+xml',
|
|
124
|
-
href: `${document.location.origin}/feed`,
|
|
125
|
-
},
|
|
126
|
-
]}
|
|
127
|
-
languageAlternates={alternateLanguageLinks}
|
|
128
|
-
{...nextSeoProps}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Returns absolute URL based on the path and without any query parameters
|
|
2
|
-
export function getAbsoluteUrl(path: string, origin: string, localeCode?: string | false): string {
|
|
3
|
-
const url = new URL(`${localeCode ? `/${localeCode}` : ''}${path || '/'}`, origin);
|
|
4
|
-
url.search = '';
|
|
5
|
-
|
|
6
|
-
return url.toString();
|
|
7
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { ExtendedStory } from '@prezly/sdk';
|
|
2
|
-
import { StoryVisibility } from '@prezly/sdk';
|
|
3
|
-
import { ArticleJsonLd, NextSeo } from 'next-seo';
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
story: ExtendedStory;
|
|
7
|
-
noindex?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* This components provides additional page attributes for the Story page.
|
|
12
|
-
* It works in conjunction with `PageSeo` component, overidding some of its attributes.
|
|
13
|
-
*/
|
|
14
|
-
export function StorySeo({ story, noindex }: Props) {
|
|
15
|
-
const { title, subtitle, published_at, updated_at, author, oembed, newsroom, summary } = story;
|
|
16
|
-
|
|
17
|
-
const authorName = author?.display_name || author?.email || 'Unknown';
|
|
18
|
-
const description = subtitle || summary;
|
|
19
|
-
const indexable = newsroom.is_indexable && story.visibility === StoryVisibility.PUBLIC;
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<>
|
|
23
|
-
<NextSeo
|
|
24
|
-
title={title}
|
|
25
|
-
description={description}
|
|
26
|
-
canonical={oembed.url}
|
|
27
|
-
noindex={noindex ?? !indexable}
|
|
28
|
-
nofollow={noindex ?? !indexable}
|
|
29
|
-
openGraph={{
|
|
30
|
-
title,
|
|
31
|
-
description,
|
|
32
|
-
url: oembed.url,
|
|
33
|
-
site_name: newsroom.display_name,
|
|
34
|
-
type: 'article',
|
|
35
|
-
article: {
|
|
36
|
-
publishedTime: published_at || undefined,
|
|
37
|
-
modifiedTime: updated_at,
|
|
38
|
-
authors: [authorName],
|
|
39
|
-
},
|
|
40
|
-
...(oembed.thumbnail_url && {
|
|
41
|
-
images: [
|
|
42
|
-
{
|
|
43
|
-
url: oembed.thumbnail_url,
|
|
44
|
-
alt: oembed.title,
|
|
45
|
-
width: oembed.thumbnail_width,
|
|
46
|
-
height: oembed.thumbnail_height,
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
}),
|
|
50
|
-
}}
|
|
51
|
-
additionalMetaTags={
|
|
52
|
-
oembed.thumbnail_url
|
|
53
|
-
? [
|
|
54
|
-
{ name: 'twitter:card', content: 'summary_large_image' },
|
|
55
|
-
{ name: 'twitter:image', content: oembed.thumbnail_url },
|
|
56
|
-
]
|
|
57
|
-
: undefined
|
|
58
|
-
}
|
|
59
|
-
additionalLinkTags={[
|
|
60
|
-
{
|
|
61
|
-
rel: 'alternate',
|
|
62
|
-
type: 'application/json',
|
|
63
|
-
href: `${document.location.origin}${document.location.pathname}.json`,
|
|
64
|
-
},
|
|
65
|
-
]}
|
|
66
|
-
/>
|
|
67
|
-
<ArticleJsonLd
|
|
68
|
-
url={oembed.url}
|
|
69
|
-
title={title}
|
|
70
|
-
images={oembed.thumbnail_url ? [oembed.thumbnail_url] : []}
|
|
71
|
-
datePublished={published_at || ''}
|
|
72
|
-
dateModified={updated_at}
|
|
73
|
-
authorName={[authorName]}
|
|
74
|
-
publisherName={newsroom.display_name}
|
|
75
|
-
publisherLogo={newsroom.thumbnail_url}
|
|
76
|
-
description={description}
|
|
77
|
-
/>
|
|
78
|
-
</>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { StorySeo } from './StorySeo';
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Document, { Head, Html, Main, NextScript } from 'next/document';
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_LOCALE, getLocaleDirection, LocaleObject } from '../intl';
|
|
4
|
-
import type { PageProps } from '../types';
|
|
5
|
-
|
|
6
|
-
export class PrezlyThemeDocument extends Document {
|
|
7
|
-
getLocaleCode() {
|
|
8
|
-
const {
|
|
9
|
-
newsroomContextProps,
|
|
10
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
11
|
-
} = this.props.__NEXT_DATA__.props.pageProps as PageProps;
|
|
12
|
-
|
|
13
|
-
// In some cases (like server errors) the newsroom context props will not be loaded.
|
|
14
|
-
// We need to fall back to default locale to keep the app working.
|
|
15
|
-
const { localeCode } = newsroomContextProps ?? { localeCode: DEFAULT_LOCALE };
|
|
16
|
-
|
|
17
|
-
return localeCode;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
render() {
|
|
21
|
-
const locale = LocaleObject.fromAnyCode(this.getLocaleCode());
|
|
22
|
-
// TODO: The direction can be pulled from the Language object
|
|
23
|
-
const direction = getLocaleDirection(locale);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<Html lang={locale.toHyphenCode()} dir={direction}>
|
|
27
|
-
<Head>
|
|
28
|
-
<meta name="og:locale" content={locale.toHyphenCode()} />
|
|
29
|
-
{/* TODO: Add alternate locales */}
|
|
30
|
-
</Head>
|
|
31
|
-
<body>
|
|
32
|
-
<Main />
|
|
33
|
-
<NextScript />
|
|
34
|
-
</body>
|
|
35
|
-
</Html>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Category,
|
|
3
|
-
ExtraStoryFields,
|
|
4
|
-
Newsroom,
|
|
5
|
-
NewsroomLanguageSettings,
|
|
6
|
-
Story,
|
|
7
|
-
} from '@prezly/sdk';
|
|
8
|
-
import PrezlySDK from '@prezly/sdk';
|
|
9
|
-
import type { IncomingMessage } from 'http';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
getCompanyInformation,
|
|
13
|
-
getDefaultLanguage,
|
|
14
|
-
getLanguageFromNextLocaleIsoCode,
|
|
15
|
-
getLanguageFromStory,
|
|
16
|
-
getNotifications,
|
|
17
|
-
LocaleObject,
|
|
18
|
-
} from '../../intl';
|
|
19
|
-
import type { PageProps, ServerSidePageProps } from '../../types';
|
|
20
|
-
import { DEFAULT_PAGE_SIZE } from '../../utils';
|
|
21
|
-
import { getAlgoliaSettings, isSdkError, isUuid } from '../lib';
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
getContactsQuery,
|
|
25
|
-
getGalleriesQuery,
|
|
26
|
-
getSlugQuery,
|
|
27
|
-
getSortByPublishedDate,
|
|
28
|
-
getStoriesQuery,
|
|
29
|
-
} from './queries';
|
|
30
|
-
|
|
31
|
-
const CATEGORIES_SORT_ORDER = '+order';
|
|
32
|
-
const DEFAULT_SORT_ORDER: SortOrder = 'desc';
|
|
33
|
-
|
|
34
|
-
const ERROR_CODE_NOT_FOUND = 404;
|
|
35
|
-
const ERROR_CODE_FORBIDDEN = 403;
|
|
36
|
-
const ERROR_CODE_GONE = 410;
|
|
37
|
-
|
|
38
|
-
type SortOrder = 'desc' | 'asc';
|
|
39
|
-
|
|
40
|
-
interface GetStoriesOptions {
|
|
41
|
-
page?: number;
|
|
42
|
-
pageSize?: number;
|
|
43
|
-
order?: SortOrder;
|
|
44
|
-
include?: (keyof ExtraStoryFields)[];
|
|
45
|
-
localeCode?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface GetGalleriesOptions {
|
|
49
|
-
page?: number;
|
|
50
|
-
pageSize?: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class PrezlyApi {
|
|
54
|
-
private readonly sdk: PrezlySDK;
|
|
55
|
-
|
|
56
|
-
private readonly newsroomUuid: Newsroom['uuid'];
|
|
57
|
-
|
|
58
|
-
private readonly themeUuid: string | undefined;
|
|
59
|
-
|
|
60
|
-
constructor(accessToken: string, newsroomUuid: Newsroom['uuid'], themeUuid?: string) {
|
|
61
|
-
const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
|
|
62
|
-
this.sdk = new PrezlySDK({
|
|
63
|
-
accessToken,
|
|
64
|
-
baseUrl,
|
|
65
|
-
// This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
|
|
66
|
-
headers: { 'X-Convert-v1-To-v3': 'true' },
|
|
67
|
-
});
|
|
68
|
-
this.newsroomUuid = newsroomUuid;
|
|
69
|
-
this.themeUuid = themeUuid;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async getStory(uuid: string) {
|
|
73
|
-
if (!isUuid(uuid)) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
return await this.sdk.stories.get(uuid);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (
|
|
81
|
-
isSdkError(error) &&
|
|
82
|
-
(error.status === ERROR_CODE_NOT_FOUND ||
|
|
83
|
-
error.status === ERROR_CODE_GONE ||
|
|
84
|
-
error.status === ERROR_CODE_FORBIDDEN)
|
|
85
|
-
) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async getNewsroom() {
|
|
93
|
-
return this.sdk.newsrooms.get(this.newsroomUuid);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async getNewsroomContacts() {
|
|
97
|
-
return this.sdk.newsroomContacts.search(this.newsroomUuid, {
|
|
98
|
-
query: JSON.stringify(getContactsQuery()),
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async getNewsroomLanguages(): Promise<NewsroomLanguageSettings[]> {
|
|
103
|
-
return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
|
|
108
|
-
*/
|
|
109
|
-
async getAllStories(order: SortOrder = DEFAULT_SORT_ORDER) {
|
|
110
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
111
|
-
const newsroom = await this.getNewsroom();
|
|
112
|
-
const jsonQuery = JSON.stringify(getStoriesQuery(newsroom.uuid));
|
|
113
|
-
const maxStories = newsroom.stories_number;
|
|
114
|
-
const chunkSize = 200;
|
|
115
|
-
|
|
116
|
-
const pages = Math.ceil(maxStories / chunkSize);
|
|
117
|
-
const storiesPromises = Array.from({ length: pages }, (_, pageIndex) =>
|
|
118
|
-
this.searchStories({
|
|
119
|
-
limit: chunkSize,
|
|
120
|
-
sortOrder,
|
|
121
|
-
jsonQuery,
|
|
122
|
-
offset: pageIndex * chunkSize,
|
|
123
|
-
}),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const stories = (await Promise.all(storiesPromises)).flatMap(
|
|
127
|
-
(response) => response.stories,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return stories;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async getStories({
|
|
134
|
-
page = undefined,
|
|
135
|
-
pageSize = DEFAULT_PAGE_SIZE,
|
|
136
|
-
order = DEFAULT_SORT_ORDER,
|
|
137
|
-
include,
|
|
138
|
-
localeCode,
|
|
139
|
-
}: GetStoriesOptions = {}) {
|
|
140
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
141
|
-
const jsonQuery = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
|
|
142
|
-
|
|
143
|
-
const { stories, pagination } = await this.searchStories({
|
|
144
|
-
limit: pageSize,
|
|
145
|
-
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
146
|
-
sortOrder,
|
|
147
|
-
jsonQuery,
|
|
148
|
-
include,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const storiesTotal = pagination.matched_records_number;
|
|
152
|
-
|
|
153
|
-
return { stories, storiesTotal };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async getStoriesFromCategory(
|
|
157
|
-
category: Category,
|
|
158
|
-
{
|
|
159
|
-
page = undefined,
|
|
160
|
-
pageSize = DEFAULT_PAGE_SIZE,
|
|
161
|
-
order = DEFAULT_SORT_ORDER,
|
|
162
|
-
include,
|
|
163
|
-
localeCode,
|
|
164
|
-
}: GetStoriesOptions = {},
|
|
165
|
-
) {
|
|
166
|
-
const sortOrder = getSortByPublishedDate(order);
|
|
167
|
-
const jsonQuery = JSON.stringify(
|
|
168
|
-
getStoriesQuery(this.newsroomUuid, category.id, localeCode),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const { stories, pagination } = await this.searchStories({
|
|
172
|
-
limit: pageSize,
|
|
173
|
-
offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
|
|
174
|
-
sortOrder,
|
|
175
|
-
jsonQuery,
|
|
176
|
-
include,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const storiesTotal = pagination.matched_records_number;
|
|
180
|
-
|
|
181
|
-
return { stories, storiesTotal };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async getStoryBySlug(slug: string) {
|
|
185
|
-
const jsonQuery = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
|
|
186
|
-
const { stories } = await this.searchStories({
|
|
187
|
-
limit: 1,
|
|
188
|
-
jsonQuery,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
if (stories[0]) {
|
|
192
|
-
return this.getStory(stories[0].uuid);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async getCategories(): Promise<Category[]> {
|
|
199
|
-
const categories = await this.sdk.newsroomCategories.list(this.newsroomUuid, {
|
|
200
|
-
sortOrder: CATEGORIES_SORT_ORDER,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
return Array.isArray(categories) ? categories : Object.values(categories);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async getCategoryBySlug(slug: string) {
|
|
207
|
-
const categories = await this.getCategories();
|
|
208
|
-
|
|
209
|
-
return categories.find((category) =>
|
|
210
|
-
Object.values(category.i18n).some((t) => t.slug === slug),
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
searchStories: typeof PrezlySDK.prototype.stories.search = (options) =>
|
|
215
|
-
this.sdk.stories.search(options);
|
|
216
|
-
|
|
217
|
-
async getGalleries({ page, pageSize }: GetGalleriesOptions) {
|
|
218
|
-
return this.sdk.newsroomGalleries.list(this.newsroomUuid, {
|
|
219
|
-
limit: pageSize,
|
|
220
|
-
offset:
|
|
221
|
-
typeof page === 'undefined' || typeof pageSize === 'undefined'
|
|
222
|
-
? undefined
|
|
223
|
-
: (page - 1) * pageSize,
|
|
224
|
-
scope: getGalleriesQuery(),
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async getGallery(uuid: string) {
|
|
229
|
-
if (!isUuid(uuid)) {
|
|
230
|
-
// Check for legacy number ID reference, which is also supported for back-compat.
|
|
231
|
-
if (Number.isNaN(Number(uuid))) {
|
|
232
|
-
return undefined;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
return await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
if (isSdkError(error) && error.status === 404) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
throw error;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
|
|
248
|
-
*/
|
|
249
|
-
async getThemePreset() {
|
|
250
|
-
if (this.themeUuid) {
|
|
251
|
-
return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async getNewsroomServerSideProps(
|
|
258
|
-
request?: IncomingMessage,
|
|
259
|
-
nextLocaleIsoCode?: string,
|
|
260
|
-
story?: Story,
|
|
261
|
-
): Promise<PageProps & ServerSidePageProps> {
|
|
262
|
-
const [newsroom, languages, categories, themePreset] = await Promise.all([
|
|
263
|
-
this.getNewsroom(),
|
|
264
|
-
this.getNewsroomLanguages(),
|
|
265
|
-
this.getCategories(),
|
|
266
|
-
this.getThemePreset(),
|
|
267
|
-
]);
|
|
268
|
-
|
|
269
|
-
const currentLanguage = story
|
|
270
|
-
? getLanguageFromStory(languages, story)
|
|
271
|
-
: getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode);
|
|
272
|
-
const defaultLanguage = getDefaultLanguage(languages);
|
|
273
|
-
|
|
274
|
-
const { code: localeCode } = currentLanguage || defaultLanguage;
|
|
275
|
-
const locale = LocaleObject.fromAnyCode(localeCode);
|
|
276
|
-
|
|
277
|
-
// TODO: if no information given for current language, show boilerplate from default language
|
|
278
|
-
const companyInformation = getCompanyInformation(languages, locale);
|
|
279
|
-
|
|
280
|
-
const notifications = getNotifications(languages, locale);
|
|
281
|
-
const algoliaSettings = getAlgoliaSettings(request);
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
newsroomContextProps: {
|
|
285
|
-
newsroom,
|
|
286
|
-
companyInformation,
|
|
287
|
-
categories,
|
|
288
|
-
languages,
|
|
289
|
-
localeCode,
|
|
290
|
-
notifications,
|
|
291
|
-
themePreset,
|
|
292
|
-
algoliaSettings,
|
|
293
|
-
},
|
|
294
|
-
localeResolved: Boolean(currentLanguage),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async getNewsroomDefaultLanguage() {
|
|
299
|
-
const languages = await this.getNewsroomLanguages();
|
|
300
|
-
return getDefaultLanguage(languages);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from 'http';
|
|
2
|
-
|
|
3
|
-
import { getEnvVariables } from '../lib/getEnvVariables';
|
|
4
|
-
|
|
5
|
-
import { PrezlyApi } from './PrezlyApi';
|
|
6
|
-
|
|
7
|
-
export function getPrezlyApi(req?: IncomingMessage): PrezlyApi {
|
|
8
|
-
if (typeof window !== 'undefined') {
|
|
9
|
-
throw new Error('"getPrezlyApi" should only be used on back-end side.');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// `getEnvVariables` handles both cases for envs parsing - .env and request headers
|
|
13
|
-
const { PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID } = getEnvVariables(req);
|
|
14
|
-
|
|
15
|
-
if (!PREZLY_ACCESS_TOKEN) {
|
|
16
|
-
throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!PREZLY_NEWSROOM_UUID) {
|
|
20
|
-
throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getPrezlyApi';
|