Skip to content

Commit

Permalink
docs: update simplified nextjs config
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 13, 2021
1 parent 7270cf3 commit 1870bea
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions examples/stories/src/tutorial/getting-started/ssg/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,15 @@ Create a new or edit `index.tsx` or `index.js` file in the pages folder:
import React from 'react';
import { GetStaticProps } from 'next';
import {
DocPageTemplate,
NextLayout,
store,
getIndexPage,
} from '@component-controls/nextjs-plugin';

const HomePage: typeof DocPageTemplate = props => (
<DocPageTemplate {...props} />
);
const HomePage: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticProps: GetStaticProps = async () => {
const homePage = getIndexPage(store);
const { docId = null, type = null, storyId = null } = homePage;
return { props: { docId, type, storyId } };
return { props: getIndexPage(store) };
};

export default HomePage;
Expand All @@ -143,23 +139,21 @@ Create a new `[doctype].tsx` or `[doctype].js` file in the pages folder:
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocHomeTemplate,
NextLayout,
store,
getHomePagesPaths,
getDocHomePage,
} from '@component-controls/nextjs-plugin';

const DocHome: typeof DocHomeTemplate = props => <DocHomeTemplate {...props} />;
const DocHome: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getHomePagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype: basepath } = params as { doctype: string };
const page = getDocHomePage(store, basepath);
const { type = null, docId = null, storyId = null } = page || {};
return { props: { docId, storyId, type } };
return { props: getDocHomePage(store, basepath) };
};

export default DocHome;
Expand All @@ -183,29 +177,21 @@ mkdir pages/[doctype]
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocPageTemplate,
NextLayout,
store,
getDocPagesPaths,
getDocPage,
} from '@component-controls/nextjs-plugin';

const DocPage: typeof DocPageTemplate = props => <DocPageTemplate {...props} />;
const DocPage: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getDocPagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype, docid } = params as { doctype: string; docid: string[] };
const page = getDocPage(store, doctype, docid);
const {
type = null,
docId = null,
storyId = null,
category = null,
activeTab = null,
} = page || {};
return { props: { docId, type, storyId, category, activeTab } };
return { props: getDocPage(store, doctype, docid) };
};

export default DocPage;
Expand Down

0 comments on commit 1870bea

Please sign in to comment.