@openstack_dev/gatsby-theme-marketing-oif-core 1.0.31 → 1.0.33-beta.1
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 +1 -1
- package/package.json +1 -1
- package/redirection-rules.js +44 -32
- package/src/cms/config/index.js +5 -1
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
20.19.4
|
package/package.json
CHANGED
package/redirection-rules.js
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
headers
|
|
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
|
-
|
|
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) {
|
package/src/cms/config/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withPrefix } from "gatsby";
|
|
1
2
|
import configurationsCollection from "./collections/configurationsCollection";
|
|
2
3
|
|
|
3
4
|
const CMS_BACKEND_REPO = process.env.GATSBY_CMS_BACKEND_REPO;
|
|
@@ -5,6 +6,9 @@ const CMS_BACKEND_BRANCH = process.env.GATSBY_CMS_BACKEND_BRANCH || "main";
|
|
|
5
6
|
|
|
6
7
|
export const collections = [configurationsCollection];
|
|
7
8
|
|
|
9
|
+
// Gatsby sets __PATH_PREFIX__ at runtime ("" in dev, "/marketplace" in prod builds)
|
|
10
|
+
const publicFolder = withPrefix("/img");
|
|
11
|
+
|
|
8
12
|
const config = {
|
|
9
13
|
backend: {
|
|
10
14
|
name: "github",
|
|
@@ -22,7 +26,7 @@ const config = {
|
|
|
22
26
|
// missing, but will improve performance and avoid a load error.
|
|
23
27
|
load_config_file: false,
|
|
24
28
|
media_folder: "static/img",
|
|
25
|
-
public_folder:
|
|
29
|
+
public_folder: publicFolder,
|
|
26
30
|
collections
|
|
27
31
|
};
|
|
28
32
|
|