Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): allow hiding docs table of contents #2012

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export default async function processMetadata({
delete metadata.custom_edit_url;
}

if (metadata.hide_table_of_contents) {
metadata.hideTableOfContents = Boolean(metadata.hide_table_of_contents);
delete metadata.hide_table_of_contents;
}

if (showLastUpdateAuthor || showLastUpdateTime) {
// Use fake data in dev for faster development
const fileLastUpdateData =
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface MetadataRaw extends OrderMetadata {
lastUpdatedAt?: number;
lastUpdatedBy?: string;
hide_title?: boolean;
hide_table_of_contents?: boolean;
[key: string]: any;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-theme-classic/src/theme/DocItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function DocItem(props) {
lastUpdatedAt,
lastUpdatedBy,
keywords,
hideTableOfContents,
} = metadata;

const metaImageUrl = siteUrl + useBaseUrl(metaImage);
Expand Down Expand Up @@ -172,7 +173,9 @@ function DocItem(props) {
</div>
</div>
</div>
{DocContent.rightToc && <DocTOC headings={DocContent.rightToc} />}
{!hideTableOfContents && DocContent.rightToc && (
<DocTOC headings={DocContent.rightToc} />
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
.docItemContainer {
margin: 0 auto;
padding: 0 0.5rem;
max-width: 45em;
}

.tableOfContents {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/markdown-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Documents use the following markdown header fields that are enclosed by a line `
- `id`: A unique document id. If this field is not present, the document's `id` will default to its file name (without the extension).
- `title`: The title of your document. If this field is not present, the document's `title` will default to its `id`.
- `hide_title`: Whether to hide the title at the top of the doc. By default it is `false`.
- `hide_table_of_contents`: Whether to hide the table of contents to the right. By default it is `false`.
- `sidebar_label`: The text shown in the document sidebar and in the next/previous button for this document. If this field is not present, the document's `sidebar_label` will default to its `title`.
- `custom_edit_url`: The URL for editing this document. If this field is not present, the document's edit URL will fall back to `editUrl` from options fields passed to `docusaurus-plugin-content-docs`.
- `keywords`: Keywords meta tag for the document page, for search engines.
Expand All @@ -112,6 +113,7 @@ Example:
id: doc-markdown
title: Markdown Features
hide_title: false
hide_table_of_contents: false
sidebar_label: Markdown :)
custom_edit_url: https://github.com/facebook/docusaurus/edit/master/docs/api-doc-markdown.md
description: How do I find you when I cannot solve this problem
Expand Down