feat: hljs syntax highlighting & nits

This commit is contained in:
endiliey 2018-08-26 17:06:16 +08:00
parent 0058b20d9e
commit ea37e54477
8 changed files with 44 additions and 52 deletions

View file

@ -6,8 +6,8 @@ import Layout from '@theme/Layout'; // eslint-disable-line
export default class Docs extends React.Component {
render() {
const {location, docsData, config} = this.props;
const currentDoc = docsData.find(data => data.path === location.pathname);
const {route, docsData, siteConfig} = this.props;
const currentDoc = docsData.find(data => data.path === route.path);
const highlight = Object.assign(
{},
@ -15,21 +15,21 @@ export default class Docs extends React.Component {
version: '9.12.0',
theme: 'default'
},
config.highlight
siteConfig.highlight
);
// Use user-provided themeUrl if it exists, else construct one from version and theme.
const highlightThemeURL = highlight.themeUrl
? highlight.themeUrl
: `//cdnjs.cloudflare.com/ajax/libs/highlight.js/${
: `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${
highlight.version
}/styles/${highlight.theme}.min.css`;
return (
<Layout {...this.props}>
<Helmet>
<title>{currentDoc.title || 'Document'}</title>
<link rel="stylesheet" href={highlightThemeURL} />
<title>{(currentDoc && currentDoc.title) || siteConfig.title}</title>
<link rel="stylesheet" type="text/css" href={highlightThemeURL} />
</Helmet>
<div className={styles.mainContainer}>{this.props.children}</div>
</Layout>