From a8b08d25cbaf5b3bae6db47509b42d6f85869704 Mon Sep 17 00:00:00 2001 From: Mickael Zhang Date: Fri, 10 Jan 2020 19:10:42 +0100 Subject: [PATCH] feat: add the ability to hide a document from the menu --- core/docz-core/src/lib/Entry.ts | 2 ++ core/gatsby-theme-docz/src/components/NavLink/index.js | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/docz-core/src/lib/Entry.ts b/core/docz-core/src/lib/Entry.ts index 17e8b463e..a2a7b395c 100644 --- a/core/docz-core/src/lib/Entry.ts +++ b/core/docz-core/src/lib/Entry.ts @@ -39,6 +39,7 @@ export class Entry { public readonly fullpath: string public readonly headings: Heading[] public readonly id: string + public readonly hidden: boolean public readonly menu: string | null public readonly name: string public readonly route: string @@ -57,6 +58,7 @@ export class Entry { this.filepath = filepath this.fullpath = path.resolve(root, file) this.link = '' + this.hidden = parsed.hidden || false this.slug = this.slugify(filepath, config.separator) this.route = this.getRoute(parsed) this.name = name diff --git a/core/gatsby-theme-docz/src/components/NavLink/index.js b/core/gatsby-theme-docz/src/components/NavLink/index.js index 5b6bcdce7..73272e24d 100644 --- a/core/gatsby-theme-docz/src/components/NavLink/index.js +++ b/core/gatsby-theme-docz/src/components/NavLink/index.js @@ -22,9 +22,14 @@ const getCurrentHash = () => { export const NavLink = React.forwardRef(({ item, ...props }, ref) => { const docs = useDocs() + const current = useCurrentDoc() + + if (item.hidden) { + return null + } + const to = item.route const headings = docs && getHeadings(to, docs) - const current = useCurrentDoc() const isCurrent = item.route === current.route const showHeadings = isCurrent && headings && headings.length > 0 const currentHash = getCurrentHash()