Refactor: Put comments into site info
This commit is contained in:
parent
21d203431b
commit
7b2961afad
22
src/main.rs
22
src/main.rs
@ -43,9 +43,21 @@ struct Comment {
|
||||
text: Box<str>,
|
||||
}
|
||||
|
||||
struct SiteInfo {
|
||||
comments: Vec<Comment>,
|
||||
}
|
||||
|
||||
impl SiteInfo {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
comments: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Context {
|
||||
comments: HashMap<Box<str>, Vec<Comment>>,
|
||||
infos: HashMap<Box<str>, SiteInfo>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
@ -126,9 +138,9 @@ impl Context {
|
||||
};
|
||||
|
||||
use Entry::*;
|
||||
let local_comments = match self.comments.entry(relative_path.clone().into_boxed_str()) {
|
||||
let info = match self.infos.entry(relative_path.clone().into_boxed_str()) {
|
||||
Occupied(o) => o.into_mut(),
|
||||
Vacant(v) => v.insert(Vec::new()),
|
||||
Vacant(v) => v.insert(SiteInfo::new()),
|
||||
};
|
||||
|
||||
let mut entries = request.body.split('&');
|
||||
@ -159,7 +171,7 @@ impl Context {
|
||||
.unwrap_or_default()
|
||||
.into();
|
||||
|
||||
local_comments.push(Comment { name, text });
|
||||
info.comments.push(Comment { name, text });
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +264,7 @@ impl Context {
|
||||
};
|
||||
let _ = stream.write_all(html.into_string().as_bytes());
|
||||
|
||||
for Comment { name, text } in local_comments {
|
||||
for Comment { name, text } in &info.comments {
|
||||
let _ = writeln!(stream, "<fieldset><legend>{name}</legend>{text}</fieldset>");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user