@prezly/theme-kit-nextjs 1.10.2-0 → 1.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,49 @@ This function returns the combined base props and your additional props, with so
|
|
|
181
181
|
|
|
182
182
|
The third argument is needed to properly handle locale redirects. It should contain the URL for the current page without locale prefixes (like `/`, `/media`, `/category/${category.slug}`. If omitted, the redirect logic will not be executing.
|
|
183
183
|
|
|
184
|
+
**Helpers for common pages**
|
|
185
|
+
|
|
186
|
+
To reduce boilerplate for common scenarios, the library provides a collection of prop fetching methods for each of the default Prezly Newsroom pages. All of them support custom props, so you can still have minimal boilerplate with all the same customization. If you have a more specific scenario, you can still use the code shown in the beginning of this section.
|
|
187
|
+
|
|
188
|
+
Here's an example of `getServerSideProps` function with no custom props:
|
|
189
|
+
```ts
|
|
190
|
+
import { getHomepageServerSideProps } from '@prezly/theme-kit-nextjs';
|
|
191
|
+
|
|
192
|
+
/* ...your page component */
|
|
193
|
+
|
|
194
|
+
export const getServerSideProps = getHomepageServerSideProps({});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
And here's a more sophisticated scenario from Bea Theme, with extra options and custom props that depend on the Next request context and newsroom context props:
|
|
198
|
+
```ts
|
|
199
|
+
import { getHomepageServerSideProps, type HomePageProps } from '@prezly/theme-kit-nextjs';
|
|
200
|
+
import dynamic from 'next/dynamic';
|
|
201
|
+
import type { FunctionComponent } from 'react';
|
|
202
|
+
|
|
203
|
+
import { importMessages, isTrackingEnabled } from '@/utils';
|
|
204
|
+
import type { BasePageProps, StoryWithImage } from 'types';
|
|
205
|
+
|
|
206
|
+
const Stories = dynamic(() => import('@/modules/Stories'), { ssr: true });
|
|
207
|
+
|
|
208
|
+
type Props = BasePageProps & HomePageProps<StoryWithImage>;
|
|
209
|
+
|
|
210
|
+
const IndexPage: FunctionComponent<Props> = ({ stories, pagination }) => (
|
|
211
|
+
<Stories stories={stories} pagination={pagination} />
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
export const getServerSideProps = getHomepageServerSideProps<BasePageProps, StoryWithImage>(
|
|
215
|
+
async (context, { newsroomContextProps }) => ({
|
|
216
|
+
isTrackingEnabled: isTrackingEnabled(context),
|
|
217
|
+
translations: await importMessages(newsroomContextProps.localeCode),
|
|
218
|
+
}),
|
|
219
|
+
{ extraStoryFields: ['thumbnail_image'] },
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
export default IndexPage;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
You can find all of the helper methods in the [page-props](./tree/main/src/adapter-nextjs/page-props) directory. You can also refer to [Prezly Bea Theme](https://github.com/prezly/theme-nextjs-bea) for usage examples.
|
|
226
|
+
|
|
184
227
|
### SEO Helper components
|
|
185
228
|
|
|
186
229
|
This library provides two components: [PageSeo](./tree/main/src/components-nextjs/PageSeo) and [StorySeo](./tree/main/src/components-nextjs/StorySeo), both based on the [next-seo](https://github.com/garmeeh/next-seo) library. They consume information from the `NewsroomContext` and provide all the necessary tags for your pages, with correct social preview, as well as JsonLD and OpenGraph data for your stories. You can also override the parameters for `PageSeo` component, these will be passed straight to `NextSeo` component. See the JSDoc comments on the exported components to get instructions on their usage.
|