@openstack_dev/gatsby-theme-marketing-oif-core 1.0.31 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 18.20.2
1
+ 20.19.4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openstack_dev/gatsby-theme-marketing-oif-core",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "Base theme for Marketing Sites",
5
5
  "author": "smarcet",
6
6
  "keywords": [
@@ -1,13 +1,17 @@
1
1
  const fs = require("fs");
2
2
  const yaml = require("js-yaml");
3
3
 
4
+ const HTTP_301 = 301;
5
+ const HTTP_200 = 200;
6
+ const BASE_10 = 10;
7
+
4
8
  require("dotenv").config({
5
- path: `.env.${process.env.NODE_ENV}`,
9
+ path: `.env.${process.env.NODE_ENV}`
6
10
  });
7
11
 
8
12
  const NodeType = {
9
13
  Header: "header",
10
- Route: "route",
14
+ Route: "route"
11
15
  };
12
16
 
13
17
  const tomlNodeExists = (formerToml, nodeType, route) => {
@@ -36,52 +40,60 @@ const buildRedirectionRules = () => {
36
40
  }
37
41
 
38
42
  let netlifyToml = "";
43
+ if (netlifyConfig?.headers?.length > 0) {
44
+ for (let i = 0; i < netlifyConfig.headers.length; i++) {
45
+ const header = netlifyConfig.headers[i];
39
46
 
40
- for (let i = 0; i < netlifyConfig.headers.length; i++) {
41
- const header = netlifyConfig.headers[i];
42
-
43
- if (formerToml && tomlNodeExists(formerToml, NodeType.Header, header.for)) continue;
47
+ if (formerToml && tomlNodeExists(formerToml, NodeType.Header, header.for))
48
+ continue;
44
49
 
45
- netlifyToml += `
50
+ netlifyToml += `
46
51
  [[headers]]
47
52
  # Define which paths this specific [[headers]] block will cover.
48
53
  for = "${header.for}"
49
54
  [headers.values]
50
55
  Authorization = "Basic ${authToken}"\n`;
56
+ }
51
57
  }
52
58
 
53
- for (let i = 0; i < netlifyConfig.redirects.length; i++) {
54
- const redirect = netlifyConfig.redirects[i];
55
- // see https://docs.netlify.com/routing/redirects/redirect-options/#splats
56
- const hasSplat = redirect.from.endsWith("*");
57
- if (formerToml && tomlNodeExists(formerToml, NodeType.Route, redirect.from)) continue;
58
-
59
- const httpRegExp = /^https?:\/\//;
60
- const isAbsolute = httpRegExp.test(redirect.to);
61
- const host = isAbsolute ? '' : redirectionHost;
62
-
63
- // Status code logic correction:
64
- // 200 for regular redirects (within the same site): for backward compatibility below v1.1.0
65
- // 301 for absolute URLs (external redirects): permanent redirect
66
- // If status is provided and is a valid number, has precedence over defaultStatus
67
- const defaultStatus = isAbsolute ? 301 : 200;
68
- const parsedStatus = parseInt(redirect.status, 10);
69
- const status = !isNaN(parsedStatus) ? parsedStatus : defaultStatus;
70
- const headers = [
71
- `X-From = "netlify"`,
72
- `X-Forwarded-Host = "${forwardedHost}"`,
73
- ]
74
- if (!isAbsolute) {
75
- headers.unshift(`Authorization = "Basic ${authToken}"`);
76
- }
59
+ if (netlifyConfig?.redirects?.length > 0) {
60
+ for (let i = 0; i < netlifyConfig.redirects.length; i++) {
61
+ const redirect = netlifyConfig.redirects[i];
62
+ // see https://docs.netlify.com/routing/redirects/redirect-options/#splats
63
+ const hasSplat = redirect.from.endsWith("*");
64
+ if (
65
+ formerToml &&
66
+ tomlNodeExists(formerToml, NodeType.Route, redirect.from)
67
+ )
68
+ continue;
69
+
70
+ const httpRegExp = /^https?:\/\//;
71
+ const isAbsolute = httpRegExp.test(redirect.to);
72
+ const host = isAbsolute ? "" : redirectionHost;
73
+
74
+ // Status code logic correction:
75
+ // 200 for regular redirects (within the same site): for backward compatibility below v1.1.0
76
+ // 301 for absolute URLs (external redirects): permanent redirect
77
+ // If status is provided and is a valid number, has precedence over defaultStatus
78
+ const defaultStatus = isAbsolute ? HTTP_301 : HTTP_200;
79
+ const parsedStatus = parseInt(redirect.status, BASE_10);
80
+ const status = !Number.isNaN(parsedStatus) ? parsedStatus : defaultStatus;
81
+ const headers = [
82
+ "X-From = \"netlify\"",
83
+ `X-Forwarded-Host = "${forwardedHost}"`
84
+ ];
85
+ if (!isAbsolute) {
86
+ headers.unshift(`Authorization = "Basic ${authToken}"`);
87
+ }
77
88
 
78
- netlifyToml += `
89
+ netlifyToml += `
79
90
  [[redirects]]
80
91
  from = "${redirect.from}"
81
92
  to = "${host}${redirect.to}${hasSplat ? ":splat" : ""}"
82
93
  status = ${status}
83
94
  force = true
84
95
  headers = {${headers.join(", ")}}\n`;
96
+ }
85
97
  }
86
98
 
87
99
  if (!appendMode) {