diff --git a/new-examples/layers.js b/new-examples/layers.js
index 1157501c83..e5d6b5d5f5 100644
--- a/new-examples/layers.js
+++ b/new-examples/layers.js
@@ -30,6 +30,6 @@ const map = new Map({
target: 'map',
view: new View({
center: [0, 0],
- zoom: 1
+ zoom: 2
})
});
diff --git a/site/plugins/examples/components/Example.js b/site/plugins/examples/components/Example.js
index 265d4d35a6..9e8db5bed7 100644
--- a/site/plugins/examples/components/Example.js
+++ b/site/plugins/examples/components/Example.js
@@ -1,36 +1,47 @@
import React, {Component, Fragment} from 'react';
import {object} from 'prop-types';
import injectSheet from 'react-jss';
+import ExampleList from './ExampleList';
class Example extends Component {
render() {
const example = this.props.data.sitePage.context;
return (
-
- {example.frontmatter.title}
-
- script
-
- {example.js}
-
- markup
-
- {example.html}
-
- {example.css && (
-
- style
-
- {example.css}
-
-
- )}
-
+
+
+
+
+
+
{example.frontmatter.title}
+
+
+
script
+
+ {example.js}
+
+
markup
+
+ {example.html}
+
+ {example.css && (
+
+ style
+
+ {example.css}
+
+
+ )}
+
+
);
}
}
@@ -58,11 +69,28 @@ export const query = graphql`
`;
const styles = {
+ wrapper: {
+ display: 'flex'
+ },
+ nav: {
+ marginRight: '1em'
+ },
+ content: {
+ minWidth: 300,
+ flexGrow: 1
+ },
+ pre: {
+ overflow: 'auto'
+ },
embed: {
margin: 0,
padding: 0,
height: 350,
width: '100%'
+ },
+ aside: {
+ textAlign: 'right',
+ fontSize: '0.75em'
}
};
diff --git a/site/plugins/examples/components/ExampleList.js b/site/plugins/examples/components/ExampleList.js
new file mode 100644
index 0000000000..46b5dd404f
--- /dev/null
+++ b/site/plugins/examples/components/ExampleList.js
@@ -0,0 +1,62 @@
+import React, {Component} from 'react';
+import {object} from 'prop-types';
+import injectSheet from 'react-jss';
+import Link from 'gatsby-link';
+
+class ExampleList extends Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ index: null
+ };
+ }
+
+ componentDidMount() {
+ fetch('../index.json')
+ .then(response => response.json())
+ .then(index => {
+ this.setState({index});
+ });
+ }
+
+ renderList() {
+ const index = this.state.index;
+ if (!index) {
+ return '...';
+ }
+
+ const list = [];
+ for (const id in index) {
+ const example = index[id];
+ list.push(
+
+ {example.title}
+
+ );
+ }
+ return ;
+ }
+
+ render() {
+ return (
+ {this.renderList()}
+ );
+ }
+}
+
+ExampleList.propTypes = {
+ classes: object.isRequired
+};
+
+const styles = {
+ wrapper: {
+ minWidth: '10em'
+ },
+ list: {
+ margin: 0,
+ listStyle: 'none'
+ }
+};
+
+export default injectSheet(styles)(ExampleList);
diff --git a/site/plugins/examples/gatsby-node.js b/site/plugins/examples/gatsby-node.js
index 7017cc34da..17b4ee168c 100644
--- a/site/plugins/examples/gatsby-node.js
+++ b/site/plugins/examples/gatsby-node.js
@@ -50,7 +50,15 @@ exports.createPages = async (
{graphql, boundActionCreators},
{sourceInstanceName, baseCss = ''}
) => {
- const {createPage} = boundActionCreators;
+ const {createPage, createRedirect} = boundActionCreators;
+
+ createRedirect({
+ fromPath: `/examples/`,
+ isPermanent: false,
+ redirectInBrowser: true,
+ toPath: `/examples/map/`
+ });
+
const {data} = await graphql(`
{
allFile(
@@ -100,6 +108,7 @@ exports.createPages = async (
const embedDirName = 'example-embeds';
const embedDir = path.join(__dirname, '..', '..', 'public', embedDirName);
+ const exampleDir = path.join(__dirname, '..', '..', 'public', 'examples');
rollupCache = await bundle.write({
format: 'es',
@@ -108,6 +117,7 @@ exports.createPages = async (
});
const writes = [];
+ const index = {};
for (const name in examples) {
const node = examples[name].md;
@@ -162,6 +172,10 @@ exports.createPages = async (
writes.push(writeFile(path.join(embedDir, embedName), embed));
const slug = markdownNode.fields.slug;
+ index[name] = {
+ title: markdownNode.frontmatter.title,
+ slug
+ };
createPage({
path: slug,
@@ -177,5 +191,9 @@ exports.createPages = async (
});
}
+ writes.push(
+ writeFile(path.join(exampleDir, 'index.json'), JSON.stringify(index))
+ );
+
await Promise.all(writes);
};