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

* feat(v2): allow hiding docs table of contents

* move to frontmatter
This commit is contained in:
Yangshun Tay 2019-11-19 00:08:45 -08:00 committed by Endi
parent 1bf590ea2b
commit edf4c16c93
4 changed files with 12 additions and 4 deletions

View file

@ -94,7 +94,6 @@ export interface MetadataRaw extends OrderMetadata {
editUrl?: string; editUrl?: string;
lastUpdatedAt?: number; lastUpdatedAt?: number;
lastUpdatedBy?: string; lastUpdatedBy?: string;
hide_title?: boolean;
[key: string]: any; [key: string]: any;
} }

View file

@ -63,6 +63,12 @@ function DocItem(props) {
lastUpdatedBy, lastUpdatedBy,
keywords, keywords,
} = metadata; } = metadata;
const {
frontMatter: {
hide_title: hideTitle,
hide_table_of_contents: hideTableOfContents,
},
} = DocContent;
const metaImageUrl = siteUrl + useBaseUrl(metaImage); const metaImageUrl = siteUrl + useBaseUrl(metaImage);
@ -90,7 +96,7 @@ function DocItem(props) {
<div className="col"> <div className="col">
<div className={styles.docItemContainer}> <div className={styles.docItemContainer}>
<article> <article>
{!metadata.hide_title && ( {!hideTitle && (
<header> <header>
<h1 className={styles.docTitle}>{metadata.title}</h1> <h1 className={styles.docTitle}>{metadata.title}</h1>
</header> </header>
@ -172,7 +178,9 @@ function DocItem(props) {
</div> </div>
</div> </div>
</div> </div>
{DocContent.rightToc && <DocTOC headings={DocContent.rightToc} />} {!hideTableOfContents && DocContent.rightToc && (
<DocTOC headings={DocContent.rightToc} />
)}
</div> </div>
</div> </div>
</div> </div>

View file

@ -20,7 +20,6 @@
.docItemContainer { .docItemContainer {
margin: 0 auto; margin: 0 auto;
padding: 0 0.5rem; padding: 0 0.5rem;
max-width: 45em;
} }
.tableOfContents { .tableOfContents {

View file

@ -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). - `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`. - `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_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`. - `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`. - `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. - `keywords`: Keywords meta tag for the document page, for search engines.
@ -112,6 +113,7 @@ Example:
id: doc-markdown id: doc-markdown
title: Markdown Features title: Markdown Features
hide_title: false hide_title: false
hide_table_of_contents: false
sidebar_label: Markdown :) sidebar_label: Markdown :)
custom_edit_url: https://github.com/facebook/docusaurus/edit/master/docs/api-doc-markdown.md 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 description: How do I find you when I cannot solve this problem