gatsby-link 4.18.0-next.0 → 4.18.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/.babelrc +1 -1
- package/index.js +112 -168
- package/is-local-link.js +5 -13
- package/package.json +4 -4
- package/parse-path.js +8 -13
- package/rewrite-link-path.js +27 -42
package/.babelrc
CHANGED
package/index.js
CHANGED
|
@@ -1,78 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
17
|
-
|
|
18
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
19
|
-
|
|
20
|
-
var _react = _interopRequireDefault(require("react"));
|
|
21
|
-
|
|
22
|
-
var _reachRouter = require("@gatsbyjs/reach-router");
|
|
23
|
-
|
|
24
|
-
var _parsePath = require("./parse-path");
|
|
25
|
-
|
|
26
|
-
exports.parsePath = _parsePath.parsePath;
|
|
27
|
-
|
|
28
|
-
var _isLocalLink = require("./is-local-link");
|
|
29
|
-
|
|
30
|
-
var _rewriteLinkPath = require("./rewrite-link-path");
|
|
31
|
-
|
|
32
|
-
var _excluded = ["to", "getProps", "onClick", "onMouseEnter", "activeClassName", "activeStyle", "innerRef", "partiallyActive", "state", "replace", "_location"];
|
|
33
|
-
|
|
34
|
-
function withPrefix(path, prefix) {
|
|
35
|
-
var _ref, _prefix;
|
|
36
|
-
|
|
37
|
-
if (prefix === void 0) {
|
|
38
|
-
prefix = getGlobalBasePrefix();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!(0, _isLocalLink.isLocalLink)(path)) {
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
const _excluded = ["to", "getProps", "onClick", "onMouseEnter", "activeClassName", "activeStyle", "innerRef", "partiallyActive", "state", "replace", "_location"];
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { Link, Location } from "@gatsbyjs/reach-router";
|
|
7
|
+
import { parsePath } from "./parse-path";
|
|
8
|
+
import { isLocalLink } from "./is-local-link";
|
|
9
|
+
import { rewriteLinkPath } from "./rewrite-link-path";
|
|
10
|
+
export { parsePath };
|
|
11
|
+
export function withPrefix(path, prefix = getGlobalBasePrefix()) {
|
|
12
|
+
var _ref;
|
|
13
|
+
|
|
14
|
+
if (!isLocalLink(path)) {
|
|
42
15
|
return path;
|
|
43
16
|
}
|
|
44
17
|
|
|
45
|
-
if (path.startsWith(
|
|
18
|
+
if (path.startsWith(`./`) || path.startsWith(`../`)) {
|
|
46
19
|
return path;
|
|
47
20
|
}
|
|
48
21
|
|
|
49
|
-
|
|
50
|
-
return
|
|
22
|
+
const base = (_ref = prefix !== null && prefix !== void 0 ? prefix : getGlobalPathPrefix()) !== null && _ref !== void 0 ? _ref : `/`;
|
|
23
|
+
return `${base !== null && base !== void 0 && base.endsWith(`/`) ? base.slice(0, -1) : base}${path.startsWith(`/`) ? path : `/${path}`}`;
|
|
51
24
|
} // These global values are wrapped in typeof clauses to ensure the values exist.
|
|
52
25
|
// This is especially problematic in unit testing of this component.
|
|
53
26
|
|
|
27
|
+
const getGlobalPathPrefix = () => process.env.NODE_ENV !== `production` ? typeof __PATH_PREFIX__ !== `undefined` ? __PATH_PREFIX__ : undefined : __PATH_PREFIX__;
|
|
54
28
|
|
|
55
|
-
|
|
56
|
-
return process.env.NODE_ENV !== "production" ? typeof __PATH_PREFIX__ !== "undefined" ? __PATH_PREFIX__ : undefined : __PATH_PREFIX__;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
var getGlobalBasePrefix = function getGlobalBasePrefix() {
|
|
60
|
-
return process.env.NODE_ENV !== "production" ? typeof __BASE_PATH__ !== "undefined" ? __BASE_PATH__ : undefined : __BASE_PATH__;
|
|
61
|
-
};
|
|
29
|
+
const getGlobalBasePrefix = () => process.env.NODE_ENV !== `production` ? typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : undefined : __BASE_PATH__;
|
|
62
30
|
|
|
63
|
-
function withAssetPrefix(path) {
|
|
31
|
+
export function withAssetPrefix(path) {
|
|
64
32
|
return withPrefix(path, getGlobalPathPrefix());
|
|
65
33
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
partiallyActive: _propTypes.default.bool
|
|
34
|
+
const NavLinkPropTypes = {
|
|
35
|
+
activeClassName: PropTypes.string,
|
|
36
|
+
activeStyle: PropTypes.object,
|
|
37
|
+
partiallyActive: PropTypes.bool
|
|
71
38
|
}; // Set up IntersectionObserver
|
|
72
39
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
entries.forEach(
|
|
40
|
+
const createIntersectionObserver = (el, cb) => {
|
|
41
|
+
const io = new window.IntersectionObserver(entries => {
|
|
42
|
+
entries.forEach(entry => {
|
|
76
43
|
if (el === entry.target) {
|
|
77
44
|
// Check if element is within viewport, remove listener, destroy observer, and run link callback.
|
|
78
45
|
// MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0
|
|
@@ -84,67 +51,59 @@ var createIntersectionObserver = function createIntersectionObserver(el, cb) {
|
|
|
84
51
|
io.observe(el);
|
|
85
52
|
return {
|
|
86
53
|
instance: io,
|
|
87
|
-
el
|
|
54
|
+
el
|
|
88
55
|
};
|
|
89
56
|
};
|
|
90
57
|
|
|
91
58
|
function GatsbyLinkLocationWrapper(props) {
|
|
92
|
-
return /*#__PURE__*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
59
|
+
return /*#__PURE__*/React.createElement(Location, null, ({
|
|
60
|
+
location
|
|
61
|
+
}) => /*#__PURE__*/React.createElement(GatsbyLink, _extends({}, props, {
|
|
62
|
+
_location: location
|
|
63
|
+
})));
|
|
98
64
|
}
|
|
99
65
|
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
function GatsbyLink(props) {
|
|
104
|
-
var _this;
|
|
105
|
-
|
|
106
|
-
_this = _React$Component.call(this, props) || this; // Default to no support for IntersectionObserver
|
|
66
|
+
class GatsbyLink extends React.Component {
|
|
67
|
+
constructor(props) {
|
|
68
|
+
super(props); // Default to no support for IntersectionObserver
|
|
107
69
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
70
|
+
this.defaultGetProps = ({
|
|
71
|
+
isPartiallyCurrent,
|
|
72
|
+
isCurrent
|
|
73
|
+
}) => {
|
|
74
|
+
if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {
|
|
113
75
|
return {
|
|
114
|
-
className: [
|
|
115
|
-
style: (
|
|
76
|
+
className: [this.props.className, this.props.activeClassName].filter(Boolean).join(` `),
|
|
77
|
+
style: _extends({}, this.props.style, this.props.activeStyle)
|
|
116
78
|
};
|
|
117
79
|
}
|
|
118
80
|
|
|
119
81
|
return null;
|
|
120
82
|
};
|
|
121
83
|
|
|
122
|
-
|
|
84
|
+
let IOSupported = false;
|
|
123
85
|
|
|
124
|
-
if (typeof window !==
|
|
86
|
+
if (typeof window !== `undefined` && window.IntersectionObserver) {
|
|
125
87
|
IOSupported = true;
|
|
126
88
|
}
|
|
127
89
|
|
|
128
|
-
|
|
129
|
-
IOSupported
|
|
90
|
+
this.state = {
|
|
91
|
+
IOSupported
|
|
130
92
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return _this;
|
|
93
|
+
this.abortPrefetch = null;
|
|
94
|
+
this.handleRef = this.handleRef.bind(this);
|
|
134
95
|
}
|
|
135
96
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
_proto._prefetch = function _prefetch() {
|
|
139
|
-
var currentPath = window.location.pathname + window.location.search; // reach router should have the correct state
|
|
97
|
+
_prefetch() {
|
|
98
|
+
let currentPath = window.location.pathname + window.location.search; // reach router should have the correct state
|
|
140
99
|
|
|
141
100
|
if (this.props._location && this.props._location.pathname) {
|
|
142
101
|
currentPath = this.props._location.pathname + this.props._location.search;
|
|
143
102
|
}
|
|
144
103
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
104
|
+
const rewrittenPath = rewriteLinkPath(this.props.to, currentPath);
|
|
105
|
+
const parsed = parsePath(rewrittenPath);
|
|
106
|
+
const newPathName = parsed.pathname + parsed.search; // Prefetch is used to speed up next navigations. When you use it on the current navigation,
|
|
148
107
|
// there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete
|
|
149
108
|
|
|
150
109
|
if (currentPath !== newPathName) {
|
|
@@ -152,16 +111,17 @@ var GatsbyLink = /*#__PURE__*/function (_React$Component) {
|
|
|
152
111
|
}
|
|
153
112
|
|
|
154
113
|
return undefined;
|
|
155
|
-
}
|
|
114
|
+
}
|
|
156
115
|
|
|
157
|
-
|
|
116
|
+
componentWillUnmount() {
|
|
158
117
|
if (!this.io) {
|
|
159
118
|
return;
|
|
160
119
|
}
|
|
161
120
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
121
|
+
const {
|
|
122
|
+
instance,
|
|
123
|
+
el
|
|
124
|
+
} = this.io;
|
|
165
125
|
|
|
166
126
|
if (this.abortPrefetch) {
|
|
167
127
|
this.abortPrefetch.abort();
|
|
@@ -169,12 +129,10 @@ var GatsbyLink = /*#__PURE__*/function (_React$Component) {
|
|
|
169
129
|
|
|
170
130
|
instance.unobserve(el);
|
|
171
131
|
instance.disconnect();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
_proto.handleRef = function handleRef(ref) {
|
|
175
|
-
var _this2 = this;
|
|
132
|
+
}
|
|
176
133
|
|
|
177
|
-
|
|
134
|
+
handleRef(ref) {
|
|
135
|
+
if (this.props.innerRef && Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)) {
|
|
178
136
|
this.props.innerRef.current = ref;
|
|
179
137
|
} else if (this.props.innerRef) {
|
|
180
138
|
this.props.innerRef(ref);
|
|
@@ -182,85 +140,80 @@ var GatsbyLink = /*#__PURE__*/function (_React$Component) {
|
|
|
182
140
|
|
|
183
141
|
if (this.state.IOSupported && ref) {
|
|
184
142
|
// If IO supported and element reference found, setup Observer functionality
|
|
185
|
-
this.io = createIntersectionObserver(ref,
|
|
143
|
+
this.io = createIntersectionObserver(ref, inViewPort => {
|
|
186
144
|
if (inViewPort) {
|
|
187
|
-
|
|
145
|
+
this.abortPrefetch = this._prefetch();
|
|
188
146
|
} else {
|
|
189
|
-
if (
|
|
190
|
-
|
|
147
|
+
if (this.abortPrefetch) {
|
|
148
|
+
this.abortPrefetch.abort();
|
|
191
149
|
}
|
|
192
150
|
}
|
|
193
151
|
});
|
|
194
152
|
}
|
|
195
|
-
}
|
|
153
|
+
}
|
|
196
154
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
_location = _this$props._location,
|
|
213
|
-
rest = (0, _objectWithoutPropertiesLoose2.default)(_this$props, _excluded);
|
|
214
|
-
|
|
215
|
-
if (process.env.NODE_ENV !== "production" && !(0, _isLocalLink.isLocalLink)(to)) {
|
|
216
|
-
console.warn("External link " + to + " was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links");
|
|
155
|
+
render() {
|
|
156
|
+
const _this$props = this.props,
|
|
157
|
+
{
|
|
158
|
+
to,
|
|
159
|
+
getProps = this.defaultGetProps,
|
|
160
|
+
onClick,
|
|
161
|
+
onMouseEnter,
|
|
162
|
+
state,
|
|
163
|
+
replace,
|
|
164
|
+
_location
|
|
165
|
+
} = _this$props,
|
|
166
|
+
rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
167
|
+
|
|
168
|
+
if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {
|
|
169
|
+
console.warn(`External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`);
|
|
217
170
|
}
|
|
218
171
|
|
|
219
|
-
|
|
172
|
+
const prefixedTo = rewriteLinkPath(to, _location.pathname);
|
|
220
173
|
|
|
221
|
-
if (!
|
|
222
|
-
return /*#__PURE__*/
|
|
174
|
+
if (!isLocalLink(prefixedTo)) {
|
|
175
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
223
176
|
href: prefixedTo
|
|
224
177
|
}, rest));
|
|
225
178
|
}
|
|
226
179
|
|
|
227
|
-
return /*#__PURE__*/
|
|
180
|
+
return /*#__PURE__*/React.createElement(Link, _extends({
|
|
228
181
|
to: prefixedTo,
|
|
229
182
|
state: state,
|
|
230
183
|
getProps: getProps,
|
|
231
184
|
innerRef: this.handleRef,
|
|
232
|
-
onMouseEnter:
|
|
233
|
-
if (
|
|
234
|
-
|
|
185
|
+
onMouseEnter: e => {
|
|
186
|
+
if (onMouseEnter) {
|
|
187
|
+
onMouseEnter(e);
|
|
235
188
|
}
|
|
236
189
|
|
|
237
|
-
|
|
190
|
+
const parsed = parsePath(prefixedTo);
|
|
238
191
|
|
|
239
192
|
___loader.hovering(parsed.pathname + parsed.search);
|
|
240
193
|
},
|
|
241
|
-
onClick:
|
|
242
|
-
if (
|
|
243
|
-
|
|
194
|
+
onClick: e => {
|
|
195
|
+
if (onClick) {
|
|
196
|
+
onClick(e);
|
|
244
197
|
}
|
|
245
198
|
|
|
246
199
|
if (e.button === 0 && // ignore right clicks
|
|
247
|
-
!
|
|
200
|
+
!this.props.target && // let browser handle "target=_blank"
|
|
248
201
|
!e.defaultPrevented && // onClick prevented default
|
|
249
202
|
!e.metaKey && // ignore clicks with modifier keys...
|
|
250
203
|
!e.altKey && !e.ctrlKey && !e.shiftKey) {
|
|
251
204
|
e.preventDefault();
|
|
252
|
-
|
|
205
|
+
let shouldReplace = replace;
|
|
253
206
|
|
|
254
|
-
|
|
207
|
+
const isCurrent = encodeURI(prefixedTo) === _location.pathname;
|
|
255
208
|
|
|
256
|
-
if (typeof replace !==
|
|
209
|
+
if (typeof replace !== `boolean` && isCurrent) {
|
|
257
210
|
shouldReplace = true;
|
|
258
211
|
} // Make sure the necessary scripts and data are
|
|
259
212
|
// loaded before continuing.
|
|
260
213
|
|
|
261
214
|
|
|
262
215
|
window.___navigate(prefixedTo, {
|
|
263
|
-
state
|
|
216
|
+
state,
|
|
264
217
|
replace: shouldReplace
|
|
265
218
|
});
|
|
266
219
|
}
|
|
@@ -268,28 +221,19 @@ var GatsbyLink = /*#__PURE__*/function (_React$Component) {
|
|
|
268
221
|
return true;
|
|
269
222
|
}
|
|
270
223
|
}, rest));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return GatsbyLink;
|
|
274
|
-
}(_react.default.Component);
|
|
224
|
+
}
|
|
275
225
|
|
|
276
|
-
|
|
277
|
-
onClick: _propTypes.default.func,
|
|
278
|
-
to: _propTypes.default.string.isRequired,
|
|
279
|
-
replace: _propTypes.default.bool,
|
|
280
|
-
state: _propTypes.default.object
|
|
281
|
-
});
|
|
226
|
+
}
|
|
282
227
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
228
|
+
GatsbyLink.propTypes = _extends({}, NavLinkPropTypes, {
|
|
229
|
+
onClick: PropTypes.func,
|
|
230
|
+
to: PropTypes.string.isRequired,
|
|
231
|
+
replace: PropTypes.bool,
|
|
232
|
+
state: PropTypes.object
|
|
287
233
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
window.___navigate(
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
exports.navigate = navigate;
|
|
234
|
+
export default /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(GatsbyLinkLocationWrapper, _extends({
|
|
235
|
+
innerRef: ref
|
|
236
|
+
}, props)));
|
|
237
|
+
export const navigate = (to, options) => {
|
|
238
|
+
window.___navigate(rewriteLinkPath(to, window.location.pathname), options);
|
|
239
|
+
};
|
package/is-local-link.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.isLocalLink = void 0;
|
|
5
1
|
// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js
|
|
6
|
-
|
|
2
|
+
const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
return ABSOLUTE_URL_REGEX.test(path);
|
|
10
|
-
};
|
|
4
|
+
const isAbsolute = path => ABSOLUTE_URL_REGEX.test(path);
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
if (typeof path !==
|
|
6
|
+
export const isLocalLink = path => {
|
|
7
|
+
if (typeof path !== `string`) {
|
|
14
8
|
return undefined; // TODO(v5): Re-Add TypeError
|
|
15
9
|
// throw new TypeError(`Expected a \`string\`, got \`${typeof path}\``)
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
return !isAbsolute(path);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
exports.isLocalLink = isLocalLink;
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-link",
|
|
3
3
|
"description": "An enhanced Link component for Gatsby sites with support for resource prefetching",
|
|
4
|
-
"version": "4.18.
|
|
4
|
+
"version": "4.18.1",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/runtime": "^7.15.4",
|
|
11
11
|
"@types/reach__router": "^1.3.10",
|
|
12
|
-
"gatsby-page-utils": "^2.18.
|
|
12
|
+
"gatsby-page-utils": "^2.18.1",
|
|
13
13
|
"prop-types": "^15.8.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@babel/cli": "^7.15.4",
|
|
17
17
|
"@babel/core": "^7.15.5",
|
|
18
18
|
"@testing-library/react": "^11.2.7",
|
|
19
|
-
"babel-preset-gatsby-package": "^2.18.0
|
|
19
|
+
"babel-preset-gatsby-package": "^2.18.0",
|
|
20
20
|
"cross-env": "^7.0.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=14.15.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c6aa79d485c32ed81f22ec056669e8cd1766dd62"
|
|
48
48
|
}
|
package/parse-path.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function parsePath(path) {
|
|
7
|
-
var pathname = path || "/";
|
|
8
|
-
var search = "";
|
|
9
|
-
var hash = "";
|
|
10
|
-
var hashIndex = pathname.indexOf("#");
|
|
1
|
+
export function parsePath(path) {
|
|
2
|
+
let pathname = path || `/`;
|
|
3
|
+
let search = ``;
|
|
4
|
+
let hash = ``;
|
|
5
|
+
const hashIndex = pathname.indexOf(`#`);
|
|
11
6
|
|
|
12
7
|
if (hashIndex !== -1) {
|
|
13
8
|
hash = pathname.slice(hashIndex);
|
|
14
9
|
pathname = pathname.slice(0, hashIndex);
|
|
15
10
|
}
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
const searchIndex = pathname.indexOf(`?`);
|
|
18
13
|
|
|
19
14
|
if (searchIndex !== -1) {
|
|
20
15
|
search = pathname.slice(searchIndex);
|
|
@@ -23,7 +18,7 @@ function parsePath(path) {
|
|
|
23
18
|
|
|
24
19
|
return {
|
|
25
20
|
pathname: pathname,
|
|
26
|
-
search: search ===
|
|
27
|
-
hash: hash ===
|
|
21
|
+
search: search === `?` ? `` : search,
|
|
22
|
+
hash: hash === `#` ? `` : hash
|
|
28
23
|
};
|
|
29
24
|
}
|
package/rewrite-link-path.js
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from "@gatsbyjs/reach-router/lib/utils"; // Specific import to treeshake Node.js stuff
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { applyTrailingSlashOption } from "gatsby-page-utils/apply-trailing-slash-option";
|
|
4
|
+
import { parsePath } from "./parse-path";
|
|
5
|
+
import { isLocalLink } from "./is-local-link";
|
|
6
|
+
import { withPrefix } from ".";
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const isAbsolutePath = path => path === null || path === void 0 ? void 0 : path.startsWith(`/`);
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _parsePath2 = require("./parse-path");
|
|
11
|
-
|
|
12
|
-
var _isLocalLink = require("./is-local-link");
|
|
13
|
-
|
|
14
|
-
var _ = require(".");
|
|
15
|
-
|
|
16
|
-
// Specific import to treeshake Node.js stuff
|
|
17
|
-
var isAbsolutePath = function isAbsolutePath(path) {
|
|
18
|
-
return path === null || path === void 0 ? void 0 : path.startsWith("/");
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
var getGlobalTrailingSlash = function getGlobalTrailingSlash() {
|
|
22
|
-
return typeof __TRAILING_SLASH__ !== "undefined" ? __TRAILING_SLASH__ : undefined;
|
|
23
|
-
};
|
|
10
|
+
const getGlobalTrailingSlash = () => typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined;
|
|
24
11
|
|
|
25
12
|
function absolutify(path, current) {
|
|
26
13
|
// If it's already absolute, return as-is
|
|
@@ -28,39 +15,37 @@ function absolutify(path, current) {
|
|
|
28
15
|
return path;
|
|
29
16
|
}
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const option = getGlobalTrailingSlash();
|
|
19
|
+
const absolutePath = resolve(path, current);
|
|
33
20
|
|
|
34
|
-
if (option ===
|
|
35
|
-
return
|
|
21
|
+
if (option === `always` || option === `never`) {
|
|
22
|
+
return applyTrailingSlashOption(absolutePath, option);
|
|
36
23
|
}
|
|
37
24
|
|
|
38
25
|
return absolutePath;
|
|
39
26
|
}
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
if (typeof path ===
|
|
28
|
+
export const rewriteLinkPath = (path, relativeTo) => {
|
|
29
|
+
if (typeof path === `number`) {
|
|
43
30
|
return path;
|
|
44
31
|
}
|
|
45
32
|
|
|
46
|
-
if (!
|
|
33
|
+
if (!isLocalLink(path)) {
|
|
47
34
|
return path;
|
|
48
35
|
}
|
|
49
36
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (option ===
|
|
59
|
-
|
|
60
|
-
adjustedPath =
|
|
37
|
+
const {
|
|
38
|
+
pathname,
|
|
39
|
+
search,
|
|
40
|
+
hash
|
|
41
|
+
} = parsePath(path);
|
|
42
|
+
const option = getGlobalTrailingSlash();
|
|
43
|
+
let adjustedPath = path;
|
|
44
|
+
|
|
45
|
+
if (option === `always` || option === `never`) {
|
|
46
|
+
const output = applyTrailingSlashOption(pathname, option);
|
|
47
|
+
adjustedPath = `${output}${search}${hash}`;
|
|
61
48
|
}
|
|
62
49
|
|
|
63
|
-
return isAbsolutePath(adjustedPath) ?
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.rewriteLinkPath = rewriteLinkPath;
|
|
50
|
+
return isAbsolutePath(adjustedPath) ? withPrefix(adjustedPath) : absolutify(adjustedPath, relativeTo);
|
|
51
|
+
};
|