| Crates.io | blogr-themes |
| lib.rs | blogr-themes |
| version | 0.4.1 |
| created_at | 2025-09-20 14:34:54.541866+00 |
| updated_at | 2025-10-04 07:45:51.052505+00 |
| description | Theme system for Blogr static site generator |
| homepage | |
| repository | https://github.com/bahdotsh/blogr |
| max_upload_size | |
| id | 1847826 |
| size | 363,536 |
The theme system for Blogr static site generator, providing beautiful and customizable themes for blogs.
Blogr Themes is a library that provides the theme system for the Blogr static site generator. It includes built-in themes and a flexible architecture for creating custom themes.
Current Version: 0.4.0
This crate uses independent versioning from the main Blogr CLI to allow for theme-specific updates and improvements.
Add to your Cargo.toml:
[dependencies]
blogr-themes = "0.4.0"
use blogr_themes::{ThemeManager, get_theme};
// Get a theme by name
let theme = get_theme("minimal_retro")?;
// Get theme information
let info = theme.info();
println!("Theme: {} v{}", info.name, info.version);
// Get templates
let templates = theme.templates();
let base_template = templates.get("base.html").unwrap();
// Get assets (CSS, images, etc.)
let assets = theme.assets();
use blogr_themes::ThemeManager;
let mut manager = ThemeManager::new();
// List available themes
let themes = manager.list_themes();
for theme_name in themes {
println!("Available theme: {}", theme_name);
}
// Load a specific theme
let theme = manager.load_theme("obsidian")?;
Each theme implements the Theme trait:
pub trait Theme {
fn info(&self) -> ThemeInfo;
fn templates(&self) -> HashMap<String, String>;
fn assets(&self) -> HashMap<String, Vec<u8>>;
fn preview_tui_style(&self) -> ratatui::style::Style;
}
pub struct ThemeInfo {
pub name: String,
pub version: String,
pub author: String,
pub description: String,
pub config_schema: HashMap<String, ConfigOption>,
}
Themes can define configurable options:
pub struct ConfigOption {
pub option_type: String, // "string", "boolean", "number"
pub default: String, // Default value
pub description: String, // Help text
}
Themes use the Tera templating engine with these standard templates:
base.html - Base layout templateindex.html - Homepage templatepost.html - Individual post templatearchive.html - Archive page templatetags.html - Tags index templatetag.html - Individual tag page templateCommon variables available in templates:
<!-- Site configuration -->
{{ site.blog.title }}
{{ site.blog.description }}
{{ site.blog.author }}
{{ site.theme.config.* }}
<!-- Post data -->
{{ post.metadata.title }}
{{ post.metadata.date }}
{{ post.metadata.tags }}
{{ post.content }}
<!-- Collections -->
{{ posts }} <!-- All posts -->
{{ tags }} <!-- All tags with counts -->
Built-in template functions:
<!-- Generate URLs -->
{{ url(path="posts/my-post.html") }}
{{ asset_url(path="css/style.css") }}
<!-- Date formatting -->
{{ post.metadata.date | date(format="%Y-%m-%d") }}
use blogr_themes::{Theme, ThemeInfo, ConfigOption};
use std::collections::HashMap;
pub struct MyCustomTheme;
impl Theme for MyCustomTheme {
fn info(&self) -> ThemeInfo {
let mut schema = HashMap::new();
schema.insert("primary_color".to_string(), ConfigOption {
option_type: "string".to_string(),
default: "#007acc".to_string(),
description: "Primary theme color".to_string(),
});
ThemeInfo {
name: "My Custom Theme".to_string(),
version: "1.0.0".to_string(),
author: "Your Name".to_string(),
description: "A custom theme for my blog".to_string(),
config_schema: schema,
}
}
fn templates(&self) -> HashMap<String, String> {
let mut templates = HashMap::new();
templates.insert(
"base.html".to_string(),
include_str!("templates/base.html").to_string(),
);
// Add more templates...
templates
}
fn assets(&self) -> HashMap<String, Vec<u8>> {
let mut assets = HashMap::new();
assets.insert(
"css/style.css".to_string(),
include_bytes!("assets/style.css").to_vec(),
);
// Add more assets...
assets
}
fn preview_tui_style(&self) -> ratatui::style::Style {
use ratatui::style::{Color, Style};
Style::default()
.fg(Color::Blue)
.bg(Color::Black)
}
}
use blogr_themes::ThemeManager;
let mut manager = ThemeManager::new();
manager.register_theme("my_custom", Box::new(MyCustomTheme));
Themes can bundle assets (CSS, images, fonts) directly into the binary:
fn assets(&self) -> HashMap<String, Vec<u8>> {
let mut assets = HashMap::new();
// Bundle CSS
assets.insert(
"css/style.css".to_string(),
include_bytes!("assets/style.css").to_vec(),
);
// Bundle images
assets.insert(
"images/logo.png".to_string(),
include_bytes!("assets/logo.png").to_vec(),
);
assets
}
Themes can provide custom styling for the terminal user interface:
fn preview_tui_style(&self) -> ratatui::style::Style {
use ratatui::style::{Color, Style};
Style::default()
.fg(Color::Rgb(167, 139, 250)) // Purple accent
.bg(Color::Rgb(32, 32, 32)) // Dark background
}
cargo build
cargo test
src/Theme traittemplates/assets/lib.rsWe welcome theme contributions! Please:
See the main CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by bahdotsh