From 6ee952133d0e8fe56e27ddb6af3d65edeecc6f42 Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Tue, 15 Apr 2025 13:30:05 +0200 Subject: [PATCH] feat: Add config.lang for translation links --- src/main.rs | 14 +++++++++++--- src/template_engine.rs | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index a1e7508..3779967 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,8 +28,9 @@ use crate::fetcher::Fetcher; use anyhow::Result; use camino::{Utf8Path, Utf8PathBuf}; use clap::Parser; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::fs; +use url::Url; //mod atom_serializer; mod feed_store; @@ -76,10 +77,17 @@ struct Config { /// 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, + /// List of languages for translations + #[serde(default)] + lang: Vec, } -pub fn to_checked_pathbuf(dir: &str) -> Utf8PathBuf { - let dir = Utf8PathBuf::from(dir); +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Lang { + code: String, + name: String, + link: Url, +} pub fn to_checked_pathbuf(dir: &Utf8Path) -> Utf8PathBuf { let m = dir diff --git a/src/template_engine.rs b/src/template_engine.rs index 63582ab..32cd841 100644 --- a/src/template_engine.rs +++ b/src/template_engine.rs @@ -20,6 +20,7 @@ pub fn build(config: &Config, feed_store: &mut FeedStore) -> Result<()> { let (feeds, entries): (HashMap, _) = feed_store.collect(config.max_entries); context.insert("feeds", &feeds); context.insert("entries", &entries); + context.insert("lang", &config.lang); context.insert("PKG_AUTHORS", env!("CARGO_PKG_AUTHORS")); context.insert("PKG_HOMEPAGE", env!("CARGO_PKG_HOMEPAGE")); context.insert("PKG_NAME", env!("CARGO_PKG_NAME"));