fix theme

This commit is contained in:
2025-06-14 01:17:18 +09:00
parent 5c13dc0a1c
commit a4114c5be3
4 changed files with 12 additions and 3 deletions

View File

@ -7,6 +7,7 @@ author = "syui"
[build] [build]
highlight_code = true highlight_code = true
highlight_theme = "Monokai"
minify = false minify = false
[ai] [ai]

View File

@ -23,6 +23,7 @@ pub struct SiteConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BuildConfig { pub struct BuildConfig {
pub highlight_code: bool, pub highlight_code: bool,
pub highlight_theme: Option<String>,
pub minify: bool, pub minify: bool,
} }
@ -146,6 +147,7 @@ impl Default for Config {
}, },
build: BuildConfig { build: BuildConfig {
highlight_code: true, highlight_code: true,
highlight_theme: Some("Monokai".to_string()),
minify: false, minify: false,
}, },
ai: Some(AiConfig { ai: Some(AiConfig {

View File

@ -18,7 +18,7 @@ pub struct Generator {
impl Generator { impl Generator {
pub fn new(base_path: PathBuf, config: Config) -> Result<Self> { pub fn new(base_path: PathBuf, config: Config) -> Result<Self> {
let markdown_processor = MarkdownProcessor::new(config.build.highlight_code); let markdown_processor = MarkdownProcessor::new(config.build.highlight_code, config.build.highlight_theme.clone());
let template_engine = TemplateEngine::new(base_path.join("templates"))?; let template_engine = TemplateEngine::new(base_path.join("templates"))?;
let ai_manager = if let Some(ref ai_config) = config.ai { let ai_manager = if let Some(ref ai_config) = config.ai {

View File

@ -9,14 +9,16 @@ use serde_json::Value;
pub struct MarkdownProcessor { pub struct MarkdownProcessor {
highlight_code: bool, highlight_code: bool,
highlight_theme: String,
syntax_set: SyntaxSet, syntax_set: SyntaxSet,
theme_set: ThemeSet, theme_set: ThemeSet,
} }
impl MarkdownProcessor { impl MarkdownProcessor {
pub fn new(highlight_code: bool) -> Self { pub fn new(highlight_code: bool, highlight_theme: Option<String>) -> Self {
Self { Self {
highlight_code, highlight_code,
highlight_theme: highlight_theme.unwrap_or_else(|| "Monokai".to_string()),
syntax_set: SyntaxSet::load_defaults_newlines(), syntax_set: SyntaxSet::load_defaults_newlines(),
theme_set: ThemeSet::load_defaults(), theme_set: ThemeSet::load_defaults(),
} }
@ -86,7 +88,11 @@ impl MarkdownProcessor {
let parser = Parser::new_ext(content, options); let parser = Parser::new_ext(content, options);
let mut html_output = String::new(); let mut html_output = String::new();
let mut code_block = None; let mut code_block = None;
let theme = &self.theme_set.themes["base16-ocean.dark"]; let theme = self.theme_set.themes.get(&self.highlight_theme)
.or_else(|| self.theme_set.themes.get("Monokai"))
.or_else(|| self.theme_set.themes.get("InspiredGitHub"))
.or_else(|| self.theme_set.themes.get("base16-ocean.dark"))
.unwrap_or_else(|| self.theme_set.themes.values().next().unwrap());
let mut events = Vec::new(); let mut events = Vec::new();
for event in parser { for event in parser {