@openstack_dev/gatsby-theme-marketing-oif-core 1.0.32 → 1.0.33-beta.2
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/package.json +1 -1
- package/src/cms/config/index.js +5 -1
- package/src/components/Link.js +43 -10
package/package.json
CHANGED
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
|
|
package/src/components/Link.js
CHANGED
|
@@ -3,40 +3,73 @@ import { Link as GatsbyLink } from "gatsby";
|
|
|
3
3
|
// Since DOM elements <a> cannot receive activeClassName
|
|
4
4
|
// and partiallyActive, destructure the prop here and
|
|
5
5
|
// pass it only to GatsbyLink
|
|
6
|
-
function Link({
|
|
7
|
-
children, to, activeClassName, partiallyActive, ...other
|
|
8
|
-
}) {
|
|
6
|
+
function Link({ children, to, activeClassName, partiallyActive, ...other }) {
|
|
9
7
|
// Tailor the following test to your environment.
|
|
10
|
-
|
|
11
|
-
// will start with exactly one slash, and that anything else is external.
|
|
12
|
-
const internal = /^\/(?!\/)/.test(to);
|
|
13
|
-
// Use Gatsby Link for internal links, and <a> for others
|
|
8
|
+
|
|
14
9
|
const email = /\S+@\S+\.\S+/.test(to);
|
|
10
|
+
const isAbsoluteUrl = /^(https?:)?\/\//i.test(to);
|
|
11
|
+
const isHash = to.startsWith("#");
|
|
12
|
+
|
|
13
|
+
// Gatsby pathPrefix at runtime ("" in dev, "/marketplace" in your build)
|
|
14
|
+
const prefix =
|
|
15
|
+
typeof __PATH_PREFIX__ !== "undefined" && __PATH_PREFIX__
|
|
16
|
+
? __PATH_PREFIX__
|
|
17
|
+
: "";
|
|
18
|
+
|
|
19
|
+
console.log(`Link::render prefix ${prefix}`);
|
|
20
|
+
// Internal for Gatsby routing *only if*:
|
|
21
|
+
// - it’s a single-slash path
|
|
22
|
+
// - and it’s inside the current prefix (or there is no prefix)
|
|
23
|
+
const isSingleSlashPath = /^\/(?!\/)/.test(to);
|
|
24
|
+
|
|
25
|
+
// If we're running with /marketplace prefix, only /marketplace/* should be Gatsby-internal
|
|
26
|
+
const internal =
|
|
27
|
+
isSingleSlashPath &&
|
|
28
|
+
(!prefix || to === prefix || to.startsWith(`${prefix}/`));
|
|
15
29
|
|
|
30
|
+
// Use Gatsby Link for internal links, and <a> for others
|
|
16
31
|
if (internal) {
|
|
17
32
|
return (
|
|
18
33
|
<GatsbyLink
|
|
19
34
|
to={to}
|
|
20
35
|
activeClassName={activeClassName}
|
|
21
36
|
partiallyActive={partiallyActive}
|
|
22
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
23
37
|
{...other}
|
|
24
38
|
>
|
|
25
39
|
{children}
|
|
26
40
|
</GatsbyLink>
|
|
27
41
|
);
|
|
28
42
|
}
|
|
43
|
+
|
|
29
44
|
if (email) {
|
|
30
45
|
const href = /^mailto:/.test(to) ? to : `mailto:${to}`;
|
|
31
46
|
return (
|
|
32
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
33
47
|
<a href={href} {...other}>
|
|
34
48
|
{children}
|
|
35
49
|
</a>
|
|
36
50
|
);
|
|
37
51
|
}
|
|
52
|
+
|
|
53
|
+
// For absolute URLs keep new tab behavior
|
|
54
|
+
if (isAbsoluteUrl) {
|
|
55
|
+
return (
|
|
56
|
+
<a href={to} target="_blank" rel="noreferrer" {...other}>
|
|
57
|
+
{children}
|
|
58
|
+
</a>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Hash or base-site root paths like /software should be same-tab
|
|
63
|
+
if (isHash || isSingleSlashPath) {
|
|
64
|
+
return (
|
|
65
|
+
<a href={to} {...other}>
|
|
66
|
+
{children}
|
|
67
|
+
</a>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Fallback
|
|
38
72
|
return (
|
|
39
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
40
73
|
<a href={to} target="_blank" rel="noreferrer" {...other}>
|
|
41
74
|
{children}
|
|
42
75
|
</a>
|