Also put description and comments in a tab

This commit is contained in:
p11 2025-05-30 00:09:15 +02:00
parent 3bb1ceaf49
commit 84f57449f8

View File

@ -653,11 +653,17 @@ fn handle_relative_connection(
.parent() .parent()
.map(|parent| parent.with_extension("mlc")); .map(|parent| parent.with_extension("mlc"));
enum SectionInfo {
Description,
Comment(Vec<Comment>),
}
#[derive(Default)] #[derive(Default)]
struct Section { struct Section {
title: Box<str>, title: Box<str>,
lines: Vec<String>, lines: Vec<String>,
config_map: Option<IndexMap<Box<str>, Box<str>>>, config_map: Option<IndexMap<Box<str>, Box<str>>>,
info: Option<SectionInfo>,
} }
let mut sections = Vec::new(); let mut sections = Vec::new();
@ -667,6 +673,7 @@ fn handle_relative_connection(
title: "Game".into(), title: "Game".into(),
lines: Vec::new(), lines: Vec::new(),
config_map, config_map,
info: None,
}); });
} else { } else {
let Ok(pk_file) = File::open(file_paths.pk) else { let Ok(pk_file) = File::open(file_paths.pk) else {
@ -687,6 +694,7 @@ fn handle_relative_connection(
title: title.into(), title: title.into(),
lines: vec![line], lines: vec![line],
config_map: None, config_map: None,
info: None,
}; };
continue; continue;
@ -698,6 +706,22 @@ fn handle_relative_connection(
sections.push(current_section); 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 count = sections.len();
let _ = write!(stream, "<style>"); let _ = write!(stream, "<style>");
@ -781,7 +805,10 @@ fn handle_relative_connection(
for ( for (
i, i,
Section { Section {
lines, config_map, .. lines,
config_map,
info,
..
}, },
) in sections.into_iter().enumerate() ) in sections.into_iter().enumerate()
{ {
@ -814,15 +841,10 @@ fn handle_relative_connection(
return; return;
} }
} }
let _ = write!(stream, "</div>"); if let Some(info) = info {
} match info {
SectionInfo::Description => {
let _ = write!(stream, "</div>"); let Ok(pki_file) = File::open(file_paths.pki.unwrap()) else {
section(&mut stream);
if let Some(pki_path) = file_paths.pki {
let Ok(pki_file) = File::open(pki_path) else {
unreachable!(); unreachable!();
}; };
@ -839,10 +861,8 @@ fn handle_relative_connection(
let lines = BufReader::new(pki_file).lines(); let lines = BufReader::new(pki_file).lines();
convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1); convert_subheader(lines.map(Result::unwrap_or_default), &mut stream, 1);
section(&mut stream);
} }
SectionInfo::Comment(comments) => {
let html = html! { let html = html! {
h1 { "Comments" } h1 { "Comments" }
form method="POST" { form method="POST" {
@ -868,6 +888,13 @@ fn handle_relative_connection(
}; };
let _ = stream.write_all(html.into_string().as_bytes()); let _ = stream.write_all(html.into_string().as_bytes());
} }
}
}
}
let _ = write!(stream, "</div>");
}
let _ = write!(stream, "</div>");
section(&mut stream); section(&mut stream);
} }