Section info not optional anymore
This commit is contained in:
parent
ce23dcf455
commit
81134d2007
139
src/main.rs
139
src/main.rs
@ -651,10 +651,9 @@ fn handle_relative_connection(
|
|||||||
Comment(Vec<Comment>),
|
Comment(Vec<Comment>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct Section {
|
struct Section {
|
||||||
title: Box<str>,
|
title: Box<str>,
|
||||||
info: Option<SectionInfo>,
|
info: SectionInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sections = Vec::new();
|
let mut sections = Vec::new();
|
||||||
@ -671,7 +670,7 @@ fn handle_relative_connection(
|
|||||||
if let Some(config_map) = config_map {
|
if let Some(config_map) = config_map {
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Game".into(),
|
title: "Game".into(),
|
||||||
info: Some(SectionInfo::Game(config_map)),
|
info: SectionInfo::Game(config_map),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let Ok(pk_file) = File::open(file_paths.pk) else {
|
let Ok(pk_file) = File::open(file_paths.pk) else {
|
||||||
@ -689,7 +688,7 @@ fn handle_relative_connection(
|
|||||||
if !current_title.is_empty() {
|
if !current_title.is_empty() {
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: current_title,
|
title: current_title,
|
||||||
info: Some(SectionInfo::Lines(current_lines)),
|
info: SectionInfo::Lines(current_lines),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
current_title = title.into();
|
current_title = title.into();
|
||||||
@ -703,20 +702,20 @@ fn handle_relative_connection(
|
|||||||
|
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: current_title,
|
title: current_title,
|
||||||
info: Some(SectionInfo::Lines(current_lines)),
|
info: SectionInfo::Lines(current_lines),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if file_paths.pki.is_some() {
|
if file_paths.pki.is_some() {
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Description".into(),
|
title: "Description".into(),
|
||||||
info: Some(SectionInfo::Description),
|
info: SectionInfo::Description,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.push(Section {
|
sections.push(Section {
|
||||||
title: "Comments".into(),
|
title: "Comments".into(),
|
||||||
info: Some(SectionInfo::Comment(comments)),
|
info: SectionInfo::Comment(comments),
|
||||||
});
|
});
|
||||||
|
|
||||||
let count = sections.len();
|
let count = sections.len();
|
||||||
@ -802,80 +801,78 @@ fn handle_relative_connection(
|
|||||||
for (i, Section { info, .. }) in sections.into_iter().enumerate() {
|
for (i, Section { info, .. }) in sections.into_iter().enumerate() {
|
||||||
let index = i + 1;
|
let index = i + 1;
|
||||||
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
|
let _ = write!(stream, r#"<div class="tab-content" id="content-{index}">"#);
|
||||||
if let Some(info) = info {
|
match info {
|
||||||
match info {
|
SectionInfo::Lines(lines) => {
|
||||||
SectionInfo::Lines(lines) => {
|
convert_extended(
|
||||||
convert_extended(
|
lines,
|
||||||
lines,
|
&mut stream,
|
||||||
&mut stream,
|
Settings::default()
|
||||||
Settings::default()
|
.with_handler(entry_handler(path, relative_path, censored))
|
||||||
.with_handler(entry_handler(path, relative_path, censored))
|
.with_start_level(start_level)
|
||||||
.with_start_level(start_level)
|
.with_use_textboxes(true),
|
||||||
.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(
|
SectionInfo::Description => {
|
||||||
config_map,
|
let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else {
|
||||||
file_paths.pk,
|
unreachable!();
|
||||||
mlc_path.as_deref(),
|
};
|
||||||
file_paths.mld,
|
|
||||||
relative_path,
|
let _ = writeln!(stream, "<h1>Description</h1>");
|
||||||
&mut stream,
|
|
||||||
choice,
|
if let Some(audio_path) = &file_paths.audio {
|
||||||
progress,
|
if Path::is_file(audio_path) {
|
||||||
)
|
let _ = writeln!(
|
||||||
.is_err()
|
stream,
|
||||||
{
|
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
|
||||||
fail(stream);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SectionInfo::Description => {
|
|
||||||
let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else {
|
|
||||||
unreachable!();
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = writeln!(stream, "<h1>Description</h1>");
|
let lines = BufReader::new(pki_file).lines();
|
||||||
|
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
|
||||||
if let Some(audio_path) = &file_paths.audio {
|
}
|
||||||
if Path::is_file(audio_path) {
|
SectionInfo::Comment(comments) => {
|
||||||
let _ = writeln!(
|
let html = html! {
|
||||||
stream,
|
h1 { "Comments" }
|
||||||
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
|
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();
|
for Comment { name, text } in comments {
|
||||||
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
|
|
||||||
}
|
|
||||||
SectionInfo::Comment(comments) => {
|
|
||||||
let html = html! {
|
let html = html! {
|
||||||
h1 { "Comments" }
|
fieldset {
|
||||||
form method="POST" {
|
legend { (name) }
|
||||||
input type="text" name="name" value="anon" placeholder="Name";
|
(maud::PreEscaped(text))
|
||||||
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 _ = 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user