Skip to content

Commit

Permalink
feat(docz-core): add ordering property for config
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 3, 2018
1 parent 7886e75 commit efd215e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/docz-core/src/DataServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class DataServer {
...config.themeConfig,
title: config.title,
description: config.description,
ordering: config.ordering,
})
}

Expand Down
5 changes: 5 additions & 0 deletions packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Argv {
title: string
description: string
theme: string
ordering: 'ascending' | 'descending'
wrapper?: string
indexHtml?: string
}
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions packages/docz/src/components/Docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Docs: React.SFC<DocsProps> = ({ children }) => {

return (
<dataContext.Consumer>
{({ entries }) => {
{({ entries, config }) => {
if (!entries || !children) return null
if (!isFn(children)) {
throw new Error(
Expand All @@ -51,7 +51,12 @@ export const Docs: React.SFC<DocsProps> = ({ 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({
Expand Down

0 comments on commit efd215e

Please sign in to comment.