From 97053b87077ba99d24852898dc120caeeb6f4876 Mon Sep 17 00:00:00 2001
From: Stephen <webmaster@scd31.com>
Date: Sat, 11 Mar 2023 09:39:38 -0400
Subject: [PATCH] hidden posts

---
 src/blog.rs | 4 +++-
 src/post.rs | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/blog.rs b/src/blog.rs
index fed1c0e..38667c6 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 9c8d9c2..1b3faec 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,
-- 
GitLab