@openstack_dev/gatsby-theme-marketing-oif-core 1.0.33-beta.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openstack_dev/gatsby-theme-marketing-oif-core",
3
- "version": "1.0.33-beta.1",
3
+ "version": "1.0.33-beta.2",
4
4
  "description": "Base theme for Marketing Sites",
5
5
  "author": "smarcet",
6
6
  "keywords": [
@@ -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
- // This example assumes that any internal link (intended for Gatsby)
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>