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): ?>
+ 📝 字
+
📅