@prezly/theme-kit-nextjs 4.2.0-alpha.2 → 4.2.0-alpha.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/cjs/components-nextjs/PageSeo/PageSeo.js +1 -0
- package/build/cjs/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/cjs/components-nextjs/StorySeo/StorySeo.js +1 -0
- package/build/cjs/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/cjs/components-nextjs/document.js +1 -0
- package/build/cjs/components-nextjs/document.js.map +1 -1
- package/build/cjs/newsroom-context/context.js +1 -0
- package/build/cjs/newsroom-context/context.js.map +1 -1
- package/build/esm/components-nextjs/PageSeo/PageSeo.js +1 -0
- package/build/esm/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/esm/components-nextjs/StorySeo/StorySeo.js +1 -0
- package/build/esm/components-nextjs/StorySeo/StorySeo.js.map +1 -1
- package/build/esm/components-nextjs/document.js +1 -0
- package/build/esm/components-nextjs/document.js.map +1 -1
- package/build/esm/newsroom-context/context.js +1 -0
- package/build/esm/newsroom-context/context.js.map +1 -1
- package/build/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/__mocks__/languages.ts +0 -479
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +0 -24
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +0 -43
- 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 -156
- 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 -131
- 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 -45
- 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 -96
- package/src/adapter-nextjs/page-props/storyPreview.ts +0 -33
- package/src/adapter-nextjs/processRequest.ts +0 -50
- package/src/adapter-nextjs/processStaticRequest.ts +0 -32
- package/src/components-nextjs/PageSeo/PageSeo.tsx +0 -132
- package/src/components-nextjs/PageSeo/index.ts +0 -1
- package/src/components-nextjs/PageSeo/lib/getAbsoluteUrl.ts +0 -7
- package/src/components-nextjs/PageSeo/lib/index.ts +0 -1
- package/src/components-nextjs/StorySeo/StorySeo.tsx +0 -87
- package/src/components-nextjs/StorySeo/index.ts +0 -1
- package/src/components-nextjs/document.tsx +0 -37
- package/src/components-nextjs/index.ts +0 -3
- package/src/data-fetching/NextPrezlyApi.ts +0 -57
- package/src/data-fetching/getNextPrezlyApi.ts +0 -23
- package/src/data-fetching/index.ts +0 -1
- package/src/index.ts +0 -8
- package/src/infinite-loading/index.ts +0 -4
- package/src/infinite-loading/types.ts +0 -9
- package/src/infinite-loading/useInfiniteGalleriesLoading.ts +0 -54
- package/src/infinite-loading/useInfiniteLoading.ts +0 -67
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +0 -94
- package/src/intl/index.ts +0 -2
- package/src/intl/languages.test.ts +0 -37
- package/src/intl/languages.ts +0 -40
- package/src/intl/locale.test.ts +0 -42
- package/src/intl/locale.ts +0 -39
- package/src/newsroom-context/context.tsx +0 -114
- 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 -36
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +0 -99
- 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 -10
- package/src/sentry/common.ts +0 -82
- package/src/sentry/index.ts +0 -2
- package/src/sentry/server.ts +0 -10
- package/src/types.ts +0 -16
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { Category, ExtendedStory } from '@prezly/sdk';
|
|
2
|
-
import { Story } from '@prezly/sdk';
|
|
3
|
-
import type { LocaleObject } from '@prezly/theme-kit-core';
|
|
4
|
-
import { getCategoryHasTranslation, getCategoryUrl } from '@prezly/theme-kit-core';
|
|
5
|
-
import { useRouter } from 'next/router';
|
|
6
|
-
import { useCallback } from 'react';
|
|
7
|
-
|
|
8
|
-
import { useCurrentCategory } from './useCurrentCategory';
|
|
9
|
-
import { useCurrentStory } from './useCurrentStory';
|
|
10
|
-
|
|
11
|
-
// Pulled from SDK types to not leak the `@prezly/sdk` dependency into the client bundle
|
|
12
|
-
// It looks like a hack, but the name of enum must be the same as in SDK
|
|
13
|
-
enum Visibility {
|
|
14
|
-
PUBLIC = 'public',
|
|
15
|
-
EMBARGO = 'embargo',
|
|
16
|
-
PRIVATE = 'private',
|
|
17
|
-
CONFIDENTIAL = 'confidential',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getAllowedTranslationVisibilityValues(story: ExtendedStory): Visibility[] {
|
|
21
|
-
const { visibility } = story;
|
|
22
|
-
|
|
23
|
-
switch (visibility) {
|
|
24
|
-
case Visibility.EMBARGO:
|
|
25
|
-
return [Visibility.EMBARGO, Visibility.PUBLIC];
|
|
26
|
-
case Visibility.PRIVATE:
|
|
27
|
-
return [Visibility.PRIVATE, Visibility.PUBLIC];
|
|
28
|
-
case Visibility.CONFIDENTIAL:
|
|
29
|
-
return [Visibility.CONFIDENTIAL, Visibility.PRIVATE, Visibility.PUBLIC];
|
|
30
|
-
default:
|
|
31
|
-
return [Visibility.PUBLIC];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Determine correct URL for translated stories/categories with a fallback to homepage.
|
|
37
|
-
* E.g. if a story has a translation, the function will return the localized slug URL.
|
|
38
|
-
* If there is no translation for the story, it will return the index page URL (`/`),
|
|
39
|
-
* or empty string, if `noFallback` is set to `true` (this is useful for alternate locale links).
|
|
40
|
-
*/
|
|
41
|
-
function getTranslationUrl(
|
|
42
|
-
locale: LocaleObject,
|
|
43
|
-
path: string,
|
|
44
|
-
currentCategory?: Category,
|
|
45
|
-
currentStory?: ExtendedStory,
|
|
46
|
-
noFallback?: boolean,
|
|
47
|
-
) {
|
|
48
|
-
if (currentCategory) {
|
|
49
|
-
if (getCategoryHasTranslation(currentCategory, locale)) {
|
|
50
|
-
return getCategoryUrl(currentCategory, locale);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (noFallback) {
|
|
54
|
-
return '';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return '/';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const localeCode = locale.toUnderscoreCode();
|
|
61
|
-
|
|
62
|
-
if (currentStory && currentStory.culture.locale !== localeCode) {
|
|
63
|
-
const allowedVisibilityValues = getAllowedTranslationVisibilityValues(currentStory);
|
|
64
|
-
|
|
65
|
-
const translatedStory = currentStory.translations.find(
|
|
66
|
-
({ culture, lifecycle_status, visibility }) =>
|
|
67
|
-
culture.locale === localeCode &&
|
|
68
|
-
Story.isPublished(lifecycle_status) &&
|
|
69
|
-
allowedVisibilityValues.includes(visibility),
|
|
70
|
-
);
|
|
71
|
-
if (translatedStory) {
|
|
72
|
-
return `/${translatedStory.slug}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (noFallback) {
|
|
76
|
-
return '';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return '/';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return path;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* This hook returns a function that is meant to be used in language pickers and alternate locales list for the pages.
|
|
87
|
-
* `noFallback` parameter is useful for alternate language links in the `head` section of the document (so that there are no unwanted links to the homepage).
|
|
88
|
-
*/
|
|
89
|
-
export function useGetTranslationUrl() {
|
|
90
|
-
const { asPath } = useRouter();
|
|
91
|
-
const currentCategory = useCurrentCategory();
|
|
92
|
-
const currentStory = useCurrentStory();
|
|
93
|
-
|
|
94
|
-
return useCallback(
|
|
95
|
-
(locale: LocaleObject, noFallback?: boolean) =>
|
|
96
|
-
getTranslationUrl(locale, asPath, currentCategory, currentStory, noFallback),
|
|
97
|
-
[asPath, currentCategory, currentStory],
|
|
98
|
-
);
|
|
99
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { NewsroomContextType } from '../context';
|
|
4
|
-
import { NewsroomContext } from '../context';
|
|
5
|
-
|
|
6
|
-
export function useNewsroomContext() {
|
|
7
|
-
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
8
|
-
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
9
|
-
const newsroomContext: NewsroomContextType | undefined = useContext(NewsroomContext);
|
|
10
|
-
if (!newsroomContext) {
|
|
11
|
-
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return newsroomContext;
|
|
15
|
-
}
|
package/src/sentry/client.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { init } from '@sentry/nextjs';
|
|
2
|
-
|
|
3
|
-
import { getCommonClientOptions } from './common';
|
|
4
|
-
|
|
5
|
-
export function getSentryClientOptions(
|
|
6
|
-
dsn: string,
|
|
7
|
-
themeName: string | null,
|
|
8
|
-
): Parameters<typeof init>[0] {
|
|
9
|
-
return getCommonClientOptions(dsn, themeName);
|
|
10
|
-
}
|
package/src/sentry/common.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Exception, init, StackFrame } from '@sentry/nextjs';
|
|
2
|
-
|
|
3
|
-
const IGNORED_EVENT_CULPRITS = [
|
|
4
|
-
// This usually means that something happened outside of application code.
|
|
5
|
-
// All instances of errors with this origin that I found usually were caused by referring to variables that couldn't ever exist in our code.
|
|
6
|
-
// Likely misbehaving browser extensions or people playing around in DevTools trying to break the app.
|
|
7
|
-
'<anonymous>',
|
|
8
|
-
'?(<anonymous>)',
|
|
9
|
-
'global code',
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
function shouldStackFrameBeIgnored(frame: StackFrame) {
|
|
13
|
-
const { abs_path, function: frameFunction } = frame;
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
abs_path &&
|
|
17
|
-
IGNORED_EVENT_CULPRITS.some((ignoredCulprit) => abs_path.includes(ignoredCulprit))
|
|
18
|
-
) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
frameFunction &&
|
|
24
|
-
IGNORED_EVENT_CULPRITS.some((ignoredCulprit) => frameFunction.includes(ignoredCulprit))
|
|
25
|
-
) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function shouldExceptionBeIgnored(exception: Exception) {
|
|
33
|
-
const { stacktrace } = exception;
|
|
34
|
-
|
|
35
|
-
// Ignore global code errors that are not related to the application code.
|
|
36
|
-
// See comments in `IGNORED_EVENT_CULPRITS` const for context on each entry
|
|
37
|
-
if (stacktrace && stacktrace.frames?.some(shouldStackFrameBeIgnored)) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getCommonClientOptions(
|
|
45
|
-
dsn: string,
|
|
46
|
-
themeName: string | null,
|
|
47
|
-
): Parameters<typeof init>[0] {
|
|
48
|
-
return {
|
|
49
|
-
dsn,
|
|
50
|
-
// Adjust this value in production, or use tracesSampler for greater control
|
|
51
|
-
tracesSampleRate: 0.02,
|
|
52
|
-
// ...
|
|
53
|
-
// Note: if you want to override the automatic release value, do not set a
|
|
54
|
-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
|
|
55
|
-
// that it will also get attached to your source maps
|
|
56
|
-
|
|
57
|
-
ignoreErrors: [
|
|
58
|
-
// This particular error is coming from Microsoft Outlook SafeLink crawler.
|
|
59
|
-
// It doesn't affect the user experience in any way, but produces a lot of unwanted Sentry events.
|
|
60
|
-
// See https://forum.sentry.io/t/unhandledrejection-non-error-promise-rejection-captured-with-value/14062
|
|
61
|
-
'Object Not Found Matching Id',
|
|
62
|
-
// This error is caused by `beacon.min.js` polyfill in Cloudflare Insights. From what we see, it doesn't affect the user experience.
|
|
63
|
-
'Illegal invocation',
|
|
64
|
-
],
|
|
65
|
-
|
|
66
|
-
beforeSend: (event) => {
|
|
67
|
-
if (event.exception?.values?.every(shouldExceptionBeIgnored)) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return event;
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
// Attach theme tag to each event
|
|
75
|
-
initialScope: (scope) => {
|
|
76
|
-
if (themeName) {
|
|
77
|
-
scope.setTags({ prezly_theme: themeName });
|
|
78
|
-
}
|
|
79
|
-
return scope;
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
package/src/sentry/index.ts
DELETED
package/src/sentry/server.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { init } from '@sentry/nextjs';
|
|
2
|
-
|
|
3
|
-
import { getCommonClientOptions } from './common';
|
|
4
|
-
|
|
5
|
-
export function getSentryServerOptions(
|
|
6
|
-
dsn: string,
|
|
7
|
-
themeName: string | null,
|
|
8
|
-
): Parameters<typeof init>[0] {
|
|
9
|
-
return getCommonClientOptions(dsn, themeName);
|
|
10
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { NewsroomContextProps } from './newsroom-context';
|
|
2
|
-
|
|
3
|
-
export interface ServerSidePageProps {
|
|
4
|
-
/**
|
|
5
|
-
* Indicates whether the locale requested by the Next application was correctly resolved to an active newsroom locale.
|
|
6
|
-
* This is used by `processRequest` method to redirect to the default locale if the property is `false`.
|
|
7
|
-
*/
|
|
8
|
-
localeResolved: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* These are the props returned by the `processRequest` method that are meant to be passed to your `_app` to be injected into the `NewsroomContextProvider`.
|
|
13
|
-
*/
|
|
14
|
-
export interface PageProps {
|
|
15
|
-
newsroomContextProps: NewsroomContextProps;
|
|
16
|
-
}
|