mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 19:27:48 +02:00
feat(v2): add optional custom wrapper class name for pages based on theme classic Layout (#3457)
* feat(v2): add optional custom wrapper class name for pages based on theme classic Layout * feat(v2): add optional custom wrapper class name for markdown pages * fix TS types
This commit is contained in:
parent
0ad8958438
commit
f9944cb2fc
5 changed files with 12 additions and 3 deletions
|
@ -13,6 +13,7 @@ declare module '@theme/MDXPage' {
|
||||||
readonly frontMatter: {
|
readonly frontMatter: {
|
||||||
readonly title: string;
|
readonly title: string;
|
||||||
readonly description: string;
|
readonly description: string;
|
||||||
|
readonly wrapperClassName?: string;
|
||||||
};
|
};
|
||||||
readonly metadata: {readonly permalink: string};
|
readonly metadata: {readonly permalink: string};
|
||||||
readonly rightToc: readonly MarkdownRightTableOfContents[];
|
readonly rightToc: readonly MarkdownRightTableOfContents[];
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import clsx from 'clsx';
|
||||||
import Head from '@docusaurus/Head';
|
import Head from '@docusaurus/Head';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||||
|
@ -43,6 +44,7 @@ function Layout(props: Props): JSX.Element {
|
||||||
image,
|
image,
|
||||||
keywords,
|
keywords,
|
||||||
permalink,
|
permalink,
|
||||||
|
wrapperClassName,
|
||||||
} = props;
|
} = props;
|
||||||
const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle;
|
const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle;
|
||||||
const metaImage = image || defaultImage;
|
const metaImage = image || defaultImage;
|
||||||
|
@ -87,7 +89,7 @@ function Layout(props: Props): JSX.Element {
|
||||||
|
|
||||||
<AnnouncementBar />
|
<AnnouncementBar />
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<div className="main-wrapper">{children}</div>
|
<div className={clsx('main-wrapper', wrapperClassName)}>{children}</div>
|
||||||
{!noFooter && <Footer />}
|
{!noFooter && <Footer />}
|
||||||
</Providers>
|
</Providers>
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,11 +14,15 @@ import type {Props} from '@theme/MDXPage';
|
||||||
function MDXPage(props: Props): JSX.Element {
|
function MDXPage(props: Props): JSX.Element {
|
||||||
const {content: MDXPageContent} = props;
|
const {content: MDXPageContent} = props;
|
||||||
const {frontMatter, metadata} = MDXPageContent;
|
const {frontMatter, metadata} = MDXPageContent;
|
||||||
const {title, description} = frontMatter;
|
const {title, description, wrapperClassName} = frontMatter;
|
||||||
const {permalink} = metadata;
|
const {permalink} = metadata;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout title={title} description={description} permalink={permalink}>
|
<Layout
|
||||||
|
title={title}
|
||||||
|
description={description}
|
||||||
|
permalink={permalink}
|
||||||
|
wrapperClassName={wrapperClassName}>
|
||||||
<main>
|
<main>
|
||||||
<div className="container margin-vert--lg padding-vert--lg">
|
<div className="container margin-vert--lg padding-vert--lg">
|
||||||
<MDXProvider components={MDXComponents}>
|
<MDXProvider components={MDXComponents}>
|
||||||
|
|
|
@ -245,6 +245,7 @@ declare module '@theme/Layout' {
|
||||||
image?: string;
|
image?: string;
|
||||||
keywords?: string[];
|
keywords?: string[];
|
||||||
permalink?: string;
|
permalink?: string;
|
||||||
|
wrapperClassName?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Layout: (props: Props) => JSX.Element;
|
const Layout: (props: Props) => JSX.Element;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
title: Markdown Page example title
|
title: Markdown Page example title
|
||||||
description: Markdown Page example description
|
description: Markdown Page example description
|
||||||
|
wrapperClassName: docusaurus-markdown-example
|
||||||
---
|
---
|
||||||
|
|
||||||
# Markdown page
|
# Markdown page
|
||||||
|
|
Loading…
Add table
Reference in a new issue