Section info not optional anymore

This commit is contained in:
p11 2025-05-30 00:22:58 +02:00
parent ce23dcf455
commit 81134d2007

View File

@ -651,10 +651,9 @@ fn handle_relative_connection(
Comment(Vec<Comment>),
}
#[derive(Default)]
struct Section {
title: Box<str>,
info: Option<SectionInfo>,
info: SectionInfo,
}
let mut sections = Vec::new();
@ -671,7 +670,7 @@ fn handle_relative_connection(
if let Some(config_map) = config_map {
sections.push(Section {
title: "Game".into(),
info: Some(SectionInfo::Game(config_map)),
info: SectionInfo::Game(config_map),
});
} else {
let Ok(pk_file) = File::open(file_paths.pk) else {
@ -689,7 +688,7 @@ fn handle_relative_connection(
if !current_title.is_empty() {
sections.push(Section {
title: current_title,
info: Some(SectionInfo::Lines(current_lines)),
info: SectionInfo::Lines(current_lines),
})
}
current_title = title.into();
@ -703,20 +702,20 @@ fn handle_relative_connection(
sections.push(Section {
title: current_title,
info: Some(SectionInfo::Lines(current_lines)),
info: SectionInfo::Lines(current_lines),
})
}
if file_paths.pki.is_some() {
sections.push(Section {
title: "Description".into(),
info: Some(SectionInfo::Description),
info: SectionInfo::Description,
});
}
sections.push(Section {
title: "Comments".into(),
info: Some(SectionInfo::Comment(comments)),
info: SectionInfo::Comment(comments),
});
let count = sections.len();
@ -802,80 +801,78 @@ fn handle_relative_connection(
for (i, Section { info, .. }) in sections.into_iter().enumerate() {
let index = i + 1;
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
if let Some(info) = info {
match info {
SectionInfo::Lines(lines) => {
convert_extended(
lines,
&mut stream,
Settings::default()
.with_handler(entry_handler(path, relative_path, censored))
.with_start_level(start_level)
.with_use_textboxes(true),
);
match info {
SectionInfo::Lines(lines) => {
convert_extended(
lines,
&mut stream,
Settings::default()
.with_handler(entry_handler(path, relative_path, censored))
.with_start_level(start_level)
.with_use_textboxes(true),
);
}
SectionInfo::Game(config_map) => {
if render_novel(
config_map,
file_paths.pk,
mlc_path.as_deref(),
file_paths.mld,
relative_path,
&mut stream,
choice,
progress,
)
.is_err()
{
fail(stream);
return;
}
SectionInfo::Game(config_map) => {
if render_novel(
config_map,
file_paths.pk,
mlc_path.as_deref(),
file_paths.mld,
relative_path,
&mut stream,
choice,
progress,
)
.is_err()
{
fail(stream);
return;
}
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>"
);
}
}
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());
let lines = BufReader::new(pki_file).lines();
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
}
SectionInfo::Comment(comments) => {
for Comment { name, text } in 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";
fieldset {
legend { (name) }
(maud::PreEscaped(text))
}
};
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());
}
}
}
}