From 9718fee13ebcef27220eb7f6d899d2df631b9a7a Mon Sep 17 00:00:00 2001 From: atanasster Date: Thu, 11 Jun 2020 01:38:40 -0400 Subject: [PATCH] feat: new page types for tags and authors --- core/specification/src/configuration.ts | 26 ++++++-- .../gatsby-theme-stories/src/gatsby-node.ts | 61 +++++++++++-------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/core/specification/src/configuration.ts b/core/specification/src/configuration.ts index 4e1ffad34..86b19ea38 100644 --- a/core/specification/src/configuration.ts +++ b/core/specification/src/configuration.ts @@ -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 { /** @@ -14,9 +14,7 @@ export interface PageConfiguration { label?: string; } -export interface PagesConfiguration { - [key: string]: PageConfiguration; -} +export type PagesConfiguration = Record; /** * global configuration used at build time @@ -32,7 +30,7 @@ export interface BuildConfiguration { /** * base url path for API documentation pages. Default is "docs/" */ - pages?: { [key: string]: Pick }; + pages?: Record>; } /** @@ -110,6 +108,15 @@ export const defaultRunConfig: RunConfiguration = { blog: { label: 'Blog', }, + author: { + label: 'Author', + }, + page: { + label: 'Page', + }, + tag: { + label: 'Tag', + }, }, }; @@ -121,5 +128,14 @@ export const defaultBuildConfig: BuildConfiguration = { blog: { basePath: 'blogs/', }, + author: { + basePath: 'authors/', + }, + page: { + basePath: 'pages/', + }, + tag: { + basePath: 'tags/', + }, }, }; diff --git a/integrations/gatsby-theme-stories/src/gatsby-node.ts b/integrations/gatsby-theme-stories/src/gatsby-node.ts index e915b3dbd..81500b054 100644 --- a/integrations/gatsby-theme-stories/src/gatsby-node.ts +++ b/integrations/gatsby-theme-stories/src/gatsby-node.ts @@ -1,4 +1,8 @@ -import { getDocPath, PageType } from '@component-controls/specification'; +import { + getDocPath, + PageType, + BuildPageConfig, +} from '@component-controls/specification'; import { compile, @@ -25,11 +29,15 @@ 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 = { 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 } = @@ -37,33 +45,34 @@ exports.createPages = async ( ? 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: `/`,