feat: add config.theme for templates subdirectory

This commit is contained in:
selfhoster selfhoster 2025-04-15 13:29:43 +02:00
parent 001ca4879a
commit 6e288b3525
3 changed files with 13 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use anyhow::{Result, bail}; use anyhow::{bail, Result};
use camino::{Utf8Path, Utf8PathBuf}; use camino::{Utf8Path, Utf8PathBuf};
use chrono::{DateTime, Duration, Utc}; use chrono::{DateTime, Duration, Utc};
use feed_rs::model::Entry; use feed_rs::model::Entry;
@ -259,7 +259,7 @@ impl FeedStore {
Err(e) => { Err(e) => {
warn!("Problem parsing feed file for feed {}: {}", feed_url, e); warn!("Problem parsing feed file for feed {}: {}", feed_url, e);
continue; continue;
}, }
}; };
for entry in &mut feed.entries { for entry in &mut feed.entries {

View File

@ -71,6 +71,11 @@ struct Config {
max_entries: usize, max_entries: usize,
/// How soon to refresh, in hours /// How soon to refresh, in hours
refresh: usize, refresh: usize,
/// A theme to apply, if any.
///
/// This is a folder in the templates_dir. If an assets directory
/// exists within, the contents will be copied over to the out_dir.
theme: Option<String>,
} }
pub fn to_checked_pathbuf(dir: &str) -> Utf8PathBuf { pub fn to_checked_pathbuf(dir: &str) -> Utf8PathBuf {

View File

@ -2,13 +2,18 @@ use crate::feed_store::FeedStore;
use crate::to_checked_pathbuf; use crate::to_checked_pathbuf;
use crate::Config; use crate::Config;
use anyhow::Result; use anyhow::Result;
use camino::Utf8Path;
use feed_rs::model::Feed; use feed_rs::model::Feed;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use tera::{from_value, Tera}; use tera::{from_value, Tera};
pub fn build(config: &Config, feed_store: &mut FeedStore) -> Result<()> { pub fn build(config: &Config, feed_store: &mut FeedStore) -> Result<()> {
let mut tera = create_tera(&config.templates_dir)?; let mut tera = if let Some(theme) = &config.theme {
create_tera(&config.templates_dir.join(theme))?
} else {
create_tera(&config.templates_dir)?
};
let out_dir = to_checked_pathbuf(&config.out_dir); let out_dir = to_checked_pathbuf(&config.out_dir);
let mut context = tera::Context::new(); let mut context = tera::Context::new();