Skip to content

Commit

Permalink
Update gatsby-node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Mar 9, 2024
1 parent 7a189d7 commit d175e03
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const debug = require('debug')('datalab:gatsby-node')
const fs = require('fs')

debug('gatsby-node.js')
const NotebooksJsonFilepath = __dirname + '/static/data/notebooks.json'
const AuthorsJsonFilepath = __dirname + '/static/data/authors.json'
const CollectionsJsonFilepath = __dirname + '/static/data/collections.json'
const debug = require("debug")("datalab:gatsby-node")
const fs = require("fs")
const path = require("path")

debug("gatsby-node.js")
const rootPath = path.resolve()
const NotebooksJsonFilepath = path.join(rootPath, "/static/data/notebooks.json")
const AuthorsJsonFilepath = path.join(rootPath, "/static/data/authors.json")
const CollectionsJsonFilepath = path.join(
rootPath,
"/static/data/collections.json"
)
const NotebooksDir = path.join(rootPath, "/static/data/notebooks")

exports.createPages = async function ({ actions, graphql }) {
const authorsMap = {}
const notebooksMap = {}
const collectionsMap = {}
if (!fs.existsSync(__dirname + '/static/data/notebooks')) {
fs.mkdirSync(__dirname + '/static/data/notebooks')
if (!fs.existsSync(NotebooksDir)) {
fs.mkdirSync(NotebooksDir)
}

const { data: authors } = await graphql(`
Expand All @@ -31,7 +37,7 @@ exports.createPages = async function ({ actions, graphql }) {
}
`)

debug('createPages: n. authors: ', authors.allFile.nodes.length)
debug("createPages: n. authors: ", authors.allFile.nodes.length)
authors.allFile.nodes.forEach((node) => {
authorsMap[node.name] = {
name: node.name,
Expand Down Expand Up @@ -64,7 +70,7 @@ exports.createPages = async function ({ actions, graphql }) {
}
}
`)
console.log('createPages: n. notebooks: ', notebooks.allFile.nodes.length)
console.log("createPages: n. notebooks: ", notebooks.allFile.nodes.length)
notebooks.allFile.nodes.forEach((node) => {
notebooksMap[node.name] = {
name: node.name,
Expand Down Expand Up @@ -129,7 +135,7 @@ exports.createPages = async function ({ actions, graphql }) {
}
`)

debug('createPages: n. collections: ', collections.allFile.nodes.length)
debug("createPages: n. collections: ", collections.allFile.nodes.length)
collections.allFile.nodes.forEach((node) => {
collectionsMap[node.name] = {
name: node.name,
Expand Down

0 comments on commit d175e03

Please sign in to comment.