diff --git a/gatsby-node.js b/gatsby-node.js
index c7d39c2..fd41b57 100644
--- a/gatsby-node.js
+++ b/gatsby-node.js
@@ -1,9 +1,36 @@
+const fs = require('fs');
const path = require('path');
+const jsYaml = require('js-yaml');
const { createFilePath } = require('gatsby-source-filesystem');
const sourceRepos = require('./source-repos');
-const { cacheNavigationJSON } = require('./src/navigation');
+const { fromMkdocsYaml } = require('./src/navigation');
-exports.onPostBootstrap = cacheNavigationJSON;
+exports.onPostBootstrap = function cacheSourceData() {
+ const sourceData = sourceRepos.filter(({ name, mkdocs, baseURI }) => {
+ let isValid = true, msg = 'Skipping source.';
+ if (typeof name !== 'string') {
+ isValid = false; msg = `${msg} Invalid name: ${name}.`
+ }
+ if (typeof mkdocs !== 'string') {
+ isValid = false; msg = `${msg} Invalid MkDocs path: ${mkdocs}.`
+ }
+ if (typeof baseURI !== 'string') {
+ isValid = false; msg = `${msg} Invalid base URI: ${baseURI}.`
+ }
+ if (!isValid && process.env.NODE_ENV == 'development') console.warn(msg);
+ return isValid;
+ }).map((config) => {
+ const { name, mkdocs, baseURI } = config;
+ const mkdocsPath = path.join(__dirname, '.cache/gatsby-source-git/', name, mkdocs);
+ const file = fs.readFileSync(mkdocsPath);
+ const yaml = jsYaml.load(file);
+ const navigation = fromMkdocsYaml(yaml, baseURI);
+ return { ...config, navigation };
+ });
+ const json = JSON.stringify(sourceData);
+ const jsonPath = path.join(__dirname, '.cache/__farmOS__source_data.json');
+ fs.writeFileSync(jsonPath, json);
+};
const multiSlashRE = /\/{2,}/g;
exports.onCreateNode = ({ node, getNode, actions }) => {
diff --git a/source-repos.js b/source-repos.js
index ee1a07f..bf4489b 100644
--- a/source-repos.js
+++ b/source-repos.js
@@ -2,7 +2,7 @@ module.exports = [
{
name: 'farmOS',
title: 'farmOS 2.x Docs',
- baseURI: '/',
+ baseURI: '/docs',
mkdocs: 'mkdocs.yml',
remote: 'https://github.com/farmOS/farmOS.git',
branch: '2.x',
@@ -11,7 +11,7 @@ module.exports = [
{
name: 'farmOS.js',
title: 'farmOS.js Docs',
- baseURI: '/js',
+ baseURI: '/docs/js',
mkdocs: 'docs/config.yml',
remote: 'https://github.com/jgaehring/farmOS.js.git',
branch: 'main',
diff --git a/src/components/layout.js b/src/components/layout.js
index f59a75c..3c90d4b 100644
--- a/src/components/layout.js
+++ b/src/components/layout.js
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from 'react';
+import React from 'react';
import { Link } from 'gatsby-material-ui-components';
import {
AppBar, Box, Container, CssBaseline, Drawer, Hidden,
@@ -93,11 +93,19 @@ const useStyles = makeStyles({
});
export default function Layout({ children, location }) {
- const [nav, setNav] = useState(null);
- useEffect(() => {
+ const [nav, setNav] = React.useState(null);
+ React.useEffect(() => {
const loadNav = async () => {
- const navigation = await import('../../.cache/__farmOS__navigation_tree.json');
- setNav(navigation);
+ const { default: sourceData } = await import('../../.cache/__farmOS__source_data.json');
+ setNav({
+ key: '/',
+ title: 'farmOS',
+ page: {
+ pathname: '/',
+ title: 'farmOS'
+ },
+ children: sourceData.map(({ navigation }) => navigation),
+ });
};
loadNav();
}, []);
diff --git a/src/navigation.js b/src/navigation.js
index ff4fee9..46d1b86 100644
--- a/src/navigation.js
+++ b/src/navigation.js
@@ -1,8 +1,3 @@
-const fs = require('fs');
-const path = require('path');
-const jsYaml = require('js-yaml');
-const sourceRepos = require('../source-repos');
-
const defaultTransform = title => title
.split('-')
.map(str => str.charAt(0).toUpperCase() + str.slice(1))
@@ -105,33 +100,7 @@ function fromMkdocsYaml(mkdocs, baseURI) {
};
}
-function cacheNavigationJSON() {
- const navigation = sourceRepos.filter(({ name, mkdocs, baseURI }) => {
- let isValid = true, msg = 'Skipping navigation source.';
- if (typeof name !== 'string') {
- isValid = false; msg = `${msg} Invalid name: ${name}.`
- }
- if (typeof mkdocs !== 'string') {
- isValid = false; msg = `${msg} Invalid MkDocs path: ${mkdocs}.`
- }
- if (typeof baseURI !== 'string') {
- isValid = false; msg = `${msg} Invalid base URI: ${baseURI}.`
- }
- if (!isValid && process.env.NODE_ENV == 'development') console.warn(msg);
- return isValid;
- }).map(({ name, mkdocs, baseURI }) => {
- const mkdocsPath = path.join(__dirname, '../.cache/gatsby-source-git/', name, mkdocs);
- const file = fs.readFileSync(mkdocsPath);
- const yaml = jsYaml.load(file);
- return fromMkdocsYaml(yaml, baseURI);
- })[0]; // <--- TEMPORARY HACK (while we're just using one source repository)
- const json = JSON.stringify(navigation);
- const jsonPath = path.join(__dirname, '../.cache/__farmOS__navigation_tree.json');
- fs.writeFileSync(jsonPath, json);
-};
-
module.exports = {
fromRemarkNodes,
fromMkdocsYaml,
- cacheNavigationJSON,
};
diff --git a/src/pages/index.js b/src/pages/index.js
new file mode 100644
index 0000000..03599f0
--- /dev/null
+++ b/src/pages/index.js
@@ -0,0 +1,38 @@
+import * as React from "react"
+import { Link } from 'gatsby-material-ui-components';
+import { makeStyles } from '@material-ui/core/styles';
+import { Box, Typography } from '@material-ui/core';
+import Seo from '../components/seo';
+import theme from "../theme";
+
+const useStyles = makeStyles({
+ main: {
+ '& h1': {
+ color: theme.palette.text.secondary,
+ fontWeight: 300,
+ fontSize: '2rem',
+ lineHeight: 1.3,
+ letterSpacing: '-.01em',
+ margin: '0 0 1.25rem',
+ },
+ },
+});
+
+const HomePage = () => {
+ const classes = useStyles();
+ return (
+ <>
+
+
+
+ Home Page!
+
+
+ Return home.
+
+
+ >
+ )
+}
+
+export default HomePage