mirror of
https://github.com/redlib-org/redlib.git
synced 2025-04-03 21:17:37 +03:00
Embed css themes to simplify adding and testing new themes (#489)
This commit is contained in:
parent
1c8bcf33c1
commit
60c7b6b23f
14 changed files with 274 additions and 121 deletions
15
src/utils.rs
15
src/utils.rs
|
@ -11,6 +11,7 @@ use std::collections::{HashMap, HashSet};
|
|||
use std::str::FromStr;
|
||||
use time::{Duration, OffsetDateTime, macros::format_description};
|
||||
use url::Url;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
// Post flair with content, background color and foreground color
|
||||
pub struct Flair {
|
||||
|
@ -445,6 +446,7 @@ pub struct Params {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct Preferences {
|
||||
pub available_themes: Vec<String>,
|
||||
pub theme: String,
|
||||
pub front_page: String,
|
||||
pub layout: String,
|
||||
|
@ -459,10 +461,23 @@ pub struct Preferences {
|
|||
pub filters: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "static/themes/"]
|
||||
#[include = "*.css"]
|
||||
pub struct ThemeAssets;
|
||||
|
||||
impl Preferences {
|
||||
// Build preferences from cookies
|
||||
pub fn new(req: Request<Body>) -> Self {
|
||||
// Read available theme names from embedded css files.
|
||||
// Always make the default "system" theme available.
|
||||
let mut themes = vec!["system".to_string()];
|
||||
for file in ThemeAssets::iter() {
|
||||
let chunks: Vec<&str> = file.as_ref().split(".css").collect();
|
||||
themes.push(chunks[0].to_owned())
|
||||
}
|
||||
Self {
|
||||
available_themes: themes,
|
||||
theme: setting(&req, "theme"),
|
||||
front_page: setting(&req, "front_page"),
|
||||
layout: setting(&req, "layout"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue