refactor(v2): move themes components from docs blog (#1571)

* refactor(v2): move themes from docs blog

* move mdxprovider to docs and blog only
This commit is contained in:
Endi 2019-06-06 16:53:47 +07:00 committed by GitHub
parent e486d3d1b0
commit f0d5313d48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 33 additions and 27 deletions

View file

@ -17,10 +17,8 @@
},
"peerDependencies": {
"@docusaurus/core": "^2.0.0",
"classnames": "^2.2.6",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-config": "^5.0.1"
"react-dom": "^16.8.4"
},
"engines": {
"node": ">=8"

View file

@ -155,10 +155,6 @@ module.exports = function(context, opts) {
});
},
getThemePath() {
return path.resolve(__dirname, './theme');
},
configureWebpack(config, isServer, {getBabelLoader, getCacheLoader}) {
const {rehypePlugins, remarkPlugins} = options;
return {

View file

@ -1,69 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import Head from '@docusaurus/Head';
import DocPaginator from '@theme/DocPaginator';
import styles from './styles.module.css';
function Headings({headings, isChild}) {
if (!headings.length) return null;
return (
<ul className={isChild ? '' : 'contents contents__left-border'}>
{headings.map(heading => (
<li key={heading.id}>
<a href={`#${heading.id}`} className="contents__link">
{heading.value}
</a>
<Headings isChild headings={heading.children} />
</li>
))}
</ul>
);
}
function DocItem(props) {
const {metadata, content: DocContent, docsMetadata} = props;
return (
<div>
<Head>
{metadata && metadata.title && <title>{metadata.title}</title>}
</Head>
<div className="padding-vert--lg">
<div className="row">
<div className="col">
<div className={styles.docItemContainer}>
<header>
<h1 className="margin-bottom--lg">{metadata.title}</h1>
</header>
<article>
<div className="markdown">
<DocContent />
</div>
</article>
<div className="margin-top--xl margin-bottom--lg">
<DocPaginator docsMetadata={docsMetadata} metadata={metadata} />
</div>
</div>
</div>
{DocContent.rightToc && (
<div className="col col--3">
<div className={styles.tableOfContents}>
<Headings headings={DocContent.rightToc} />
</div>
</div>
)}
</div>
</div>
</div>
);
}
export default DocItem;

View file

@ -1,26 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
@media (min-width: 997px) {
.docItemContainer {
padding-left: 2rem;
}
}
.tableOfContents {
display: inherit;
max-height: calc(100vh - (var(--ifm-navbar-height) + 2rem));
overflow-y: auto;
position: sticky;
top: calc(var(--ifm-navbar-height) + 2rem);
}
@media only screen and (max-width: 996px) {
.tableOfContents {
display: none;
}
}

View file

@ -1,40 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import {renderRoutes} from 'react-router-config';
import Layout from '@theme/Layout'; // eslint-disable-line
import DocSidebar from '@theme/DocSidebar';
function DocPage(props) {
const {route, docsMetadata, location} = props;
const {permalinkToId} = docsMetadata;
const id =
permalinkToId[location.pathname] ||
permalinkToId[location.pathname.replace(/\/$/, '')];
const metadata = docsMetadata.docs[id] || {};
const {sidebar, description} = metadata;
return (
<Layout noFooter description={description}>
<div className="container container--fluid">
<div className="row">
<div className="col col--3">
<DocSidebar docsMetadata={docsMetadata} sidebar={sidebar} />
</div>
<main className="col">
{renderRoutes(route.routes, {docsMetadata})}
</main>
</div>
</div>
</Layout>
);
}
export default DocPage;

View file

@ -1,47 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import Link from '@docusaurus/Link';
function DocPaginator(props) {
const {
docsMetadata: {docs},
metadata,
} = props;
return (
<nav className="pagination-nav">
<div className="pagination-nav__item">
{metadata.previous && docs[metadata.previous] && (
<Link
className="pagination-nav__link"
to={docs[metadata.previous].permalink}>
<h5 className="pagination-nav__link--sublabel">Previous</h5>
<h4 className="pagination-nav__link--label">
&laquo; {metadata.previous_title}
</h4>
</Link>
)}
</div>
<div className="pagination-nav__item pagination-nav__item--next">
{metadata.next && docs[metadata.next] && (
<Link
className="pagination-nav__link"
to={docs[metadata.next].permalink}>
<h5 className="pagination-nav__link--sublabel">Next</h5>
<h4 className="pagination-nav__link--label">
{metadata.next_title} &raquo;
</h4>
</Link>
)}
</div>
</nav>
);
}
export default DocPaginator;

View file

@ -1,130 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, {useState} from 'react';
import classnames from 'classnames';
import Link from '@docusaurus/Link'; // eslint-disable-line
import styles from './styles.module.css';
const MOBILE_TOGGLE_SIZE = 24;
function DocSidebar(props) {
const [showResponsiveSidebar, setShowResponsiveSidebar] = useState(false);
const {docsMetadata, sidebar} = props;
if (!sidebar) {
return null;
}
const thisSidebar = docsMetadata.docsSidebars[sidebar];
if (!thisSidebar) {
throw new Error(`Can not find ${sidebar} config`);
}
const convertDocLink = item => {
const linkID = item.id;
const linkMetadata = docsMetadata.docs[linkID];
if (!linkMetadata) {
throw new Error(
`Improper sidebars file, document with id '${linkID}' not found.`,
);
}
return {
type: 'link',
label: linkMetadata.sidebar_label || linkMetadata.title,
href: linkMetadata.permalink,
};
};
const renderItem = item => {
switch (item.type) {
case 'category':
return (
<li className="menu__list-item" key={item.label}>
<a className="menu__link" href="#!">
{item.label}
</a>
<ul className="menu__list">{item.items.map(renderItem)}</ul>
</li>
);
case 'link':
return (
<li className="menu__list-item" key={item.label}>
<Link
activeClassName="menu__link--active"
className="menu__link"
to={item.href}
onClick={() => {
setShowResponsiveSidebar(false);
}}>
{item.label}
</Link>
</li>
);
case 'ref':
default:
return renderItem(convertDocLink(item));
}
};
return (
<div className={styles.sidebar}>
<div
className={classnames('menu', 'menu--responsive', {
'menu--show': showResponsiveSidebar,
})}>
<button
aria-label={showResponsiveSidebar ? 'Close Menu' : 'Open Menu'}
className="button button--secondary button--sm menu__button"
type="button"
onClick={() => {
setShowResponsiveSidebar(!showResponsiveSidebar);
}}>
{showResponsiveSidebar ? (
<span
className={classnames(
styles.sidebarMenuIcon,
styles.sidebarMenuCloseIcon,
)}>
&times;
</span>
) : (
<svg
className={styles.sidebarMenuIcon}
xmlns="http://www.w3.org/2000/svg"
height={MOBILE_TOGGLE_SIZE}
width={MOBILE_TOGGLE_SIZE}
viewBox="0 0 32 32"
role="img"
focusable="false">
<title>Menu</title>
<path
stroke="currentColor"
strokeLinecap="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M4 7h22M4 15h22M4 23h22"
/>
</svg>
)}
</button>
<ul className="menu__list">
{thisSidebar.map(item => renderItem(item, {root: true}))}
</ul>
</div>
</div>
);
}
export default DocSidebar;

View file

@ -1,29 +0,0 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
@media (min-width: 997px) {
.sidebar {
height: calc(100vh - var(--ifm-navbar-height));
overflow-y: auto;
padding: 0.5rem;
position: sticky;
top: var(--ifm-navbar-height);
}
}
.sidebarMenuIcon {
vertical-align: middle;
}
.sidebarMenuCloseIcon {
display: inline-block;
height: 24px;
font-size: 1.5rem;
font-weight: var(--ifm-font-weight-bold);
line-height: 0.9;
width: 24px;
}