-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
100 lines (92 loc) · 3.11 KB
/
Copy pathgatsby-node.js
File metadata and controls
100 lines (92 loc) · 3.11 KB
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
100
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require(`path`)
exports.createPages = async ({ graphql, actions }) => { // async (input) => { const graphql = input.graphql ...
const { createPage } = actions // const createPage = actions.createPage
// -------------------------------------------------------
// Variante 1 mit zusätzlicher graphql Abfrage im Template
// -------------------------------------------------------
/*
// Create Detailpages from CSV
const resultPages = await graphql (`
query {
allCatfanshopCsv {
nodes {
Artikelnummer
Bild { relativePath }
Warengruppe
}
}
}
`)
resultPages.data.allCatfanshopCsv.nodes.forEach( node => {
const category = node.Warengruppe.toLowerCase() + "/"
createPage({
// Path for this page — required
path: category + node.Artikelnummer,
component: path.resolve(`./src/templates/catalog-detailpage.js`),
context: {
ArtNr: node.Artikelnummer,
image: node.Bild.relativePath
}
})
})
*/
// ----------------------------------------------------------
// Variante 2 Übergabe aller relevanten Daten per pageContext
// ----------------------------------------------------------
// Create Detailpages from CSV
const resultPages = await graphql (`
query {
allCatfanshopCsv {
nodes {
Artikelnummer
Bezeichnung
Bild {
relativePath
}
Beschreibung
Warengruppe
Preis
}
}
}
`)
resultPages.data.allCatfanshopCsv.nodes.forEach( node => {
const category = node.Warengruppe.toLowerCase()
createPage({
// Path for this page — required
path: category + '/' + node.Artikelnummer + "/",
component: path.resolve(`./src/templates/catalog-detailpage.js`),
context: {
ArtNr: node.Artikelnummer,
name: node.Bezeichnung,
image: node.Bild.relativePath,
description: node.Beschreibung,
group: node.Warengruppe,
price: node.Preis
}
})
})
// Create Categrorie pages from CSV
const resultCategories = await graphql (`
query {
allCatfanshopCsv {
distinct(field: Warengruppe)
}
}
`)
resultCategories.data.allCatfanshopCsv.distinct.forEach( category => {
createPage({
// Path for this page — required
path: category.toLowerCase() + '/',
component: path.resolve(`./src/templates/catalog-categoriepage.js`),
context: {
Category: category
}
})
})
}