Skip to content

Commit

Permalink
feat: new page types for tags and authors
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 11, 2020
1 parent 4f8ce12 commit 9718fee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
26 changes: 21 additions & 5 deletions core/specification/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StoryRenderFn } from './utility';

export type PageType = 'story' | 'blog' | 'page';
export type PageType = 'story' | 'blog' | 'page' | 'tag' | 'author';

export interface PageConfiguration {
/**
Expand All @@ -14,9 +14,7 @@ export interface PageConfiguration {
label?: string;
}

export interface PagesConfiguration {
[key: string]: PageConfiguration;
}
export type PagesConfiguration = Record<PageType, PageConfiguration>;

/**
* global configuration used at build time
Expand All @@ -32,7 +30,7 @@ export interface BuildConfiguration {
/**
* base url path for API documentation pages. Default is "docs/"
*/
pages?: { [key: string]: Pick<PageConfiguration, 'basePath'> };
pages?: Record<PageType, Pick<PageConfiguration, 'basePath'>>;
}

/**
Expand Down Expand Up @@ -110,6 +108,15 @@ export const defaultRunConfig: RunConfiguration = {
blog: {
label: 'Blog',
},
author: {
label: 'Author',
},
page: {
label: 'Page',
},
tag: {
label: 'Tag',
},
},
};

Expand All @@ -121,5 +128,14 @@ export const defaultBuildConfig: BuildConfiguration = {
blog: {
basePath: 'blogs/',
},
author: {
basePath: 'authors/',
},
page: {
basePath: 'pages/',
},
tag: {
basePath: 'tags/',
},
},
};
61 changes: 35 additions & 26 deletions integrations/gatsby-theme-stories/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getDocPath, PageType } from '@component-controls/specification';
import {
getDocPath,
PageType,
BuildPageConfig,
} from '@component-controls/specification';

import {
compile,
Expand All @@ -25,45 +29,50 @@ exports.createPages = async (
story: require.resolve(`../src/templates/DocPage.tsx`),
blog: require.resolve(`../src/templates/BlogPage.tsx`),
page: require.resolve(`../src/templates/PagePage.tsx`),
tag: require.resolve(`../src/templates/PagePage.tsx`),
author: require.resolve(`../src/templates/PagePage.tsx`),
};
const listTemplates: Record<PageType, string> = {
story: require.resolve(`../src/templates/DocPage.tsx`),
blog: require.resolve(`../src/templates/PageList.tsx`),
page: require.resolve(`../src/templates/PagePage.tsx`),
tag: require.resolve(`../src/templates/PagePage.tsx`),
author: require.resolve(`../src/templates/PagePage.tsx`),
};

const { store } =
process.env.NODE_ENV === 'development'
? await watch(config)
: await compile(config);
if (store) {
const { pages = {} } = store.buildConfig || {};
Object.keys(pages).forEach(type => {
const page = pages[type];
const pageType = type as PageType;
const docs = store.getDocs(pageType);
docs.forEach(doc => {
createPage({
path: getDocPath(pageType, doc, store.buildConfig),
component: pageTemplates[pageType],
context: {
doc: doc.title,
},
const { pages } = store.buildConfig || {};
if (pages) {
Object.keys(pages).forEach(type => {
const page: BuildPageConfig = pages[type as PageType];
const pageType = type as PageType;
const docs = store.getDocs(pageType);
docs.forEach(doc => {
createPage({
path: getDocPath(pageType, doc, store.buildConfig),
component: pageTemplates[pageType],
context: {
doc: doc.title,
},
});
});
if (docs.length) {
const docsPage = docs.find(doc => doc?.route === `/${page.basePath}`);
createPage({
path: `/${page.basePath}`,
component: listTemplates[pageType],
context: {
type: pageType,
doc: docsPage?.title,
},
});
}
});
if (docs.length) {
const docsPage = docs.find(doc => doc?.route === `/${page.basePath}`);
createPage({
path: `/${page.basePath}`,
component: listTemplates[pageType],
context: {
type: pageType,
doc: docsPage?.title,
},
});
}
});

}
const homePage = store.stores.find(s => s.doc?.route === '/');
createPage({
path: `/`,
Expand Down

0 comments on commit 9718fee

Please sign in to comment.