@zachleat/fetch-links 1.0.2 → 1.0.3
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/links.js +14 -3
- package/package.json +1 -1
- package/test/test.js +3 -0
package/links.js
CHANGED
|
@@ -36,7 +36,7 @@ export class Links {
|
|
|
36
36
|
|
|
37
37
|
let posthtmlOptions = {
|
|
38
38
|
eachURL: function(url, attr, tagName, node) {
|
|
39
|
-
if(url.startsWith("#") || tagName === "img" || tagName === "video" || tagName === "source") {
|
|
39
|
+
if(url.startsWith("#") || url.startsWith("javascript:") || tagName === "img" || tagName === "video" || tagName === "source") {
|
|
40
40
|
return url;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -101,18 +101,29 @@ export class Links {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
static stripProtocol(url) {
|
|
105
|
+
if(url.startsWith("https://")) {
|
|
106
|
+
url = url.slice("https://".length);
|
|
107
|
+
} else if(url.startsWith("http://")) {
|
|
108
|
+
url = url.slice("http://".length);
|
|
109
|
+
}
|
|
110
|
+
return url;
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
static onlyKeepExternal(entry, originalUrl) {
|
|
105
114
|
if(entry.type) { // keep feeds and other important types
|
|
106
115
|
return true;
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
let comparison = originalUrl || "https://example.com";
|
|
110
|
-
let u = new URL(entry.url, comparison);
|
|
111
|
-
|
|
119
|
+
let u = this.stripProtocol((new URL(entry.url, comparison)).toString());
|
|
120
|
+
|
|
121
|
+
return !u.startsWith(this.stripProtocol(comparison));
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
static onlyKeepRelevant(entry) {
|
|
115
125
|
if(entry.via.find(via => via.startsWith("script[") ||
|
|
126
|
+
via.includes(`[rel="preload"]`) ||
|
|
116
127
|
via.includes(`[rel="dns-prefetch"]`) ||
|
|
117
128
|
via.includes(`[rel="token_endpoint"]`) ||
|
|
118
129
|
via.includes(`[rel="authorization_endpoint"]`) ||
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -10,7 +10,10 @@ test("zachleat.com", async (t) => {
|
|
|
10
10
|
// let originalUrl = "https://www.miriamsuzanne.com/";
|
|
11
11
|
// let originalUrl = "https://daverupert.com/";
|
|
12
12
|
// let originalUrl = "https://aaadaaam.com/";
|
|
13
|
+
// let originalUrl = "https://torvalds-family.blogspot.com/";
|
|
14
|
+
// let originalUrl = "https://wesbos.com/";
|
|
13
15
|
|
|
14
16
|
let filtered = await Links.find(originalUrl);
|
|
17
|
+
// console.log( filtered );
|
|
15
18
|
assert.ok(filtered.length > 0);
|
|
16
19
|
});
|