diff --git a/README.md b/README.md index 4d17554..525e3f4 100644 --- a/README.md +++ b/README.md @@ -367,13 +367,13 @@ See the [example](https://github.com/c8r/x0/tree/master/examples/webpack-config) **REMOVE BEFORE MERGING** -- [ ] markdown scope - [ ] default route sorting -- [x] deep require context -- [ ] route dirname/full path -- [ ] minimatch -- [ ] pass front-matter as props - [ ] props.Component in custom apps +- [x] route dirname/full path +- [x] pass front-matter as props +- [x] markdown scope +- [x] deep require context +- [x] minimatch - [x] move client modules to src - [x] adjust resolve diff --git a/docs/_app.js b/docs/_app.js index bbe351d..ed66031 100644 --- a/docs/_app.js +++ b/docs/_app.js @@ -1,5 +1,6 @@ import React from 'react' import * as scope from 'rebass' +import { Link } from 'react-router-dom' import { ScopeProvider } from '../src' import { Flex, @@ -13,15 +14,24 @@ export default class App extends React.Component { } render () { - const { render } = this.props - console.log('custom app', this.props.routes) + const { routes, route, render } = this.props + console.log('custom app', routes) + console.log('route', route) return ( - {false && ( + {true && ( - custom app +
    + {routes.map(route => ( +
  • + + {route.name} ({route.path}) + +
  • + ))} +
)} diff --git a/docs/_scope.js b/docs/_scope.js deleted file mode 100644 index dbf7edf..0000000 --- a/docs/_scope.js +++ /dev/null @@ -1,46 +0,0 @@ -import React from 'react' -import styled from 'styled-components' -import * as Rebass from 'rebass' -import { heading, link } from '@compositor/md' - -const Pre = styled(Rebass.Pre)({ - borderRadius: '8px' -}) - -export default { - ...Rebass, - h1: heading(props => - ), - h2: heading(props => - ), - h3: heading(props => - ), - a: link(props => - - ), - pre: props => -
-}
diff --git a/docs/components.md b/docs/components.md
index 0cbc221..9681060 100644
--- a/docs/components.md
+++ b/docs/components.md
@@ -1,6 +1,7 @@
 ---
 title: Components
 ---
+import { Box } from 'rebass'
 
 # Components
 
@@ -11,3 +12,8 @@ This is a live/editable code block:
 ```.jsx
 Hello
 ```
+
+---
+
+fm title: {frontMatter.title}
+
diff --git a/docs/dynamic.js b/docs/dynamic.js
index 3e76460..1d9e8a1 100644
--- a/docs/dynamic.js
+++ b/docs/dynamic.js
@@ -26,12 +26,18 @@ export default class extends React.Component {
   }
 
   render () {
+    const { match } = this.props
+
     return 
dynamic routing
Home Dynamic Routes Hello Hi + + {match.params.id && ( +

{match.params.id}

+ )}
} } diff --git a/docs/examples/index.md b/docs/examples/index.md index b0fe5b7..6ba417b 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -1,2 +1,4 @@ # Examples + +- [Button](Button.md) diff --git a/docs/docs.js b/docs/readme.js similarity index 84% rename from docs/docs.js rename to docs/readme.js index 4be4317..59157cc 100644 --- a/docs/docs.js +++ b/docs/readme.js @@ -4,7 +4,6 @@ import { } from 'rebass' import styled from 'styled-components' import Readme from '../README.md' -import scope from './_scope' const Prose = styled.div([], { '& img': { @@ -20,8 +19,6 @@ const Prose = styled.div([], { export default props => - + diff --git a/examples/jsx/pages/index.jsx b/examples/jsx/pages/index.jsx index 562ff3b..529f90e 100644 --- a/examples/jsx/pages/index.jsx +++ b/examples/jsx/pages/index.jsx @@ -1,7 +1,8 @@ --- title: Hello JSX -scope: import scope from './_scope' --- +import { Box, Heading, Text, Link } from 'rebass' + {props.title} diff --git a/package.json b/package.json index 1249c85..6a07c1d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@compositor/x0", "version": "5.0.8", "description": "Zero-config React development environment and static site generator", - "main": "index.js", + "main": "src/index.js", "bin": { "x0": "cli.js" }, diff --git a/src/entry.js b/src/entry.js index 9ecd4ae..3bfc6c6 100644 --- a/src/entry.js +++ b/src/entry.js @@ -10,10 +10,10 @@ import { Link, withRouter } from 'react-router-dom' +import { Provider as RebassProvider } from 'rebass' import minimatch from 'minimatch' import Catch from './Catch' -import ScopeProvider from './ScopeProvider' import FileList from './FileList' import ScrollTop from './ScrollTop' @@ -23,17 +23,13 @@ const req = require.context(DIRNAME, true, /\.(js|md|mdx|jsx)$/) const { filename, basename = '', disableScroll } = OPTIONS const index = filename ? path.basename(filename, path.extname(filename)) : 'index' -req.keys().forEach(key => { - console.log(key, minimatch(key.replace(/^\.\//, ''), MATCH) ) -}) - const getComponents = req => req.keys() .filter(key => !MATCH || minimatch(key.replace(/^\.\//, ''), MATCH)) .map(key => ({ key, name: path.basename(key, path.extname(key)), module: req(key), - Component: req(key).default || req(key) + Component: req(key).default || req(key), })) .filter(component => !/^(\.|_)/.test(component.name)) .filter(component => typeof component.Component === 'function') @@ -58,14 +54,20 @@ const App = APP ? (require(APP).default || require(APP)) : DefaultApp export const getRoutes = async (components = initialComponents) => { const routes = await components.map(async ({ key, name, module, Component }) => { const exact = name === index - let pathname = exact ? '/' : '/' + name - const props = Component.getInitialProps + name = exact ? '/' : '/' + name + const dirname = path.dirname(key).replace(/^\./, '') + let pathname = dirname + (exact ? '/' : name) + const href = pathname + const initialProps = Component.getInitialProps ? await Component.getInitialProps({ path: pathname }) : {} + const meta = module.frontMatter || {} + const props = { ...meta, ...initialProps } pathname = props.path || pathname return { key: name, name, + href, path: pathname, exact, module, @@ -98,15 +100,13 @@ export default class Root extends React.Component { path = '/' } = this.props - console.log('App', App.defaultProps) - return ( - + {!disableScroll && } - + ) diff --git a/src/index.js b/src/index.js index d59e3fc..608ca9b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,7 @@ export { default as ScopeProvider } from './ScopeProvider' export { default as LiveEditor } from './LiveEditor' +export { default as LivePreview } from './LivePreview' +export { default as FileList } from './FileList' +export { default as Catch } from './Catch' +export { default as ScrollTop } from './ScrollTop' export { default as scope } from './scope'