diff --git a/gatsby-node.js b/gatsby-node.js index bdaf788b..c5c51cca 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -186,51 +186,50 @@ exports.createPages = ({ graphql, actions }) => { // // Create pages from swagger json files // + const swaggerSpecs = [ + './data/aquarius.json', + './data/brizo.json' + ] const apiSwaggerTemplate = path.resolve( './src/templates/Swagger/index.jsx' ) + swaggerSpecs.forEach(spec => { + const api = require(spec) // eslint-disable-line + const name = path + .basename(spec) + .split('.json') + .join('') + const slug = `/references/${name}/` + + createPage({ + path: slug, + component: apiSwaggerTemplate, + context: { + slug, + api + } + }) + }) + + // Swagger Pet Store example, fetch from remote const petStoreSlug = '/references/petstore/' try { - const spec = await getSpec() + const api = await getSpec() createPage({ path: petStoreSlug, component: apiSwaggerTemplate, context: { slug: petStoreSlug, - api: spec + api } }) } catch (error) { console.log(error) } - const aquariusSpecs = require('./data/aquarius.json') - const aquariusSlug = '/references/aquarius/' - - createPage({ - path: aquariusSlug, - component: apiSwaggerTemplate, - context: { - slug: aquariusSlug, - api: aquariusSpecs - } - }) - - const brizoSpecs = require('./data/brizo.json') - const brizoSlug = '/references/brizo/' - - createPage({ - path: brizoSlug, - component: apiSwaggerTemplate, - context: { - slug: brizoSlug, - api: brizoSpecs - } - }) - // // Create pages from TypeDoc json files // @@ -290,15 +289,16 @@ exports.createPages = ({ graphql, actions }) => { const javadocTemplate = path.resolve( './src/templates/Javadoc/index.jsx' ) - const { name, pom } = result.data.squidJava.repository - - const metaSquidJava = parser.xml2js(pom.text, { - compact: true - }) javadocSpecs.forEach(spec => { const javadoc = require(spec) // eslint-disable-line + + const { name, pom } = result.data.squidJava.repository const slug = `/references/${name}/` + const metaSquidJava = parser.xml2js(pom.text, { + compact: true + }) + const { project } = metaSquidJava createPage({ path: slug, @@ -307,13 +307,13 @@ exports.createPages = ({ graphql, actions }) => { slug, javadoc, title: name, - description: `${ - metaSquidJava.project.name._text - }. ${metaSquidJava.project.description._text}.`, - version: metaSquidJava.project.version._text, - namespace: `${ - metaSquidJava.project.groupId._text - }.${metaSquidJava.project.artifactId._text}` + description: `${project.name._text}. ${ + project.description._text + }.`, + version: project.version._text, + namespace: `${project.groupId._text}.${ + project.artifactId._text + }` } }) })