summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2026-05-11 23:52:49 +0200
committerWriterV2 <primary-v2@protonmail.com>2026-05-11 23:52:49 +0200
commit5760f597eb17eab5abe6a3ae6c905ad9e111dc46 (patch)
tree853c9062cbc911f9ebe287eba3210ecde5721949 /src
parent79618992153be5348f02ad91c8b91bd883c0b295 (diff)
Refactor page and story
Diffstat (limited to 'src')
-rw-r--r--src/data.rs98
-rw-r--r--src/main.rs284
-rw-r--r--src/story.rs187
3 files changed, 289 insertions, 280 deletions
diff --git a/src/data.rs b/src/data.rs
new file mode 100644
index 0000000..2e5b3d1
--- /dev/null
+++ b/src/data.rs
@@ -0,0 +1,98 @@
+use crate::page;
+use crate::story;
+use maud::{html, Markup};
+use serde::Deserialize;
+
+#[derive(Deserialize)]
+pub struct Data {
+ pub stories: Vec<story::Story>,
+}
+
+impl page::Page for Data {
+ fn page_title() -> String {
+ String::from("Home")
+ }
+
+ fn alternative_htmlfilename() -> Option<String> {
+ Some(String::from("index"))
+ }
+
+ fn render_content(&self) -> Markup {
+ let last_story = self.stories.first();
+ html!(
+ @if let Some(story) = last_story {
+ div class="latest-story" lang=(story.html_lang_value()) {
+ h2 lang="en" { "Latest Story" }
+ h3 {
+ (story.name)
+ }
+ @if let Some(content_warnings) = story.render_content_warnings() {
+ (content_warnings)
+ }
+
+ p { (story.description) }
+ ul lang="en" {
+ li { "Language: " (story.language) }
+ li {
+ a href=(&story.format_pdf_path()) download
+ {
+ "PDF"
+ }
+ }
+ }
+
+ }
+ }
+ )
+ }
+
+ fn content_style() -> Markup {
+ html!(
+ """
+h2 {
+ font-size: 2.5rem;
+ color: #2F3C57;
+ text-decoration: 0.1rem solid underline black;
+}
+
+h3 {
+ font-size: 1.8rem;
+ color: #2F3C57;
+ padding: 2rem 0;
+}
+
+.latest-story {
+ padding: 3rem;
+ margin: 3rem;
+ text-align: left;
+ background-color: #FFD1A3;
+ hyphens: auto;
+ * {
+ margin: 1rem 0;
+ }
+
+ p {
+ font-size: 1.2rem;
+ }
+}
+
+a {
+ text-decoration: underline;
+ color: #3D1D49;
+}
+
+ul {
+ list-style: none;
+}
+
+.content-warning {
+ background-color: #EC7981;
+ margin: 2rem 0;
+ padding: 0.3rem;
+ width: fit-content;
+}
+
+ """
+ )
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 006ed58..493529e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,287 +1,11 @@
use anyhow::{Context, Result};
-use maud::{html, Markup};
-use serde::Deserialize;
-use toml::value::Date;
-use self::page::Page;
+use data::Data;
+use page::Page;
+mod data;
mod page;
-
-#[derive(Deserialize)]
-struct Data {
- stories: Vec<Story>,
-}
-
-impl page::Page for Data {
- fn page_title() -> String {
- String::from("Home")
- }
-
- fn alternative_htmlfilename() -> Option<String> {
- Some(String::from("index"))
- }
-
- fn render_content(&self) -> Markup {
- let last_story = self.stories.first();
- html!(
- @if let Some(story) = last_story {
- div class="latest-story" lang=(story.html_lang_value()) {
- h2 lang="en" { "Latest Story" }
- h3 {
- (story.name)
- }
- @if let Some(content_warnings) = story.render_content_warnings() {
- (content_warnings)
- }
-
- p { (story.description) }
- ul lang="en" {
- li { "Language: " (story.language) }
- li {
- a href=(&story.format_pdf_path()) download
- {
- "PDF"
- }
- }
- }
-
- }
- }
- )
- }
-
- fn content_style() -> Markup {
- html!(
- """
-h2 {
- font-size: 2.5rem;
- color: #2F3C57;
- text-decoration: 0.1rem solid underline black;
-}
-
-h3 {
- font-size: 1.8rem;
- color: #2F3C57;
- padding: 2rem 0;
-}
-
-.latest-story {
- padding: 3rem;
- margin: 3rem;
- text-align: left;
- background-color: #FFD1A3;
- hyphens: auto;
- * {
- margin: 1rem 0;
- }
-
- p {
- font-size: 1.2rem;
- }
-}
-
-a {
- text-decoration: underline;
- color: #3D1D49;
-}
-
-ul {
- list-style: none;
-}
-
-.content-warning {
- background-color: #EC7981;
- margin: 2rem 0;
- padding: 0.3rem;
- width: fit-content;
-}
-
- """
- )
- }
-}
-
-impl page::Page for Vec<Story> {
- fn page_title() -> String {
- String::from("Stories")
- }
-
- fn render_content(&self) -> Markup {
- html!(
- @for story in self {
- (story.render_as_card())
- }
- )
- }
-
- fn prepare_content(&mut self) -> Result<()> {
- self.sort_by(|a, b| {
- let date1 = a.update_date.unwrap_or(a.upload_date);
- let date2 = b.update_date.unwrap_or(b.upload_date);
- date2.cmp(&date1)
- });
- for story in self {
- std::fs::copy(&story.path, story.format_local_pdf_path())?;
- }
- Ok(())
- }
-
- fn content_style() -> Markup {
- html!(
- """
-h2 {
- font-size: 1.8rem;
- margin-bottom: 2rem;
- color: #2F3C57;
-}
-
-hr {
- margin: 1rem;
-}
-
-
-.story-card {
- text-align: left;
- font-size: 1.2rem;
- hyphens: auto;
- ul {
- display: flex;
- justify-content: start;
- list-style: none;
- flex-wrap: wrap;
-
- li {
- font-size: 1rem;
- padding: 0.8rem;
- margin: 0.8rem;
- background-color: #2F3C57;
- color: #ffd1a3;
- outline: 0.2rem solid #2F3C57;
-
- a {
- text-decoration: underline #E1CCEB;
- color: #E1CCEB;
- }
- }
- }
-
- 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;
- }
-}
- """
- )
- }
-}
-
-#[derive(Deserialize, Debug)]
-enum StoryLanguage {
- German,
- English,
-}
-
-impl std::fmt::Display for StoryLanguage {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{:?}", self)
- }
-}
-
-#[derive(Deserialize)]
-struct Story {
- name: String,
- description: String,
- language: StoryLanguage,
- upload_date: Date,
- update_date: Option<Date>,
- path: String,
- warnings: Option<Vec<String>>,
-}
-
-impl Story {
- fn render_as_card(&self) -> Markup {
- 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" {
- li { "Language: " (self.language) }
- li { "Uploaded on: " (self.upload_date) }
- @if let Some(update_date) = self.update_date {
- li { "Updated on: " (update_date) }
- }
- li {
- a href=(&self.format_pdf_path()) download
- {
- "PDF"
- }
- }
- }
- }
- })
- }
-
- fn format_pdf_path(&self) -> String {
- let snake_case_name = self.name.to_lowercase().replace(" ", "_");
- format!("stories/{}.pdf", snake_case_name)
- }
-
- fn format_local_pdf_path(&self) -> String {
- format!("dist/{}", self.format_pdf_path())
- }
-
- fn html_lang_value(&self) -> String {
- match self.language {
- StoryLanguage::German => String::from("de"),
- StoryLanguage::English => String::from("en"),
- }
- }
-
- fn render_content_warnings(&self) -> Option<Markup> {
- 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
- }
- }
-}
+mod story;
fn main() -> Result<()> {
let data_file_content =
diff --git a/src/story.rs b/src/story.rs
new file mode 100644
index 0000000..c5371ee
--- /dev/null
+++ b/src/story.rs
@@ -0,0 +1,187 @@
+use crate::page;
+use anyhow::Result;
+use maud::{html, Markup};
+use serde::Deserialize;
+use toml::value::Date;
+
+impl page::Page for Vec<Story> {
+ fn page_title() -> String {
+ String::from("Stories")
+ }
+
+ fn render_content(&self) -> Markup {
+ html!(
+ @for story in self {
+ (story.render_as_card())
+ }
+ )
+ }
+
+ fn prepare_content(&mut self) -> Result<()> {
+ self.sort_by(|a, b| {
+ let date1 = a.update_date.unwrap_or(a.upload_date);
+ let date2 = b.update_date.unwrap_or(b.upload_date);
+ date2.cmp(&date1)
+ });
+ for story in self {
+ std::fs::copy(&story.path, story.format_local_pdf_path())?;
+ }
+ Ok(())
+ }
+
+ fn content_style() -> Markup {
+ html!(
+ """
+h2 {
+ font-size: 1.8rem;
+ margin-bottom: 2rem;
+ color: #2F3C57;
+}
+
+hr {
+ margin: 1rem;
+}
+
+
+.story-card {
+ text-align: left;
+ font-size: 1.2rem;
+ hyphens: auto;
+ ul {
+ display: flex;
+ justify-content: start;
+ list-style: none;
+ flex-wrap: wrap;
+
+ li {
+ font-size: 1rem;
+ padding: 0.8rem;
+ margin: 0.8rem;
+ background-color: #2F3C57;
+ color: #ffd1a3;
+ outline: 0.2rem solid #2F3C57;
+
+ a {
+ text-decoration: underline #E1CCEB;
+ color: #E1CCEB;
+ }
+ }
+ }
+
+ 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;
+ }
+}
+ """
+ )
+ }
+}
+
+#[derive(Deserialize, Debug)]
+pub enum StoryLanguage {
+ German,
+ English,
+}
+
+impl std::fmt::Display for StoryLanguage {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{:?}", self)
+ }
+}
+
+#[derive(Deserialize)]
+pub struct Story {
+ pub name: String,
+ pub description: String,
+ pub language: StoryLanguage,
+ pub upload_date: Date,
+ pub update_date: Option<Date>,
+ pub path: String,
+ pub warnings: Option<Vec<String>>,
+}
+
+impl Story {
+ fn render_as_card(&self) -> Markup {
+ 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" {
+ li { "Language: " (self.language) }
+ li { "Uploaded on: " (self.upload_date) }
+ @if let Some(update_date) = self.update_date {
+ li { "Updated on: " (update_date) }
+ }
+ li {
+ a href=(&self.format_pdf_path()) download
+ {
+ "PDF"
+ }
+ }
+ }
+ }
+ })
+ }
+
+ pub fn format_pdf_path(&self) -> String {
+ let snake_case_name = self.name.to_lowercase().replace(" ", "_");
+ format!("stories/{}.pdf", snake_case_name)
+ }
+
+ fn format_local_pdf_path(&self) -> String {
+ format!("dist/{}", self.format_pdf_path())
+ }
+
+ pub fn html_lang_value(&self) -> String {
+ match self.language {
+ StoryLanguage::German => String::from("de"),
+ StoryLanguage::English => String::from("en"),
+ }
+ }
+
+ pub fn render_content_warnings(&self) -> Option<Markup> {
+ 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
+ }
+ }
+}