Tweak view to export metadata as object from mdx

This commit is contained in:
Fred Carlsen
2019-07-02 19:56:22 +02:00
committed by fabioberger
parent 1948ffe7bd
commit fabbad2b2c
2 changed files with 23 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
--- export const meta = {
title: 'Sol-coverage Usage' title: 'Sol-coverage Usage',
--- };
Sol-coverage uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `CoverageSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with `ProviderEngine`, please read the [Web3 Provider explained](https://0x.org/wiki#Web3-Provider-Explained) wiki article. Sol-coverage uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `CoverageSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with `ProviderEngine`, please read the [Web3 Provider explained](https://0x.org/wiki#Web3-Provider-Explained) wiki article.

View File

@@ -44,11 +44,13 @@ interface Props {
} }
interface State { interface State {
title: string;
Component: JSX.Element | string; Component: JSX.Element | string;
} }
export class DocsView extends React.Component<Props, State> { export class DocsView extends React.Component<Props, State> {
public state = { public state = {
title: '',
Component: '', Component: '',
mdxComponents: { mdxComponents: {
p: Paragraph, p: Paragraph,
@@ -63,18 +65,20 @@ export class DocsView extends React.Component<Props, State> {
this._addComponentAsync(this.props.match.params.page); this._addComponentAsync(this.props.match.params.page);
} }
public componentDidUpdate(prevProps: Props, prevState: State): void { public componentDidUpdate(prevProps: Props, prevState: State): void {
console.log(this.props); if (prevProps.match.params.page !== this.props.match.params.page) {
this._addComponentAsync(this.props.match.params.page);
}
} }
public render(): React.ReactNode { public render(): React.ReactNode {
const { Component, mdxComponents } = this.state; const { title, Component, mdxComponents } = this.state;
return ( return (
<SiteWrap theme="light"> <SiteWrap theme="light">
<DocumentTitle {...documentConstants.DOCS} /> <DocumentTitle {...documentConstants.DOCS} />
<Hero isHome={false} title={`Page Template`} description="This a subheader for the page" /> <Hero isHome={false} title={title} />
<Section maxWidth={'1030px'} isPadded={false} padding="0 0"> <Section maxWidth={'1030px'} isPadded={false} padding="0 0">
<Columns> <Columns>
<aside> <aside>
<ChapterLinks /> <h3>Sidebar</h3>
</aside> </aside>
<article> <article>
<MDXProvider components={mdxComponents}>{Component ? <Component /> : null}</MDXProvider> <MDXProvider components={mdxComponents}>{Component ? <Component /> : null}</MDXProvider>
@@ -85,17 +89,19 @@ export class DocsView extends React.Component<Props, State> {
); );
} }
private async _addComponentAsync(name: string): Promise<void> { private async _addComponentAsync(name: string): Promise<void> {
return import(`../../../md/new-docs/${name}.mdx`) const component = await import(`../../../md/new-docs/${name}.mdx`).catch(e => {
.then(component => { return null;
this.setState({ });
Component: component.default, if (!component) {
}); this.setState({
}) Component: '',
.catch(() => {
this.setState({
Component: '',
});
}); });
}
this.setState({
title: component.meta.title,
Component: component.default,
});
} }
} }