-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Gustafsson
committed
Mar 4, 2021
1 parent
ce316dd
commit 164896d
Showing
15 changed files
with
198 additions
and
24,804 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,26 @@ | ||
const path = require(`path`); | ||
const contentfulPathResolver = require('./gatsby/utils/contentfulPathResolver'); | ||
const { createResolvers } = require('./gatsby/create-resolvers'); | ||
const path = require('path'); | ||
const products = require('./products.json'); | ||
|
||
exports.createResolvers = createResolvers; | ||
const createPageWithLocales = ( | ||
page, | ||
{ deletePage, createPage }, | ||
withDelete = false | ||
) => { | ||
return new Promise(resolve => { | ||
const newPath = page.path; | ||
|
||
const newPage = { | ||
...page, | ||
path: `/en${newPath}`, | ||
context: { ...page.context, locale: 'en-US' }, | ||
}; | ||
const newPage2 = { | ||
...page, | ||
path: newPath, | ||
context: { ...page.context, locale: 'sv-SE' }, | ||
}; | ||
if (withDelete) { | ||
deletePage(page); | ||
} | ||
createPage(newPage); | ||
createPage(newPage2); | ||
resolve(); | ||
}); | ||
}; | ||
|
||
const webshopDevices = async graphql => { | ||
const result = await graphql(` | ||
{ | ||
treApi { | ||
webshopDevices(customerType: consumer, deviceType: phone) { | ||
products { | ||
id | ||
urlSlug | ||
brand | ||
model | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
if (result.errors) { | ||
throw result.errors; | ||
} | ||
|
||
return result.data.treApi.webshopDevices.products || []; | ||
}; | ||
|
||
exports.createPages = async ({ graphql, actions }) => { | ||
const result = await graphql(` | ||
query { | ||
treApi { | ||
contentPages { | ||
id | ||
urlRegex | ||
blocks { | ||
type | ||
id | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
if (result.errors) { | ||
throw result.errors; | ||
} | ||
|
||
const isDevicePage = blocks => | ||
blocks.some(block => block.type === 'devicedetails'); | ||
|
||
const isProductListPage = blocks => | ||
blocks.some(block => block.type === 'productlist'); | ||
|
||
return Promise.all( | ||
result.data.treApi.contentPages.map(async page => { | ||
const { blocks, urlRegex, ...rest } = page; | ||
|
||
let path = urlRegex; | ||
|
||
if (path.includes('massesandbox')) return; | ||
if (path.includes('cizzi')) return; | ||
}) | ||
); | ||
exports.createPages = async ({ graphql, actions, reporter }) => { | ||
const { createPage } = actions; | ||
}; | ||
|
||
// You can delete this file if you're not using it | ||
exports.onCreatePage = ({ page, actions }) => { | ||
if (page.path.includes('404')) { | ||
return Promise.resolve(); | ||
} | ||
|
||
return createPageWithLocales(page, actions, true); | ||
exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => { | ||
const { createNode } = actions; | ||
|
||
products.forEach(product => { | ||
createNode({ | ||
...product, | ||
slug: product.displayName | ||
.toLowerCase() | ||
.replace(/ /g, '-') | ||
.replace(/[^\w-]+/g, ''), | ||
id: createNodeId(product.id), | ||
internal: { | ||
type: 'Product', | ||
content: JSON.stringify(product), | ||
contentDigest: createContentDigest(product), | ||
}, | ||
}); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.