misc(v2): rename components (#1434)

* misc(v2): clean up work

* misc(v2): rename components
This commit is contained in:
Yangshun Tay 2019-05-04 15:16:10 -07:00 committed by GitHub
parent ab4f4bd802
commit fb56f853af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 51 additions and 46 deletions

View file

@ -24,8 +24,8 @@ const DEFAULT_OPTIONS = {
routeBasePath: 'blog', // URL Route.
include: ['*.md', '*.mdx'], // Extensions to include.
pageCount: 10, // How many entries per page.
blogPageComponent: '@theme/BlogPage',
blogPostComponent: '@theme/BlogPost',
blogListComponent: '@theme/BlogList',
blogItemComponent: '@theme/BlogPost',
};
class DocusaurusPluginContentBlog {
@ -113,7 +113,7 @@ class DocusaurusPluginContentBlog {
}
async contentLoaded({content, actions}) {
const {blogPageComponent, blogPostComponent} = this.options;
const {blogListComponent, blogItemComponent} = this.options;
const {addRoute, createData} = actions;
await Promise.all(
content.map(async metadataItem => {
@ -125,7 +125,7 @@ class DocusaurusPluginContentBlog {
if (isBlogPage) {
addRoute({
path: permalink,
component: blogPageComponent,
component: blogListComponent,
exact: true,
modules: {
entries: metadataItem.posts.map(post => ({
@ -145,7 +145,7 @@ class DocusaurusPluginContentBlog {
addRoute({
path: permalink,
component: blogPostComponent,
component: blogItemComponent,
exact: true,
modules: {
content: metadataItem.source,

View file

@ -21,8 +21,8 @@ const DEFAULT_OPTIONS = {
// TODO: Change format to array.
sidebarPath: '', // Path to sidebar configuration for showing a list of markdown pages.
// TODO: Settle themeing.
docLayoutComponent: '@theme/Doc',
docItemComponent: '@theme/DocBody',
docLayoutComponent: '@theme/DocPage',
docItemComponent: '@theme/DocItem',
};
class DocusaurusPluginContentDocs {

View file

@ -13,7 +13,7 @@ const DEFAULT_OPTIONS = {
path: 'pages', // Path to data on filesystem, relative to site dir.
routeBasePath: '', // URL Route.
include: ['**/*.{js,jsx}'], // Extensions to include.
component: '@theme/Pages',
component: '@theme/Page',
};
class DocusaurusPluginContentPages {

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import React, {useState} from 'react';
import React from 'react';
import {renderRoutes} from 'react-router-config';
import Head from '@docusaurus/Head'; // eslint-disable-line
@ -15,9 +15,8 @@ import DocusaurusContext from '@docusaurus/context'; // eslint-disable-line
import PendingNavigation from './PendingNavigation';
function App() {
const [context, setContext] = useState({});
return (
<DocusaurusContext.Provider value={{siteConfig, ...context, setContext}}>
<DocusaurusContext.Provider value={{siteConfig}}>
{/* TODO: this link stylesheet to infima is temporary */}
<Head>
<link

View file

@ -8,7 +8,7 @@
import React from 'react';
import Layout from '@theme/Layout'; // eslint-disable-line
import Post from '../Post';
import BlogPostItem from '../BlogPostItem';
function BlogPage(props) {
const {
@ -23,9 +23,9 @@ function BlogPage(props) {
<div className="col col--6 col--offset-3">
{BlogPosts.map((PostContent, index) => (
<div className="margin-bottom--xl" key={index}>
<Post truncated metadata={posts[index]}>
<BlogPostItem truncated metadata={posts[index]}>
<PostContent />
</Post>
</BlogPostItem>
</div>
))}
</div>

View file

@ -8,20 +8,20 @@
import React from 'react';
import Layout from '@theme/Layout'; // eslint-disable-line
import Post from '../Post';
import BlogPostItem from '../BlogPostItem';
function BlogPostPage(props) {
const {content: BlogPostContents, metadata} = props;
function BlogPost(props) {
const {content, metadata} = props;
const BlogPostContents = content;
return (
<Layout title={metadata.title}>
{BlogPostContents && (
<div className="container margin-vert--xl">
<div className="row">
<div className="col col--6 col--offset-3">
<Post metadata={metadata}>
<BlogPostItem metadata={metadata}>
<BlogPostContents />
</Post>
</BlogPostItem>
</div>
</div>
</div>
@ -30,4 +30,4 @@ function BlogPost(props) {
);
}
export default BlogPost;
export default BlogPostPage;

View file

@ -8,7 +8,7 @@
import React from 'react';
import Link from '@docusaurus/Link';
function Post(props) {
function BlogPostItem(props) {
const {metadata, children, truncated} = props;
const renderPostHeader = () => {
if (!metadata) {
@ -86,7 +86,7 @@ function Post(props) {
return (
<div>
{renderPostHeader()}
<article>{children}</article>
<article className="markdown">{children}</article>
{truncated && (
<div className="text--right">
<Link className="button button--secondary" to={metadata.permalink}>
@ -98,4 +98,4 @@ function Post(props) {
);
}
export default Post;
export default BlogPostItem;

View file

@ -7,12 +7,13 @@
import React from 'react';
import DocsPaginator from '@theme/DocsPaginator'; // eslint-disable-line
import Head from '@docusaurus/Head';
import DocPaginator from '../DocPaginator';
import styles from './styles.module.css';
const Headings = ({headings, isChild}) => {
function Headings({headings, isChild}) {
if (!headings.length) return null;
return (
<ul className={isChild ? 'contents' : 'contents contents__left-border'}>
@ -26,10 +27,11 @@ const Headings = ({headings, isChild}) => {
))}
</ul>
);
};
}
function DocBody(props) {
function DocItem(props) {
const {metadata, content: DocContent, docsMetadata} = props;
return (
<div className={styles.docBody}>
<Head>
@ -46,9 +48,9 @@ function DocBody(props) {
<DocContent />
</div>
</article>
<div className="margin-vert--lg">
<DocsPaginator docsMetadata={docsMetadata} metadata={metadata} />
</div>
<div className="margin-vert--lg" />
<DocPaginator docsMetadata={docsMetadata} metadata={metadata} />
</div>
<div className="col col--3 col--offset-1">
{DocContent.rightToc && <Headings headings={DocContent.rightToc} />}
@ -59,4 +61,4 @@ function DocBody(props) {
);
}
export default DocBody;
export default DocItem;

View file

@ -9,16 +9,18 @@ import React from 'react';
import {renderRoutes} from 'react-router-config';
import Layout from '@theme/Layout'; // eslint-disable-line
import Sidebar from '@theme/Sidebar'; // eslint-disable-line
function Doc(props) {
import DocSidebar from '../DocSidebar';
function DocPage(props) {
const {route, docsMetadata, location} = props;
return (
<Layout noFooter>
<div className="container container--fluid">
<div className="row">
<div className="col col--3">
<Sidebar docsMetadata={docsMetadata} location={location} />
<DocSidebar docsMetadata={docsMetadata} location={location} />
</div>
<div className="col col--9">
{renderRoutes(route.routes, {docsMetadata})}
@ -29,4 +31,4 @@ function Doc(props) {
);
}
export default Doc;
export default DocPage;

View file

@ -8,9 +8,11 @@
import React from 'react';
import Link from '@docusaurus/Link';
function DocsPaginator(props) {
const {docsMetadata, metadata} = props;
const {docs} = docsMetadata;
function DocPaginator(props) {
const {
docsMetadata: {docs},
metadata,
} = props;
return (
<div className="row">
@ -39,4 +41,4 @@ function DocsPaginator(props) {
);
}
export default DocsPaginator;
export default DocPaginator;

View file

@ -11,7 +11,7 @@ import Link from '@docusaurus/Link'; // eslint-disable-line
import './styles.css';
function Sidebar(props) {
function DocSidebar(props) {
const {docsMetadata, location} = props;
const id =
@ -85,4 +85,4 @@ function Sidebar(props) {
);
}
export default Sidebar;
export default DocSidebar;

View file

@ -11,7 +11,7 @@ import styles from './styles.module.css';
export default props => {
if (props.error) {
console.log(props.error);
console.warn(props.error);
return <div align="center">Error</div>;
}

View file

@ -8,7 +8,8 @@
import React from 'react';
import Layout from '@theme/Layout'; // eslint-disable-line
function Pages({content: PageContent}) {
function Page(props) {
const {content: PageContent} = props;
return (
<Layout>
<PageContent />
@ -16,4 +17,4 @@ function Pages({content: PageContent}) {
);
}
export default Pages;
export default Page;

View file

@ -15,7 +15,6 @@ module.exports = function loadConfig(siteDir) {
: path.resolve(__dirname, '../../default-theme');
const requiredComponents = ['Loading', 'NotFound'];
requiredComponents.forEach(component => {
try {
require.resolve(path.join(themePath, component));