diff --git a/lib/load/theme.js b/lib/load/theme.js index 0aa529c145..a4643feb5c 100644 --- a/lib/load/theme.js +++ b/lib/load/theme.js @@ -7,7 +7,7 @@ module.exports = function loadConfig(siteDir) { ? customThemePath : path.resolve(__dirname, '../theme'); - const themeComponents = ['Docs', 'Loading', 'NotFound']; + const themeComponents = ['Docs', 'Loading', 'NotFound', 'Markdown']; themeComponents.forEach(component => { if (!require.resolve(path.join(themePath, component))) { throw new Error( diff --git a/lib/theme/Docs/index.js b/lib/theme/Docs/index.js index e4e1d0862f..910684ead6 100644 --- a/lib/theme/Docs/index.js +++ b/lib/theme/Docs/index.js @@ -9,27 +9,10 @@ export default class Docs extends React.Component { const {route, docsData, siteConfig} = this.props; const currentDoc = docsData.find(data => data.path === route.path); - const highlight = Object.assign( - {}, - { - version: '9.12.0', - theme: 'default' - }, - siteConfig.highlight - ); - - // Use user-provided themeUrl if it exists, else construct one from version and theme. - const highlightThemeURL = highlight.themeUrl - ? highlight.themeUrl - : `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${ - highlight.version - }/styles/${highlight.theme}.min.css`; - return ( {(currentDoc && currentDoc.title) || siteConfig.title} -
{this.props.children}
diff --git a/lib/core/components/Markdown/anchors.js b/lib/theme/Markdown/anchors.js similarity index 100% rename from lib/core/components/Markdown/anchors.js rename to lib/theme/Markdown/anchors.js diff --git a/lib/core/components/Markdown/highlight.js b/lib/theme/Markdown/highlight.js similarity index 100% rename from lib/core/components/Markdown/highlight.js rename to lib/theme/Markdown/highlight.js diff --git a/lib/core/components/Markdown/index.js b/lib/theme/Markdown/index.js similarity index 68% rename from lib/core/components/Markdown/index.js rename to lib/theme/Markdown/index.js index c9412efc8d..6eb0a378d1 100644 --- a/lib/core/components/Markdown/index.js +++ b/lib/theme/Markdown/index.js @@ -2,6 +2,7 @@ import React from 'react'; import Markdown from 'remarkable'; +import Helmet from 'react-helmet'; import highlight from './highlight'; import anchors from './anchors'; @@ -58,16 +59,35 @@ class MarkdownBlock extends React.Component { } render() { - const Container = this.props.container; - if (!Container) { - return
{this.content()}
; - } - return {this.content()}; + const {siteConfig} = this.props; + const highlight = Object.assign( + {}, + { + version: '9.12.0', + theme: 'default' + }, + siteConfig.highlight + ); + + // Use user-provided themeUrl if it exists, else construct one from version and theme. + const highlightThemeURL = highlight.themeUrl + ? highlight.themeUrl + : `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/${ + highlight.version + }/styles/${highlight.theme}.min.css`; + + return ( +
+ + + + {this.content()} +
+ ); } } MarkdownBlock.defaultProps = { - container: 'div', siteConfig: {} }; diff --git a/lib/core/components/Markdown/toSlug.js b/lib/theme/Markdown/toSlug.js similarity index 100% rename from lib/core/components/Markdown/toSlug.js rename to lib/theme/Markdown/toSlug.js diff --git a/lib/theme/NotFound.js b/lib/theme/NotFound.js index 74abb1c7e7..193b0edb29 100644 --- a/lib/theme/NotFound.js +++ b/lib/theme/NotFound.js @@ -7,7 +7,10 @@ export default class NotFound extends React.Component {
404 Page Not Found
- Not found + Not found
); diff --git a/lib/webpack/loader/markdown.js b/lib/webpack/loader/markdown.js index d4a14e6310..c11f3f671f 100644 --- a/lib/webpack/loader/markdown.js +++ b/lib/webpack/loader/markdown.js @@ -5,14 +5,19 @@ module.exports = function(fileString) { const options = getOptions(this); const {body} = fm(fileString); - const source = JSON.stringify(body); + + const content = JSON.stringify(body); + // TODO replace all the markdown linking to correct url depends on whether it's versioned/translated/normal docs + // e.g: [test](test.md) become [test](/docs/test) const siteConfig = JSON.stringify(options.siteConfig); return ( `import React from 'react';\n` + - `import MarkdownBlock from '@core/components/Markdown'\n` + - `export default () => ;` + `import Markdown from '@theme/Markdown'\n` + + `export default () => ( + + {${content}} + + );` ); - - // return `export default () => `; };