rehype-og-card 3.0.0 → 3.1.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/dist/index.js +15 -9
- package/dist/util/hast.js +10 -8
- package/dist/util/network.js +9 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ const rehypeOGCard = (options) => {
|
|
|
95
95
|
const targetURL = new URL(anchorNode.properties.href);
|
|
96
96
|
if (mergedOptions.excludeDomains.includes(targetURL.hostname))
|
|
97
97
|
return;
|
|
98
|
-
// eslint-disable-next-line jsdoc/require-jsdoc, max-statements, max-lines-per-function
|
|
98
|
+
// eslint-disable-next-line jsdoc/require-jsdoc, max-statements, max-lines-per-function
|
|
99
99
|
const linkCardPromise = async () => {
|
|
100
100
|
let OGData = mergedOptions.buildCache
|
|
101
101
|
? await restoreOGDataBuildCache(anchorNode.properties.href, mergedOptions.buildCachePath, mergedOptions.buildCacheMaxAge)
|
|
@@ -117,11 +117,14 @@ const rehypeOGCard = (options) => {
|
|
|
117
117
|
});
|
|
118
118
|
if (filename) {
|
|
119
119
|
OGData.OGImageURL = path.posix.join("/rehype-og-card", filename);
|
|
120
|
+
if (mergedOptions.buildCache) {
|
|
121
|
+
const downloadedFilePath = path.join(mergedOptions.serverCachePath, filename);
|
|
122
|
+
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
123
|
+
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
124
|
+
}
|
|
120
125
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
124
|
-
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
126
|
+
else {
|
|
127
|
+
delete OGData.OGImageURL;
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
if (OGData.faviconURL && mergedOptions.serverCache) {
|
|
@@ -133,11 +136,14 @@ const rehypeOGCard = (options) => {
|
|
|
133
136
|
});
|
|
134
137
|
if (filename) {
|
|
135
138
|
OGData.faviconURL = path.posix.join("/rehype-og-card", filename);
|
|
139
|
+
if (mergedOptions.buildCache) {
|
|
140
|
+
const downloadedFilePath = path.join(mergedOptions.serverCachePath, filename);
|
|
141
|
+
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
142
|
+
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
143
|
+
}
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const buildCachePath = path.join(mergedOptions.buildCachePath, filename);
|
|
140
|
-
void saveBuildCacheFile(downloadedFilePath, buildCachePath);
|
|
145
|
+
else {
|
|
146
|
+
delete OGData.faviconURL;
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
if (mergedOptions.shortenURL) {
|
package/dist/util/hast.js
CHANGED
|
@@ -42,14 +42,16 @@ const createOGCard = (data, options) => {
|
|
|
42
42
|
h("div.og-card-title", data.title),
|
|
43
43
|
data.description ? h("div.og-card-description", data.description) : null,
|
|
44
44
|
h("div.og-card-url-container", [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
data.faviconURL
|
|
46
|
+
? h("img.og-card-favicon", {
|
|
47
|
+
alt: "favicon",
|
|
48
|
+
decoding: options.decoding,
|
|
49
|
+
height: 16,
|
|
50
|
+
loading: options.loading,
|
|
51
|
+
src: data.faviconURL,
|
|
52
|
+
width: 16
|
|
53
|
+
})
|
|
54
|
+
: null,
|
|
53
55
|
h("span.og-card-url", data.displayURL)
|
|
54
56
|
])
|
|
55
57
|
]),
|
package/dist/util/network.js
CHANGED
|
@@ -107,6 +107,15 @@ const downloadImage = async (options) => {
|
|
|
107
107
|
// eslint-disable-next-line no-magic-numbers
|
|
108
108
|
signal: AbortSignal.timeout(10 * 1000)
|
|
109
109
|
});
|
|
110
|
+
if (!response.ok)
|
|
111
|
+
return null;
|
|
112
|
+
const contentType = response.headers.get("content-type");
|
|
113
|
+
const normalizedContentType = contentType?.split(";")[0]?.trim().toLowerCase();
|
|
114
|
+
if (!normalizedContentType?.startsWith("image/")) {
|
|
115
|
+
// eslint-disable-next-line no-console
|
|
116
|
+
console.error("[rehype-og-card] Invalid image content type:", contentType ?? "unknown", "for", options.url);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
110
119
|
const arrayBuffer = await response.arrayBuffer();
|
|
111
120
|
const buffer = Buffer.from(arrayBuffer);
|
|
112
121
|
const saveDirectoryExists = await checkFileExists(options.directory);
|