gatsby-node.js 788 B

123456789101112131415161718192021222324252627282930313233343536
  1. const axios = require('axios');
  2. const crypto = require('crypto');
  3. exports.sourceNodes = async ({ boundActionCreators }) => {
  4. const { createNode } = boundActionCreators;
  5. const fetchEntry = () => axios.get("http://api.archives-ouvertes.fr/search/?q=docid:410979&fl=*");
  6. const res = await fetchEntry();
  7. r = res.data.response.docs[0];
  8. console.log("ddd");
  9. const articleNode = {
  10. id : "0",
  11. parent: `__SOURCE__`,
  12. internal:{
  13. type: `Truc`
  14. },
  15. children: [],
  16. // Custom data
  17. docid: r.docid,
  18. title: r.title_s[0],
  19. pages: r.page_s
  20. }
  21. const contentDigest = crypto
  22. .createHash(`md5`)
  23. .update(JSON.stringify(articleNode))
  24. .digest(`hex`);
  25. articleNode.internal.contentDigest = contentDigest;
  26. createNode(articleNode);
  27. return;
  28. }