Created
March 7, 2018 02:50
-
-
Save richardzcode/d0fcb3a98e60528340175aa5168835bb to your computer and use it in GitHub Desktop.
A custom home page that renders README.md in Docusaurus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const React = require('react'); | |
const fs = require('fs-extra'); | |
const path = require('path'); | |
const readMetadata = require('../../server/readMetadata.js'); | |
const CompLibrary = require('../../core/CompLibrary.js'); | |
const MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */ | |
const join = path.join; | |
const CWD = process.cwd(); | |
const siteConfig = require(CWD + '/siteConfig.js'); | |
const file = join(CWD, '..', 'README.md'); | |
let meta = readMetadata.extractMetadata(fs.readFileSync(file, 'utf8')) | |
class Index extends React.Component { | |
render() { | |
let language = this.props.language || ''; | |
return ( | |
<div className="docMainWrapper wrapper"> | |
<div className="container mainContainer"> | |
<div className="wrapper"> | |
<div className="post"> | |
<header className="postHeader"> | |
<h1>{meta.metadata.title}</h1> | |
</header> | |
<article> | |
<MarkdownBlock>{meta.rawContent}</MarkdownBlock> | |
</article> | |
</div> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
} | |
module.exports = Index; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this - super helpful. Just a heads up,
extractMetadata
now lives in the metadataUtils file.