gatsby-link 4.3.0 → 4.6.0-next.0
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/CHANGELOG.md +7 -1
- package/is-local-link.js +10 -0
- package/package.json +3 -3
- package/rewrite-link-path.js +59 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [4.
|
|
6
|
+
## [4.4.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.4.0/packages/gatsby-link) (2021-12-14)
|
|
7
|
+
|
|
8
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.4)
|
|
9
|
+
|
|
10
|
+
**Note:** Version bump only for package gatsby-link
|
|
11
|
+
|
|
12
|
+
## [4.3.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.3.0/packages/gatsby-link) (2021-12-01)
|
|
7
13
|
|
|
8
14
|
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.3)
|
|
9
15
|
|
package/is-local-link.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.isLocalLink = void 0;
|
|
5
|
+
|
|
6
|
+
var isLocalLink = function isLocalLink(path) {
|
|
7
|
+
return path && !path.startsWith("http://") && !path.startsWith("https://") && !path.startsWith("//");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.isLocalLink = isLocalLink;
|
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.
|
|
4
|
+
"version": "4.6.0-next.0",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@babel/cli": "^7.15.4",
|
|
16
16
|
"@babel/core": "^7.15.5",
|
|
17
17
|
"@testing-library/react": "^11.2.7",
|
|
18
|
-
"babel-preset-gatsby-package": "^2.
|
|
18
|
+
"babel-preset-gatsby-package": "^2.6.0-next.0",
|
|
19
19
|
"cross-env": "^7.0.3"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=14.15.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "b95120b3d59a4135a7aafc1b1ae49a5b68dbb9a8"
|
|
47
47
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.rewriteLinkPath = void 0;
|
|
5
|
+
|
|
6
|
+
var _utils = require("@gatsbyjs/reach-router/lib/utils");
|
|
7
|
+
|
|
8
|
+
var _applyTrailingSlashOption = require("gatsby-page-utils/apply-trailing-slash-option");
|
|
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 process.env.NODE_ENV !== "production" ? typeof __TRAILING_SLASH__ !== "undefined" ? __TRAILING_SLASH__ : undefined : __TRAILING_SLASH__;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function absolutify(path, current) {
|
|
26
|
+
// If it's already absolute, return as-is
|
|
27
|
+
if (isAbsolutePath(path)) {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (0, _utils.resolve)(path, current);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var rewriteLinkPath = function rewriteLinkPath(path, relativeTo) {
|
|
35
|
+
if (typeof path === "number") {
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!(0, _isLocalLink.isLocalLink)(path)) {
|
|
40
|
+
return path;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var _parsePath = (0, _parsePath2.parsePath)(path),
|
|
44
|
+
pathname = _parsePath.pathname,
|
|
45
|
+
search = _parsePath.search,
|
|
46
|
+
hash = _parsePath.hash;
|
|
47
|
+
|
|
48
|
+
var option = getGlobalTrailingSlash();
|
|
49
|
+
var adjustedPath = path;
|
|
50
|
+
|
|
51
|
+
if (option === "always" || option === "never") {
|
|
52
|
+
var output = (0, _applyTrailingSlashOption.applyTrailingSlashOption)(pathname, option);
|
|
53
|
+
adjustedPath = "" + output + search + hash;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return isAbsolutePath(adjustedPath) ? (0, _.withPrefix)(adjustedPath) : absolutify(adjustedPath, relativeTo);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.rewriteLinkPath = rewriteLinkPath;
|