aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-01-31 18:55:36 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-01-31 18:55:36 +0000
commitd1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0 (patch)
treec54999785bf7ae865ca571a475da222e9e376873 /src
parentb78d026c242e8d95e611e050afd5b72eb562d56d (diff)
downloadblossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.tar.gz
blossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.tar.bz2
blossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.zip
changed Post tags() to return a Vec<&str>
Diffstat (limited to 'src')
-rw-r--r--src/atom.rs4
-rw-r--r--src/blog.rs4
-rw-r--r--src/main.rs1
-rw-r--r--src/poetry.rs45
-rw-r--r--src/posts.rs4
5 files changed, 49 insertions, 9 deletions
diff --git a/src/atom.rs b/src/atom.rs
index a64a6aa..bda4c51 100644
--- a/src/atom.rs
+++ b/src/atom.rs
@@ -107,9 +107,9 @@ pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
.tags()
.into_iter()
.map(|category| Category {
- term: category.clone(),
+ term: category.to_string(),
scheme: None,
- label: Some(category.clone()),
+ label: Some(category.to_string()),
})
.collect();
let published = Some(entry.published_at().to_owned().into());
diff --git a/src/blog.rs b/src/blog.rs
index 0e757d5..b6ca75c 100644
--- a/src/blog.rs
+++ b/src/blog.rs
@@ -76,8 +76,8 @@ impl Post for Blogpost {
self.updated_at.as_ref()
}
- fn tags(&self) -> &Vec<String> {
- &self.tags
+ fn tags(&self) -> Vec<&str> {
+ self.tags.iter().map(|s| &**s).collect()
}
fn lang(&self) -> &str {
diff --git a/src/main.rs b/src/main.rs
index 3d52f46..4f8ec55 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -33,6 +33,7 @@ use tracing_subscriber::FmtSubscriber;
use crate::article::Article;
use crate::blog::Blogpost;
+use crate::posts::Post;
type Result<T> = std::result::Result<T, BlossomError>;
diff --git a/src/poetry.rs b/src/poetry.rs
index f5f194c..6429bd3 100644
--- a/src/poetry.rs
+++ b/src/poetry.rs
@@ -1,6 +1,10 @@
use chrono::{DateTime, Utc};
+use serde::Deserialize;
-use crate::posts::Post;
+use crate::Result;
+use crate::{article::Article, posts::Post};
+
+static DIRECTORY: &str = "./poetry";
pub struct Poem {
file_name: String,
@@ -13,6 +17,41 @@ pub struct Poem {
lang: String,
}
+#[derive(Deserialize)]
+pub struct PoemMetadata {
+ title: Option<String>,
+ created_at: String,
+ published_at: String,
+ updated_at: Option<String>,
+}
+
+impl Article for Poem {
+ type Article = Poem;
+
+ type Metadata = PoemMetadata;
+
+ fn directory() -> &'static str {
+ DIRECTORY
+ }
+
+ fn new(file_name: String, metadata: Self::Metadata, content: String) -> Result<Self::Article> {
+ let updated_at = if let Some(updated_at) = metadata.updated_at {
+ Some(updated_at.parse::<DateTime<Utc>>()?)
+ } else {
+ None
+ };
+ Ok(Poem {
+ file_name,
+ title: metadata.title,
+ created_at: metadata.created_at.parse::<DateTime<Utc>>()?,
+ published_at: metadata.published_at.parse::<DateTime<Utc>>()?,
+ updated_at,
+ content,
+ lang: "en".to_string(),
+ })
+ }
+}
+
impl Post for Poem {
fn id(&self) -> &str {
&self.file_name
@@ -30,8 +69,8 @@ impl Post for Poem {
self.updated_at.as_ref()
}
- fn tags(&self) -> &Vec<String> {
- todo!()
+ fn tags(&self) -> Vec<&str> {
+ vec!["poetry"]
}
fn lang(&self) -> &str {
diff --git a/src/posts.rs b/src/posts.rs
index a8e9f90..93c9179 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -14,7 +14,7 @@ pub trait Post {
fn subject(&self) -> Option<&str>;
fn published_at(&self) -> &DateTime<Utc>;
fn updated_at(&self) -> Option<&DateTime<Utc>>;
- fn tags(&self) -> &Vec<String>;
+ fn tags(&self) -> Vec<&str>;
fn lang(&self) -> &str;
fn post_type(&self) -> PostType;
fn content(&self) -> &str;
@@ -23,7 +23,7 @@ pub trait Post {
"https://en.blos.sm/posts/".to_owned() + self.id()
}
- fn get_tags<'a>(posts: &'a Vec<Self>) -> Vec<&'a String>
+ fn get_tags<'a>(posts: &'a Vec<Self>) -> Vec<&'a str>
where
Self: Sized,
{