Also put description and comments in a tab
This commit is contained in:
parent
3bb1ceaf49
commit
84f57449f8
129
src/main.rs
129
src/main.rs
@ -653,11 +653,17 @@ fn handle_relative_connection(
|
||||
.parent()
|
||||
.map(|parent| parent.with_extension("mlc"));
|
||||
|
||||
enum SectionInfo {
|
||||
Description,
|
||||
Comment(Vec<Comment>),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Section {
|
||||
title: Box<str>,
|
||||
lines: Vec<String>,
|
||||
config_map: Option<IndexMap<Box<str>, Box<str>>>,
|
||||
info: Option<SectionInfo>,
|
||||
}
|
||||
|
||||
let mut sections = Vec::new();
|
||||
@ -667,6 +673,7 @@ fn handle_relative_connection(
|
||||
title: "Game".into(),
|
||||
lines: Vec::new(),
|
||||
config_map,
|
||||
info: None,
|
||||
});
|
||||
} else {
|
||||
let Ok(pk_file) = File::open(file_paths.pk) else {
|
||||
@ -687,6 +694,7 @@ fn handle_relative_connection(
|
||||
title: title.into(),
|
||||
lines: vec![line],
|
||||
config_map: None,
|
||||
info: None,
|
||||
};
|
||||
|
||||
continue;
|
||||
@ -698,6 +706,22 @@ fn handle_relative_connection(
|
||||
sections.push(current_section);
|
||||
}
|
||||
|
||||
if file_paths.pki.is_some() {
|
||||
sections.push(Section {
|
||||
title: "Description".into(),
|
||||
lines: Vec::new(),
|
||||
config_map: None,
|
||||
info: Some(SectionInfo::Description),
|
||||
});
|
||||
}
|
||||
|
||||
sections.push(Section {
|
||||
title: "Comments".into(),
|
||||
lines: Vec::new(),
|
||||
config_map: None,
|
||||
info: Some(SectionInfo::Comment(comments)),
|
||||
});
|
||||
|
||||
let count = sections.len();
|
||||
|
||||
let _ = write!(stream, "<style>");
|
||||
@ -781,7 +805,10 @@ fn handle_relative_connection(
|
||||
for (
|
||||
i,
|
||||
Section {
|
||||
lines, config_map, ..
|
||||
lines,
|
||||
config_map,
|
||||
info,
|
||||
..
|
||||
},
|
||||
) in sections.into_iter().enumerate()
|
||||
{
|
||||
@ -814,60 +841,60 @@ fn handle_relative_connection(
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(info) = info {
|
||||
match info {
|
||||
SectionInfo::Description => {
|
||||
let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let _ = writeln!(stream, "<h1>Description</h1>");
|
||||
|
||||
if let Some(audio_path) = &file_paths.audio {
|
||||
if Path::is_file(audio_path) {
|
||||
let _ = writeln!(
|
||||
stream,
|
||||
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let lines = BufReader::new(pki_file).lines();
|
||||
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
|
||||
}
|
||||
SectionInfo::Comment(comments) => {
|
||||
let html = html! {
|
||||
h1 { "Comments" }
|
||||
form method="POST" {
|
||||
input type="text" name="name" value="anon" placeholder="Name";
|
||||
br;
|
||||
textarea rows="5" cols="60" name="text" placeholder="Enter comment..." {}
|
||||
br;
|
||||
input type="submit" value="Send!";
|
||||
}
|
||||
form method="POST" {
|
||||
input type="submit" value="💖️" name="up";
|
||||
input type="submit" value="💔️" name="down";
|
||||
}
|
||||
};
|
||||
let _ = stream.write_all(html.into_string().as_bytes());
|
||||
|
||||
for Comment { name, text } in comments {
|
||||
let html = html! {
|
||||
fieldset {
|
||||
legend { (name) }
|
||||
(maud::PreEscaped(text))
|
||||
}
|
||||
};
|
||||
let _ = stream.write_all(html.into_string().as_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = write!(stream, "</div>");
|
||||
}
|
||||
|
||||
let _ = write!(stream, "</div>");
|
||||
|
||||
section(&mut stream);
|
||||
|
||||
if let Some(pki_path) = file_paths.pki {
|
||||
let Ok(pki_file) = File::open(pki_path) else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let _ = writeln!(stream, "<h1>Description</h1>");
|
||||
|
||||
if let Some(audio_path) = &file_paths.audio {
|
||||
if Path::is_file(audio_path) {
|
||||
let _ = writeln!(
|
||||
stream,
|
||||
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let lines = BufReader::new(pki_file).lines();
|
||||
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
|
||||
|
||||
section(&mut stream);
|
||||
}
|
||||
|
||||
let html = html! {
|
||||
h1 { "Comments" }
|
||||
form method="POST" {
|
||||
input type="text" name="name" value="anon" placeholder="Name";
|
||||
br;
|
||||
textarea rows="5" cols="60" name="text" placeholder="Enter comment..." {}
|
||||
br;
|
||||
input type="submit" value="Send!";
|
||||
}
|
||||
form method="POST" {
|
||||
input type="submit" value="💖️" name="up";
|
||||
input type="submit" value="💔️" name="down";
|
||||
}
|
||||
};
|
||||
let _ = stream.write_all(html.into_string().as_bytes());
|
||||
|
||||
for Comment { name, text } in comments {
|
||||
let html = html! {
|
||||
fieldset {
|
||||
legend { (name) }
|
||||
(maud::PreEscaped(text))
|
||||
}
|
||||
};
|
||||
let _ = stream.write_all(html.into_string().as_bytes());
|
||||
}
|
||||
|
||||
section(&mut stream);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user