Skip to content

Commit

Permalink
Add preview version for _experimentalPrependParentSlug
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Sztyk committed Nov 23, 2023
1 parent 853376f commit d399b3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mediporta/gatsby-plugin-nginx-redirect",
"version": "0.0.14",
"version": "0.0.14-preview.1",
"description": "Adds your redirects to nginx conf on gatsby build",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 12 additions & 1 deletion src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const recursiveSearch = (needle, object) => {

export async function onPostBuild(
{ store, reporter },
{ outputConfigFile, inputConfigFile, whereToIncludeRedirects = "server" }
{ outputConfigFile, inputConfigFile, whereToIncludeRedirects = "server", _experimentalPrependParentSlug = false }
) {
const { redirects } = store.getState();
removeSync(outputConfigFile);
Expand All @@ -67,9 +67,20 @@ export async function onPostBuild(
conf.flush();
await sleep(500);

const nodes = getNodes()
var fields = nodes
.map(k => k.fields)
.filter(k => k !== undefined)

let foundObject = searchObject(whereToIncludeRedirects, conf.nginx);
if (foundObject) {
redirects.forEach((redirect) => {

if (_experimentalPrependParentSlug) {
var field = fields.find(f => f?.slug === redirect.toPath)
redirect.toPath = field.parentSlug + "/" + redirect.toPath;
}

foundObject._add(
'rewrite',
`^${redirect.fromPath}\\/?$ ${redirect.toPath} ${redirect.isPermanent ? "permanent" : "redirect"}`
Expand Down

0 comments on commit d399b3b

Please sign in to comment.