mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-17 18:22:37 +02:00
feat: add core dev files
This commit is contained in:
parent
750804646c
commit
4c36e71d1f
2 changed files with 21 additions and 52 deletions
|
@ -1,55 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {render} from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import {BrowserRouter, Route, Switch, Link} from 'react-router-dom';
|
import {BrowserRouter} from 'react-router-dom';
|
||||||
import blogMetadata from '@generated/blogMetadata';
|
|
||||||
import docsMetadata from '@generated/docsMetadata';
|
|
||||||
import Blog from './blog';
|
|
||||||
import Docs from './docs';
|
|
||||||
|
|
||||||
const renderBlog = props => {
|
import App from './App';
|
||||||
const metadata = blogMetadata.find(blog => blog.path === props.match.path);
|
|
||||||
return <Blog content={metadata.content} {...props} />;
|
|
||||||
};
|
|
||||||
const renderDocs = props => {
|
|
||||||
const metadata = docsMetadata.find(doc => doc.path === props.match.path);
|
|
||||||
return <Docs content={metadata.content} {...props} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Home = () => {
|
ReactDOM.render(
|
||||||
const showLink = path => (
|
|
||||||
<li>
|
|
||||||
<Link to={path}>{path}</Link>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
const blogLinks = blogMetadata.map(blog => showLink(blog.path));
|
|
||||||
const docsLinks = docsMetadata.map(doc => showLink(doc.path));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ul>
|
|
||||||
{'Available Routes'}
|
|
||||||
{blogLinks}
|
|
||||||
{docsLinks}
|
|
||||||
</ul>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
class App extends React.Component {
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<div>
|
<App />
|
||||||
<Switch>
|
</BrowserRouter>,
|
||||||
<Route exact path="/" component={Home} />
|
document.getElementById('app')
|
||||||
{blogMetadata.map(({path, content}) => (
|
);
|
||||||
<Route key={path} exact path={path} render={renderBlog} />
|
|
||||||
))}
|
|
||||||
{docsMetadata.map(({path}) => (
|
|
||||||
<Route key={path} exact path={path} render={renderDocs} />
|
|
||||||
))}
|
|
||||||
</Switch>
|
|
||||||
</div>
|
|
||||||
</BrowserRouter>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render(<App />, document.getElementById('app'));
|
|
||||||
|
|
12
lib/core/devTemplate.ejs
Normal file
12
lib/core/devTemplate.ejs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="<%= htmlWebpackPlugin.files.chunks.main.entry %>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue