mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-08 07:37:45 +00: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
21
src/main.rs
21
src/main.rs
|
@ -19,7 +19,7 @@ use hyper::{header::HeaderValue, Body, Request, Response};
|
|||
mod client;
|
||||
use client::proxy;
|
||||
use server::RequestExt;
|
||||
use utils::{error, redirect};
|
||||
use utils::{error, redirect, ThemeAssets};
|
||||
|
||||
mod server;
|
||||
|
||||
|
@ -85,6 +85,23 @@ async fn resource(body: &str, content_type: &str, cache: bool) -> Result<Respons
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
async fn style() -> Result<Response<Body>, String> {
|
||||
let mut res = include_str!("../static/style.css").to_string();
|
||||
for file in ThemeAssets::iter() {
|
||||
res.push_str("\n");
|
||||
let theme = ThemeAssets::get(file.as_ref()).unwrap();
|
||||
res.push_str(std::str::from_utf8(theme.data.as_ref()).unwrap());
|
||||
}
|
||||
Ok(
|
||||
Response::builder()
|
||||
.status(200)
|
||||
.header("content-type", "text/css")
|
||||
.header("Cache-Control", "public, max-age=1209600, s-maxage=86400")
|
||||
.body(res.to_string().into())
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let matches = Command::new("Libreddit")
|
||||
|
@ -152,7 +169,7 @@ async fn main() {
|
|||
}
|
||||
|
||||
// Read static files
|
||||
app.at("/style.css").get(|_| resource(include_str!("../static/style.css"), "text/css", false).boxed());
|
||||
app.at("/style.css").get(|_| style().boxed());
|
||||
app
|
||||
.at("/manifest.json")
|
||||
.get(|_| resource(include_str!("../static/manifest.json"), "application/json", false).boxed());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue