Skip to content

Instantly share code, notes, and snippets.

@vladar
Created June 24, 2020 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladar/9ccb2cf38db6e0c994226272a6ccbc15 to your computer and use it in GitHub Desktop.
Save vladar/9ccb2cf38db6e0c994226272a6ccbc15 to your computer and use it in GitHub Desktop.
diff --git a/packages/gatsby-plugin-page-creator/src/derive-path.ts b/packages/gatsby-plugin-page-creator/src/derive-path.ts
index 4d7a2aa78..4c9070e2c 100644
--- a/packages/gatsby-plugin-page-creator/src/derive-path.ts
+++ b/packages/gatsby-plugin-page-creator/src/derive-path.ts
@@ -5,7 +5,7 @@ import _ from "lodash"
// src/pages/product/{sku__en} => product/:sku__en pulls from nodes.sku.en
export function derivePath(path: string, node: Record<string, any>): string {
// 1. Remove the extension
- const pathWithoutExtension = path.replace(/\.[a-z]+$/, ``)
+ let pathWithoutExtension = path.replace(/\.[a-z]+$/, ``)
// 2. Pull out the slug parts that are within { } brackets.
const slugParts = /(\{.*\})/g.exec(pathWithoutExtension)
@@ -36,8 +36,8 @@ export function derivePath(path: string, node: Record<string, any>): string {
}
// 3.d replace the part of the slug with the actual value
- path = path.replace(slugPart, value)
+ pathWithoutExtension = pathWithoutExtension.replace(slugPart, value)
})
- return path
+ return pathWithoutExtension
}
diff --git a/packages/gatsby-plugin-page-creator/src/extract-query.ts b/packages/gatsby-plugin-page-creator/src/extract-query.ts
index e343cbc7a..4015a270f 100644
--- a/packages/gatsby-plugin-page-creator/src/extract-query.ts
+++ b/packages/gatsby-plugin-page-creator/src/extract-query.ts
@@ -29,7 +29,7 @@ export function reverseLookupParams(
): Record<string, string> {
const reversedParams = {}
- absolutePath.split(`/`).forEach(part => {
+ absolutePath.split(/[\\/]/).forEach(part => {
const regex = /^\{([a-zA-Z_]+)\}/.exec(part)
if (regex === null) return
@@ -50,7 +50,7 @@ export function reverseLookupParams(
// to
// `id,baz`
function extractUrlParamsForQuery(createdPath: string): string {
- const parts = createdPath.split(`/`)
+ const parts = createdPath.split(/[\\/]/)
return parts
.reduce<string[]>((queryParts: string[], part: string): string[] => {
if (part.startsWith(`{`)) {
diff --git a/packages/gatsby-plugin-page-creator/src/get-collection-route-params.ts b/packages/gatsby-plugin-page-creator/src/get-collection-route-params.ts
index da9c0d922..f5064abdc 100644
--- a/packages/gatsby-plugin-page-creator/src/get-collection-route-params.ts
+++ b/packages/gatsby-plugin-page-creator/src/get-collection-route-params.ts
@@ -8,7 +8,7 @@ export function getCollectionRouteParams(
): Record<string, string> {
const params = {}
// remove the starting path to simplify the loop
- const fileParts = filePath.split(`/`)
+ const fileParts = filePath.split(/[\\/]/)
const urlParts = urlPath.split(`/`)
fileParts.forEach((part, i) => {
diff --git a/packages/gatsby/src/utils/js-chunk-names.ts b/packages/gatsby/src/utils/js-chunk-names.ts
index ff19389e2..bb36fdb44 100644
--- a/packages/gatsby/src/utils/js-chunk-names.ts
+++ b/packages/gatsby/src/utils/js-chunk-names.ts
@@ -19,7 +19,7 @@ function replaceUnifiedRoutesKeys(
): string {
let newString = kebabedName
- filePath.split(`/`).forEach(part => {
+ filePath.split(/[\\/]/).forEach(part => {
if (part[0] === `[` || part[0] === `{`) {
const match = /(\[(.*)\]|\{(.*)\})/.exec(part)
newString = newString.replace(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment