diff --git a/src/blog.rs b/src/blog.rs index fed1c0e7ac4e3c1eca3b227e3a2e4896b4c5abcd..38667c6c7b3de39172c5f0263d309ff398a2011a 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -51,7 +51,9 @@ impl Blog { ); for post in &self.posts { - content.push_str(&post.link()?); + if !post.hidden { + content.push_str(&post.link()?); + } } content.push_str("</table>"); diff --git a/src/post.rs b/src/post.rs index 9c8d9c259e1f2b77e3f62aff3d8e34534815fa92..1b3faece8f2dc3c8d210fa88244eb69623ec4c50 100644 --- a/src/post.rs +++ b/src/post.rs @@ -14,6 +14,7 @@ use crate::{ #[derive(Eq)] pub struct Post { + pub hidden: bool, pub title: String, pub date: Option<NaiveDate>, pub index: u32, @@ -139,6 +140,7 @@ impl PartialEq for Post { } struct PostParser { + hidden: bool, title: Option<String>, date: Option<NaiveDate>, index: Option<u32>, @@ -150,6 +152,7 @@ struct PostParser { impl PostParser { fn new(base_path: &Path, url: String) -> anyhow::Result<Self> { Ok(Self { + hidden: false, title: None, date: None, index: None, @@ -163,6 +166,10 @@ impl PostParser { impl Parser<Post> for PostParser { fn start(&mut self, e: &Element) -> anyhow::Result<()> { match e { + Element::Keyword(Keyword { key, .. }) if key == "HIDDEN" => { + self.hidden = true; + } + Element::Keyword(Keyword { key, value, .. }) if key == "TITLE" => { if self.title.is_some() { bail!("Post has more than one title"); @@ -202,6 +209,7 @@ impl Parser<Post> for PostParser { } fn render(self) -> anyhow::Result<Post> { + let hidden = self.hidden; let title = self.title.context("Could not find post title")?; let date = self.date; let index = self.index.unwrap_or(u32::MAX); @@ -209,6 +217,7 @@ impl Parser<Post> for PostParser { let url = self.url; Ok(Post { + hidden, title, date, index,