Add titles
This commit is contained in:
parent
4fadbc2d4b
commit
cd9dd8b34b
|
@ -32,11 +32,11 @@ async fn async_main(port: u16) {
|
|||
.and_then(handle_album);
|
||||
let media_path = warp::path!(String).and(client).and_then(handle_media);
|
||||
let root_handler = warp::path::end().map(|| warp::reply::html(
|
||||
format!("<html><head><style>body {{ background-color: black; color: black; text-align: center; }}\ndiv {{ border: 1px solid #008; background: #eef; padding: 0.5em 1em 0.5em 1em; }}</style></head><body><div><b><a href=\"https://gitlab.com/blankX/imgurx\" style=\"text-decoration: none;\">ImgurX v{}</a></b><br>An alternative JS-less Imgur frontend</div></body></html>", env!("CARGO_PKG_VERSION"))
|
||||
format!("<html><head><title>ImgurX v{0}</title><style>body {{ background-color: black; color: black; text-align: center; }}\ndiv {{ border: 1px solid #008; background: #eef; padding: 0.5em 1em 0.5em 1em; }}</style></head><body><div><b><a href=\"https://gitlab.com/blankX/imgurx\" style=\"text-decoration: none;\">ImgurX v{0}</a></b><br>An alternative JS-less Imgur frontend</div></body></html>", env!("CARGO_PKG_VERSION"))
|
||||
));
|
||||
let index_handler = warp::path("index.html").and(root_handler);
|
||||
let not_found_handler = warp::any().map(|| warp::reply::with_status(
|
||||
warp::reply::html("<html><head><style>body { background-color: black; color: white; text-align: center; }\ndiv { border: 1px solid #fcc; background: #fee; padding: 0.5em 1em 0.5em 1em; color: black; }</style></head><body><div><b>404: Not Found</b></div></body></html>"),
|
||||
warp::reply::html("<html><head><title>404: Not Found</title><style>body { background-color: black; color: white; text-align: center; }\ndiv { border: 1px solid #fcc; background: #fee; padding: 0.5em 1em 0.5em 1em; color: black; }</style></head><body><div><b>404: Not Found</b></div></body></html>"),
|
||||
404.try_into().unwrap(),
|
||||
));
|
||||
let routes = warp::filters::method::get().and(
|
||||
|
|
26
src/utils.rs
26
src/utils.rs
|
@ -48,6 +48,24 @@ pub fn generate_html(album: Result<Album, Error>) -> (u16, Vec<u8>) {
|
|||
let elem = BytesStart::owned(b"head".to_vec(), 4);
|
||||
writer.write_event(Event::Start(elem)).unwrap();
|
||||
|
||||
let (show_details, title) = match album {
|
||||
Ok(ref album) if !album.title.is_empty() => (false, Some(album.title.clone())),
|
||||
Err(Error::APIErrors(ref err)) if err.errors.len() == 1 && err.errors[0].code == "404" => {
|
||||
(false, Some(format!("404: {}", &err.errors[0].detail)))
|
||||
}
|
||||
_ => (true, None),
|
||||
};
|
||||
if let Some(title) = title {
|
||||
let elem = BytesStart::owned(b"title".to_vec(), 5);
|
||||
writer.write_event(Event::Start(elem)).unwrap();
|
||||
|
||||
let elem = BytesText::from_plain_str(&title);
|
||||
writer.write_event(Event::Text(elem)).unwrap();
|
||||
|
||||
let elem = BytesEnd::owned(b"title".to_vec());
|
||||
writer.write_event(Event::End(elem)).unwrap();
|
||||
}
|
||||
|
||||
let elem = BytesStart::owned(b"style".to_vec(), 5);
|
||||
writer.write_event(Event::Start(elem)).unwrap();
|
||||
|
||||
|
@ -155,14 +173,6 @@ pub fn generate_html(album: Result<Album, Error>) -> (u16, Vec<u8>) {
|
|||
200
|
||||
}
|
||||
Err(err) => {
|
||||
let show_details = match err {
|
||||
Error::APIErrors(ref err)
|
||||
if err.errors.len() == 1 && err.errors[0].code == "404" =>
|
||||
{
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
let mut elem = BytesStart::owned(b"div".to_vec(), 3);
|
||||
if show_details {
|
||||
elem.push_attribute(("style", "text-align: left;"));
|
||||
|
|
Loading…
Reference in New Issue