draft branches, some minor cleanups

This commit is contained in:
りき萌 2024-02-20 22:36:47 +01:00
parent 3a8799f581
commit 90de54c359
7 changed files with 66 additions and 12 deletions

View file

@ -7,7 +7,10 @@ use crate::{
config::Config,
html::EscapeAttribute,
state::{FileId, Treehouse},
tree::{attributes::Content, mini_template, SemaBranchId},
tree::{
attributes::{Content, Stage},
mini_template, SemaBranchId,
},
};
use super::{markdown, EscapeHtml};
@ -22,6 +25,10 @@ pub fn branch_to_html(
let source = treehouse.source(file_id);
let branch = treehouse.tree.branch(branch_id);
if !cfg!(debug_assertions) && branch.attributes.stage == Stage::Draft {
return;
}
let has_children =
!branch.children.is_empty() || matches!(branch.attributes.content, Content::Link(_));
@ -32,6 +39,10 @@ pub fn branch_to_html(
class.push_str(&branch.attributes.classes.branch);
}
if branch.attributes.stage == Stage::Draft {
class.push_str(" draft");
}
let component = if let Content::Link(_) = branch.attributes.content {
"th-b-linked"
} else {

View file

@ -64,6 +64,11 @@ pub struct Attributes {
/// Enable `mini_template` templating in this branch.
#[serde(default)]
pub template: bool,
/// Publishing stage; if `Draft`, the branch is invisible unless treehouse is compiled in
/// debug mode.
#[serde(default)]
pub stage: Stage,
}
/// Controls for block content presentation.
@ -100,3 +105,14 @@ pub struct Classes {
#[serde(default)]
pub branch_children: String,
}
/// Publish stage of a branch.
///
/// Draft branches are not included in release builds of treehouse. In debug builds, they are also
/// marked with an extra "draft" before the content.
#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize)]
pub enum Stage {
#[default]
Public,
Draft,
}