basename($file), 'author' => '', 'date' => '', 'platform' => '', 'url' => '', 'tags' => [], 'duration' => '', 'type' => 'article' ]; // 提取并移除 YAML front matter if (preg_match('/^---\s*\n(.*?)\n---\s*\n(.*)$/s', $content, $matches)) { $yaml = $matches[1]; $content = $matches[2]; if (preg_match('/^title:\s*["\']?(.+?)["\']?\s*$/m', $yaml, $m)) { $meta['title'] = trim($m[1], '"\''); } if (preg_match('/^author:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['author'] = trim($m[1]); } if (preg_match('/^date:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['date'] = trim($m[1]); } if (preg_match('/^platform:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['platform'] = trim($m[1]); } if (preg_match('/^url:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['url'] = trim($m[1]); } if (preg_match('/^duration:\s*(.+?)\s*$/m', $yaml, $m)) { $meta['duration'] = trim($m[1]); $meta['type'] = 'video'; } if (preg_match('/^tags:\s*\[(.+)\]\s*$/m', $yaml, $m)) { $tagsStr = $m[1]; preg_match_all('/"([^"]+)"/', $tagsStr, $tagMatches); $meta['tags'] = $tagMatches[1] ?? []; } } // Markdown 转换 function markdownToHtml($text) { $text = preg_replace('/^#### (.*$)/m', '

$1

', $text); $text = preg_replace('/^### (.*$)/m', '

$1

', $text); $text = preg_replace('/^## (.*$)/m', '

$1

', $text); $text = preg_replace('/^# (.*$)/m', '

$1

', $text); $text = preg_replace('/\*\*(.+?)\*\*/', '$1', $text); $text = preg_replace('/\*(.+?)\*/', '$1', $text); $text = preg_replace('/```(\w*)\n(.*?)```/s', '
$2
', $text); $text = preg_replace('/`(.+?)`/', '$1', $text); $text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text); $text = preg_replace('/^- (.*$)/m', '
  • $1
  • ', $text); $text = preg_replace('/(
  • .*<\/li>\n?)+/', '', $text); $text = preg_replace('/\n\n/', '

    ', $text); $text = '

    ' . $text . '

    '; return $text; } function highlightSearch($text, $search) { if (empty($search)) return $text; return preg_replace('/(' . preg_quote($search, '/') . ')/i', '$1', $text); } $htmlContent = markdownToHtml(htmlspecialchars($content)); if ($search) { $htmlContent = highlightSearch($htmlContent, $search); } $folder = dirname($file) !== '.' ? dirname($file) : ''; // 平台配置 function getPlatformInfo($platform) { $platforms = [ 'bilibili' => ['name' => 'Bilibili', 'icon' => '📺', 'color' => '#fb7299'], 'youtube' => ['name' => 'YouTube', 'icon' => '▶️', 'color' => '#ff0000'], 'zhihu' => ['name' => '知乎', 'icon' => '💡', 'color' => '#0084ff'], 'wechat' => ['name' => '微信', 'icon' => '💬', 'color' => '#07c160'], ]; return $platforms[$platform] ?? ['name' => $platform ?: '未知', 'icon' => '📄', 'color' => '#666']; } $platformInfo = getPlatformInfo($meta['platform']); ?> <?php echo htmlspecialchars($meta['title']); ?> - 知识库
    ← 返回列表

    📁
    作者 👤
    发布时间 📅
    平台
    时长 ⏱️
    类型
    源链接 🔗
    标签