修复Presentation组件无法加载md文件里面的theme主题的问题

This commit is contained in:
jingrow 2025-09-03 23:47:37 +08:00
parent 65abd70f23
commit 067c136fe7

View File

@ -5,6 +5,17 @@ import Reveal from 'reveal.js';
import 'reveal.js/dist/reveal.css'; import 'reveal.js/dist/reveal.css';
import { marked } from 'marked'; import { marked } from 'marked';
const parseThemeFromContent = (content) => {
if (!content || !content.startsWith('---')) return null;
const frontmatterEnd = content.indexOf('---', 3);
if (frontmatterEnd === -1) return null;
const frontmatter = content.substring(3, frontmatterEnd);
const themeMatch = frontmatter.match(/theme:\s*(\w+)/);
return themeMatch ? themeMatch[1] : null;
};
const loadTheme = async (themeName) => { const loadTheme = async (themeName) => {
if (!themeName) return; if (!themeName) return;
@ -152,7 +163,7 @@ export default function Presentation({ data }) {
revealRef.current.destroy(); revealRef.current.destroy();
} }
const themeName = data.theme || 'default'; const themeName = data.theme || parseThemeFromContent(data.content) || 'default';
await loadTheme(themeName); await loadTheme(themeName);
revealRef.current = new Reveal(deckRef.current, REVEAL_CONFIG); revealRef.current = new Reveal(deckRef.current, REVEAL_CONFIG);