mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 14:06:59 +02:00
feat: prototype blog post generation in dev server
This commit is contained in:
parent
8cbd23d690
commit
7ecd4c9bef
9 changed files with 112 additions and 31 deletions
13
lib/core/blogPost.js
Normal file
13
lib/core/blogPost.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const React = require('react');
|
||||
import blogDatas from '@generated/blogDatas';
|
||||
|
||||
// inner blog component for the article itself, without sidebar/header/footer
|
||||
class BlogPost extends React.Component {
|
||||
render() {
|
||||
const {match} = this.props;
|
||||
const post = blogDatas.find(blog => blog.path === match.path);
|
||||
return <div className="post">{post && post.content}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BlogPost;
|
|
@ -1,30 +1,30 @@
|
|||
import React from 'react';
|
||||
import {render} from 'react-dom';
|
||||
import {BrowserRouter, Route, Switch} from 'react-router-dom';
|
||||
import Hello from '@theme/hello';
|
||||
import Layout from '@theme/layout';
|
||||
import {BrowserRouter, Route, Switch, Link} from 'react-router-dom';
|
||||
import BlogPost from './blogPost';
|
||||
import blogDatas from '@generated/blogDatas';
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
component: Hello
|
||||
},
|
||||
{
|
||||
path: '/layout',
|
||||
component: Layout
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div>
|
||||
<Switch>
|
||||
{routes.map(({path, component}) => (
|
||||
<Route key={path} exact path={path} component={component} />
|
||||
{blogDatas.map(({path}) => (
|
||||
<Route key={path} exact path={path} component={BlogPost} />
|
||||
))}
|
||||
</Switch>
|
||||
<div>
|
||||
{blogDatas.map(({path}) => {
|
||||
return (
|
||||
<div>
|
||||
<Link key={path} to={path}>
|
||||
{path}
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue