From a902648ee64a1b8b250faa03f95e9faab78e67a0 Mon Sep 17 00:00:00 2001 From: yangshun Date: Mon, 18 Nov 2019 21:35:42 -0800 Subject: [PATCH 1/2] feat(v2): allow hiding docs table of contents --- packages/docusaurus-plugin-content-docs/src/metadata.ts | 5 +++++ packages/docusaurus-plugin-content-docs/src/types.ts | 1 + packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 5 ++++- .../src/theme/DocItem/styles.module.css | 1 - website/docs/markdown-features.mdx | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 654f97b25716..88fbefc5b893 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -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 = diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index faaf3fb7be0c..c1985c704cb5 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -95,6 +95,7 @@ export interface MetadataRaw extends OrderMetadata { lastUpdatedAt?: number; lastUpdatedBy?: string; hide_title?: boolean; + hide_table_of_contents?: boolean; [key: string]: any; } diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 707c8f58a92f..113e513ca8ef 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -62,6 +62,7 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, keywords, + hideTableOfContents, } = metadata; const metaImageUrl = siteUrl + useBaseUrl(metaImage); @@ -172,7 +173,9 @@ function DocItem(props) { - {DocContent.rightToc && } + {!hideTableOfContents && DocContent.rightToc && ( + + )} diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/styles.module.css b/packages/docusaurus-theme-classic/src/theme/DocItem/styles.module.css index adfb5a0dc583..d1c2932c0206 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/styles.module.css +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/styles.module.css @@ -20,7 +20,6 @@ .docItemContainer { margin: 0 auto; padding: 0 0.5rem; - max-width: 45em; } .tableOfContents { diff --git a/website/docs/markdown-features.mdx b/website/docs/markdown-features.mdx index ad36da15c93c..1836099fa9f6 100644 --- a/website/docs/markdown-features.mdx +++ b/website/docs/markdown-features.mdx @@ -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. @@ -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 From 5614e253972c8ee9aa5632811770ea0dc2bfca6c Mon Sep 17 00:00:00 2001 From: endiliey Date: Tue, 19 Nov 2019 15:03:59 +0700 Subject: [PATCH 2/2] move to frontmatter --- packages/docusaurus-plugin-content-docs/src/metadata.ts | 5 ----- packages/docusaurus-plugin-content-docs/src/types.ts | 2 -- .../docusaurus-theme-classic/src/theme/DocItem/index.js | 9 +++++++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 88fbefc5b893..654f97b25716 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -111,11 +111,6 @@ 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 = diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index c1985c704cb5..23ab9b380d92 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -94,8 +94,6 @@ export interface MetadataRaw extends OrderMetadata { editUrl?: string; lastUpdatedAt?: number; lastUpdatedBy?: string; - hide_title?: boolean; - hide_table_of_contents?: boolean; [key: string]: any; } diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 113e513ca8ef..b45719bddb2a 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -62,8 +62,13 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, keywords, - hideTableOfContents, } = metadata; + const { + frontMatter: { + hide_title: hideTitle, + hide_table_of_contents: hideTableOfContents, + }, + } = DocContent; const metaImageUrl = siteUrl + useBaseUrl(metaImage); @@ -91,7 +96,7 @@ function DocItem(props) {
- {!metadata.hide_title && ( + {!hideTitle && (

{metadata.title}