Created
April 30, 2019 17:01
-
-
Save mark-casias/97a8e874c2cd175f4e63dd8b07aaf737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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