diff --git a/packages/docz-core/src/DataServer.ts b/packages/docz-core/src/DataServer.ts index 8e093179f..ec24f9c95 100644 --- a/packages/docz-core/src/DataServer.ts +++ b/packages/docz-core/src/DataServer.ts @@ -80,6 +80,7 @@ export class DataServer { ...config.themeConfig, title: config.title, description: config.description, + ordering: config.ordering, }) } diff --git a/packages/docz-core/src/commands/args.ts b/packages/docz-core/src/commands/args.ts index 12c1e4bef..057003485 100644 --- a/packages/docz-core/src/commands/args.ts +++ b/packages/docz-core/src/commands/args.ts @@ -33,6 +33,7 @@ export interface Argv { title: string description: string theme: string + ordering: 'ascending' | 'descending' wrapper?: string indexHtml?: string } @@ -97,6 +98,10 @@ export const args = (yargs: any) => { yargs.positional('indexHtml', { type: 'string', }) + yargs.positional('ordering', { + type: 'string', + default: 'descending', + }) yargs.positional('debug', { type: 'boolean', default: process.env.DEBUG || false, diff --git a/packages/docz/src/components/Docs.tsx b/packages/docz/src/components/Docs.tsx index 1e66708e1..496e5e9a8 100644 --- a/packages/docz/src/components/Docs.tsx +++ b/packages/docz/src/components/Docs.tsx @@ -36,7 +36,7 @@ export const Docs: React.SFC = ({ children }) => { return ( - {({ entries }) => { + {({ entries, config }) => { if (!entries || !children) return null if (!isFn(children)) { throw new Error( @@ -51,7 +51,12 @@ export const Docs: React.SFC = ({ children }) => { const docs = entriesArr .sort((a, b) => sortBy(a.name, b.name)) - .sort((a, b) => b.order - a.order) + .sort( + (a, b) => + config.ordering === 'descending' + ? b.order - a.order + : a.order - b.order + ) return Children.only( children({