nodebb-plugin-onekite-discord 1.0.6 → 1.0.7
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/library.js +22 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
package/library.js
CHANGED
|
@@ -41,6 +41,26 @@ function ensureAbsoluteUrl(baseUrl, maybeUrl) {
|
|
|
41
41
|
return s;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
function normalizeExcerptLinks(input) {
|
|
46
|
+
if (!input) return '';
|
|
47
|
+
let s = String(input);
|
|
48
|
+
|
|
49
|
+
// Convert HTML anchors to "text (url)" before stripping HTML
|
|
50
|
+
s = s.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi, (m, href, inner) => {
|
|
51
|
+
const text = stripHtml(inner).trim() || href;
|
|
52
|
+
return `${text} (${href})`;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Convert Markdown links [text](url) to "text (url)"
|
|
56
|
+
s = s.replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, (m, label, url) => `${label} (${url})`);
|
|
57
|
+
|
|
58
|
+
// Fix common malformed scheme "https:/example.com" -> "https://example.com"
|
|
59
|
+
s = s.replace(/\b(https?):\/(?!\/)/g, '$1://');
|
|
60
|
+
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
function stripHtml(html) {
|
|
45
65
|
if (!html) return '';
|
|
46
66
|
return String(html)
|
|
@@ -142,7 +162,8 @@ async function getPostExcerpt(pid) {
|
|
|
142
162
|
if (!pid) return '';
|
|
143
163
|
try {
|
|
144
164
|
const p = await posts.getPostFields(pid, ['content']);
|
|
145
|
-
const
|
|
165
|
+
const normalized = normalizeExcerptLinks(p && p.content);
|
|
166
|
+
const text = stripHtml(normalized);
|
|
146
167
|
return truncate(text, 500);
|
|
147
168
|
} catch {
|
|
148
169
|
return '';
|
package/package.json
CHANGED
package/plugin.json
CHANGED