From 79618992153be5348f02ad91c8b91bd883c0b295 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Mon, 11 May 2026 21:16:18 +0200 Subject: Add content warnings to stories --- src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5879f83..006ed58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,10 @@ impl page::Page for Data { h3 { (story.name) } + @if let Some(content_warnings) = story.render_content_warnings() { + (content_warnings) + } + p { (story.description) } ul lang="en" { li { "Language: " (story.language) } @@ -85,6 +89,13 @@ ul { list-style: none; } +.content-warning { + background-color: #EC7981; + margin: 2rem 0; + padding: 0.3rem; + width: fit-content; +} + """ ) } @@ -157,10 +168,22 @@ hr { hr { margin: 2rem 0; } + + p { + margin-top: 1rem; + } + padding: 3rem; margin: 3rem; background-color: #ffd1a3; border-bottom: 0.1rem dotted black; + + .content-warning { + background-color: #EC7981; + margin: 2rem 0; + padding: 0.3rem; + width: fit-content; + } } """ ) @@ -187,6 +210,7 @@ struct Story { upload_date: Date, update_date: Option, path: String, + warnings: Option>, } impl Story { @@ -194,6 +218,9 @@ impl Story { html!(div class="story-card" lang=(self.html_lang_value()) { card { h2 { (self.name) } + @if let Some(content_warnings) = &self.render_content_warnings() { + (content_warnings) + } p { (self.description) } hr {} ul lang="en" { @@ -228,6 +255,32 @@ impl Story { StoryLanguage::English => String::from("en"), } } + + fn render_content_warnings(&self) -> Option { + if let Some(warnings) = &self.warnings { + let (summary, prefix) = match self.language { + StoryLanguage::German => ( + String::from("Vorsicht ist geboten."), + String::from("Die Geschichte beinhaltet: "), + ), + StoryLanguage::English => ( + String::from("Reader discretion is advised."), + String::from("The story contains: "), + ), + }; + let details = format!("{}{}", prefix, warnings.join(", ")); + Some(html!( + details { + summary { + strong { (summary) } + } + p class="content-warning" { (details) } + } + )) + } else { + None + } + } } fn main() -> Result<()> { -- cgit v1.2.3