From af4edfc4ae74b01829206257fb8fbff0c0d8641a Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Sat, 28 Feb 2026 23:19:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E7=AB=A0=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8E=9F=E6=96=87=E5=AD=97=E6=95=B0=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 解析 type 字段判断资源类型 - 文章类型计算正文字数并显示 - 视频类型保持显示时长/时间 --- dashboard.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/dashboard.php b/dashboard.php index b5b6349..088b5d6 100644 --- a/dashboard.php +++ b/dashboard.php @@ -21,6 +21,7 @@ function parseMarkdownWithMeta($filePath) { 'tags' => [], 'duration' => '', 'type' => 'article', + 'word_count' => 0, 'summary' => '' ]; @@ -47,6 +48,13 @@ function parseMarkdownWithMeta($filePath) { } if (preg_match('/^duration:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['duration'] = trim($m[1]); + } + // 解析 type 字段 + if (preg_match('/^type:\s*(.+?)\s*$/m', $yaml, $m)) { + $meta['type'] = trim($m[1]); + } + // 如果有 duration 但没有明确 type,则设为 video + if ($meta['duration'] && $meta['type'] === 'article') { $meta['type'] = 'video'; } if (preg_match('/^tags:\s*\[(.+)\]\s*$/m', $yaml, $m)) { @@ -55,6 +63,14 @@ function parseMarkdownWithMeta($filePath) { $meta['tags'] = $tagMatches[1] ?? []; } + // 计算正文字数(文章类型) + if ($meta['type'] === 'article') { + // 移除 Markdown 标记,计算纯文字字数 + $plainText = strip_tags($body); + $plainText = preg_replace('/[#*_`\[\]()]/', '', $plainText); + $meta['word_count'] = mb_strlen(preg_replace('/\s+/', '', $plainText)); + } + // 提取正文概述 $lines = preg_split('/\r?\n/', trim($body)); $summaryLines = []; @@ -115,6 +131,7 @@ function scanDirectory($dir, $baseDir, $search) { 'tags' => $meta['tags'], 'duration' => $meta['duration'], 'type' => $meta['type'], + 'word_count' => $meta['word_count'], 'summary' => $meta['summary'] ]; } @@ -209,7 +226,9 @@ function getTypeIcon($type) { 👤 - + 0): ?> + 📝 字 + 📅