* Theming

- Custom CSS for blogs
- Custom themes for instance
- New dark theme
- UI to choose your instance theme
- Option to disable blog themes if you prefer to only have the instance theme
- UI to choose a blog theme
This commit is contained in:
Ana Gelez
2019-08-21 00:42:04 +02:00
committed by GitHub
parent fb60236a54
commit a6c84daa1a
203 changed files with 667 additions and 334 deletions
+46 -3
View File
@@ -2,15 +2,20 @@
use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};
use rocket::{
http::{
hyper::header::{CacheControl, CacheDirective},
hyper::header::{CacheControl, CacheDirective, ETag, EntityTag},
uri::{FromUriParam, Query},
RawStr, Status,
},
request::{self, FromFormValue, FromRequest, Request},
response::{Flash, NamedFile, Redirect},
response::{self, Flash, NamedFile, Redirect, Responder, Response},
Outcome,
};
use std::path::{Path, PathBuf};
use std::{
collections::hash_map::DefaultHasher,
hash::Hasher,
io::Read,
path::{Path, PathBuf},
};
use template_utils::Ructe;
use plume_models::{posts::Post, Connection};
@@ -168,6 +173,44 @@ pub struct CachedFile {
cache_control: CacheControl,
}
#[derive(Debug)]
pub struct ThemeFile(NamedFile);
impl<'r> Responder<'r> for ThemeFile {
fn respond_to(mut self, r: &Request) -> response::Result<'r> {
let mut contents = String::new();
self.0
.read_to_string(&mut contents)
.map_err(|_| Status::InternalServerError)?;
let mut hasher = DefaultHasher::new();
hasher.write(&contents.as_bytes());
let etag = format!("{:x}", hasher.finish());
if r.headers()
.get("If-None-Match")
.any(|s| s[1..s.len() - 1] == etag)
{
Response::build()
.status(Status::NotModified)
.header(ETag(EntityTag::strong(etag)))
.ok()
} else {
Response::build()
.merge(self.0.respond_to(r)?)
.header(ETag(EntityTag::strong(etag)))
.ok()
}
}
}
#[get("/static/cached/<_build_id>/css/<file..>", rank = 1)]
pub fn theme_files(file: PathBuf, _build_id: &RawStr) -> Option<ThemeFile> {
NamedFile::open(Path::new("static/").join(file))
.ok()
.map(ThemeFile)
}
#[get("/static/cached/<_build_id>/<file..>", rank = 2)]
pub fn plume_static_files(file: PathBuf, _build_id: &RawStr) -> Option<CachedFile> {
static_files(file)