Skip to content

Instantly share code, notes, and snippets.

@mark-casias
Created April 30, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mark-casias/97a8e874c2cd175f4e63dd8b07aaf737 to your computer and use it in GitHub Desktop.
Save mark-casias/97a8e874c2cd175f4e63dd8b07aaf737 to your computer and use it in GitHub Desktop.
const path = require(`path`)
exports.createPages = async ({ actions, graphql }) => {
const { createPage, createRedirect } = actions
const createNode = (entities, createPage, template) =>
entities.forEach(node => {
if (node) {
createPage({
path: node.path.alias,
component: template,
context: {
slug: node.nid.toString(),
},
})
}
})
const blogTemplate = path.resolve(`src/templates/BlogTemplate/index.js`
let index = 0
const { data: countData } = await graphql(`
query {
drupal {
blogs: nodeQuery(
filter: {
conditions: [
{ field: "type", operator: EQUAL, value: "blog" }
{ field: "status", operator: EQUAL, value: "1" }
]
}
) {
count
}
}
}
`)
const count = countData.drupal.blogs.count
while (index <= count) {
console.log(count, index)
const { data } = await graphql(`
query {
drupal {
blogs: nodeQuery(
limit: 200
offset: ${index}
filter: {
conditions: [
{ field: "type", operator: EQUAL, value: "blog" }
{ field: "status", operator: EQUAL, value: "1" }
]
}
sort: { field: "created", direction: DESC }
) {
count
entities {
... on Drupal_NodeBlog {
nid
status
fieldRedirects
path {
alias
}
}
}
}
}
}
`)
console.log(
`${data.drupal.blogs.entities.length} out of ${
data.drupal.blogs.count
} blogs created`
)
createNode(data.drupal.blogs.entities, createPage, blogTemplate)
index += 200
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment