Skip to content
Snippets Groups Projects
Commit 97053b87 authored by Stephen D's avatar Stephen D
Browse files

hidden posts

parent 7f97b987
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,9 @@ impl Blog { ...@@ -51,7 +51,9 @@ impl Blog {
); );
for post in &self.posts { for post in &self.posts {
content.push_str(&post.link()?); if !post.hidden {
content.push_str(&post.link()?);
}
} }
content.push_str("</table>"); content.push_str("</table>");
......
...@@ -14,6 +14,7 @@ use crate::{ ...@@ -14,6 +14,7 @@ use crate::{
#[derive(Eq)] #[derive(Eq)]
pub struct Post { pub struct Post {
pub hidden: bool,
pub title: String, pub title: String,
pub date: Option<NaiveDate>, pub date: Option<NaiveDate>,
pub index: u32, pub index: u32,
...@@ -139,6 +140,7 @@ impl PartialEq for Post { ...@@ -139,6 +140,7 @@ impl PartialEq for Post {
} }
struct PostParser { struct PostParser {
hidden: bool,
title: Option<String>, title: Option<String>,
date: Option<NaiveDate>, date: Option<NaiveDate>,
index: Option<u32>, index: Option<u32>,
...@@ -150,6 +152,7 @@ struct PostParser { ...@@ -150,6 +152,7 @@ struct PostParser {
impl PostParser { impl PostParser {
fn new(base_path: &Path, url: String) -> anyhow::Result<Self> { fn new(base_path: &Path, url: String) -> anyhow::Result<Self> {
Ok(Self { Ok(Self {
hidden: false,
title: None, title: None,
date: None, date: None,
index: None, index: None,
...@@ -163,6 +166,10 @@ impl PostParser { ...@@ -163,6 +166,10 @@ impl PostParser {
impl Parser<Post> for PostParser { impl Parser<Post> for PostParser {
fn start(&mut self, e: &Element) -> anyhow::Result<()> { fn start(&mut self, e: &Element) -> anyhow::Result<()> {
match e { match e {
Element::Keyword(Keyword { key, .. }) if key == "HIDDEN" => {
self.hidden = true;
}
Element::Keyword(Keyword { key, value, .. }) if key == "TITLE" => { Element::Keyword(Keyword { key, value, .. }) if key == "TITLE" => {
if self.title.is_some() { if self.title.is_some() {
bail!("Post has more than one title"); bail!("Post has more than one title");
...@@ -202,6 +209,7 @@ impl Parser<Post> for PostParser { ...@@ -202,6 +209,7 @@ impl Parser<Post> for PostParser {
} }
fn render(self) -> anyhow::Result<Post> { fn render(self) -> anyhow::Result<Post> {
let hidden = self.hidden;
let title = self.title.context("Could not find post title")?; let title = self.title.context("Could not find post title")?;
let date = self.date; let date = self.date;
let index = self.index.unwrap_or(u32::MAX); let index = self.index.unwrap_or(u32::MAX);
...@@ -209,6 +217,7 @@ impl Parser<Post> for PostParser { ...@@ -209,6 +217,7 @@ impl Parser<Post> for PostParser {
let url = self.url; let url = self.url;
Ok(Post { Ok(Post {
hidden,
title, title,
date, date,
index, index,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment