Skip to content

Commit

Permalink
Use pages/index.js as home, not farmOS's index.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Dec 7, 2021
1 parent bbd1eac commit bfae288
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 40 deletions.
31 changes: 29 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down
4 changes: 2 additions & 2 deletions source-repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
18 changes: 13 additions & 5 deletions src/components/layout.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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();
}, []);
Expand Down
31 changes: 0 additions & 31 deletions src/navigation.js
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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,
};
38 changes: 38 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Seo title="farmOS | Home"/>
<Box component='main' className={classes.main}>
<Typography variant='h1'>
Home Page!
</Typography>
<Typography variant='p'>
<Link to="/">Return home</Link>.
</Typography>
</Box>
</>
)
}

export default HomePage

0 comments on commit bfae288

Please sign in to comment.