-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
99 lines (96 loc) · 3.09 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// exports.createSchemaCustomization = ({ actions }) => {
// const { createTypes } = actions
// const typeDefs = `
// type MarkdownRemark implements Node @infer {
// frontmatter: Frontmatter!
// }
// type Frontmatter @infer {
// title: String!
// url: String!
// image: String!
// date: Date! @dateformat
// author: AuthorsJson @link(by: "email", from: "author")
// }
// `
// createTypes(typeDefs)
// }
// exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
// const { createNode } = actions
// // Data can come from anywhere, but for now create it manually
// const myData = ['https://www.thedailygenevan.com/blog/2021/7/2/PCAGA2021']
// metaget.fetch(
// 'https://www.thedailygenevan.com/blog/2021/7/2/PCAGA2021',
// { headers: { 'User-Agent': 'Googlebot' } },
// function (err, meta_response) {
// if (err) {
// console.log(err)
// } else {
// const title = meta_response['og:title']
// const description = meta_response['og:description']
// const image = meta_response['og:image']
// createNode({
// title,
// description,
// image,
// id: createNodeId(
// 'https://www.thedailygenevan.com/blog/2021/7/2/PCAGA2021'
// ),
// internal: {
// type: `NewsPost`,
// mediaType: `text/html`,
// contentDigest: createContentDigest(description),
// },
// })
// }
// }
// )
// }
// const { createRemoteFileNode } = require('gatsby-source-filesystem')
// exports.createSchemaCustomization = ({ actions }) => {
// const { createTypes } = actions
// createTypes(`
// type MarkdownRemark implements Node {
// frontmatter: Frontmatter
// image: File @link(from: "tags.image___NODE")
// }
// type Frontmatter {
// author: String!
// date: String!
// tags: Tags!
// }
// type Tags {
// title: String!
// description: String!
// url: String!
// image: String!
// }
// `)
// }
// exports.onCreateNode = async ({
// node,
// actions: { createNode },
// store,
// cache,
// createNodeId,
// }) => {
// // For all MarkdownRemark nodes that have a featured image url, call createRemoteFileNode
// if (
// node.internal.type === 'MarkdownRemark' &&
// node.frontmatter.tags.image !== null
// ) {
// console.log('image', node.frontmatter.tags.image)
// let fileNode = await createRemoteFileNode({
// url: node.frontmatter.tags.image, // string that points to the URL of the image
// parentNodeId: node.id, // id of the parent node of the fileNode you are going to create
// createNode, // helper function in gatsby-node to generate the node
// createNodeId, // helper function in gatsby-node to generate the node id
// cache, // Gatsby's cache
// store, // Gatsby's Redux store
// })
// // if the file was created, attach the new node to the parent node
// if (fileNode) {
// node.image___NODE = fileNode.id
// // node.featuredImg___NODE = fileNode.id
// }
// }
// }