移除旧版 HTML 模板与兼容层,并完善私信、举报、媒体存储与 SEO。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
18
frontend/src/utils/seoText.ts
Normal file
18
frontend/src/utils/seoText.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/** 从 HTML 提取纯文本摘要(供页面 description / OG) */
|
||||
export function excerptFromHTML(html: string, max = 160): string {
|
||||
if (!html) return '';
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
const text = (doc.body.textContent || '').replace(/\s+/g, ' ').trim();
|
||||
if (text.length <= max) return text;
|
||||
return `${text.slice(0, Math.max(0, max - 1))}…`;
|
||||
}
|
||||
|
||||
/** 正文中第一张图片 URL */
|
||||
export function firstImageFromHTML(html: string): string {
|
||||
if (!html) return '';
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
const img = doc.querySelector('img[src]');
|
||||
const src = img?.getAttribute('src')?.trim() || '';
|
||||
if (!src || src.startsWith('data:')) return '';
|
||||
return src;
|
||||
}
|
||||
Reference in New Issue
Block a user