rehype-og-card 0.4.0 → 0.4.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/dist/index.js +3 -3
- package/dist/util/network.js +10 -3
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ const rehypeOGCard = (options) => {
|
|
|
102
102
|
if (!OGData)
|
|
103
103
|
return;
|
|
104
104
|
if (mergedOptions.buildCache) {
|
|
105
|
-
|
|
105
|
+
void saveOGDataBuildCache(anchorNode.properties.href, OGData, mergedOptions.buildCachePath);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
if (OGData.OGImageURL && mergedOptions.serverCache) {
|
|
@@ -117,7 +117,7 @@ const rehypeOGCard = (options) => {
|
|
|
117
117
|
if (filename && mergedOptions.buildCache) {
|
|
118
118
|
const downloadedFilePath = path.join(mergedOptions.serverCachePath, filename);
|
|
119
119
|
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
120
|
-
|
|
120
|
+
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
if (OGData.faviconURL && mergedOptions.serverCache) {
|
|
@@ -132,7 +132,7 @@ const rehypeOGCard = (options) => {
|
|
|
132
132
|
if (filename && mergedOptions.buildCache) {
|
|
133
133
|
const downloadedFilePath = path.join(mergedOptions.serverCachePath, filename);
|
|
134
134
|
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
135
|
-
|
|
135
|
+
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
if (mergedOptions.shortenURL) {
|
package/dist/util/network.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { checkFileExists, generateFilename } from "./file.js";
|
|
11
|
+
import fetch from "node-fetch";
|
|
11
12
|
import fs from "fs/promises";
|
|
12
13
|
import path from "path";
|
|
13
14
|
import scraper from "open-graph-scraper";
|
|
@@ -18,9 +19,13 @@ import scraper from "open-graph-scraper";
|
|
|
18
19
|
*/
|
|
19
20
|
const isValidURL = (url) => {
|
|
20
21
|
const ALLOWED_PROTOCOLS = ["http:", "https:"];
|
|
22
|
+
const lowerCaseURL = url.toLowerCase();
|
|
23
|
+
const isLikelyURL = ALLOWED_PROTOCOLS.some((protocol) => lowerCaseURL.startsWith(protocol));
|
|
24
|
+
if (!isLikelyURL)
|
|
25
|
+
return false;
|
|
21
26
|
try {
|
|
22
|
-
|
|
23
|
-
return
|
|
27
|
+
new URL(url);
|
|
28
|
+
return true;
|
|
24
29
|
}
|
|
25
30
|
catch (_a) {
|
|
26
31
|
return false;
|
|
@@ -87,7 +92,9 @@ const downloadImage = (options) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
87
92
|
const response = yield fetch(options.url, {
|
|
88
93
|
headers: {
|
|
89
94
|
"user-agent": options.userAgent
|
|
90
|
-
}
|
|
95
|
+
},
|
|
96
|
+
// eslint-disable-next-line no-magic-numbers
|
|
97
|
+
signal: AbortSignal.timeout(10 * 1000)
|
|
91
98
|
});
|
|
92
99
|
const arrayBuffer = yield response.arrayBuffer();
|
|
93
100
|
const buffer = Buffer.from(arrayBuffer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rehype-og-card",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Rehype plugin to convert text links to link cards",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@types/hast": "^3.0.4",
|
|
60
60
|
"hast-util-is-element": "^3.0.0",
|
|
61
61
|
"hastscript": "^9.0.0",
|
|
62
|
+
"node-fetch": "^3.3.2",
|
|
62
63
|
"open-graph-scraper": "^6.6.3",
|
|
63
64
|
"unist-util-visit-parents": "^6.0.1"
|
|
64
65
|
}
|