diff options
-rw-r--r-- | src/atom.rs | 4 | ||||
-rw-r--r-- | src/blog.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/poetry.rs | 45 | ||||
-rw-r--r-- | src/posts.rs | 4 | ||||
-rw-r--r-- | templates/blogpost-panel.html | 5 |
6 files changed, 52 insertions, 11 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, { diff --git a/templates/blogpost-panel.html b/templates/blogpost-panel.html index 6375012..45117b6 100644 --- a/templates/blogpost-panel.html +++ b/templates/blogpost-panel.html @@ -1,8 +1,9 @@ <div class="panel content blogpost"> <h1 class="title">{{ blogpost.subject().unwrap_or("untitled") }}</h1> <h2 class="created-at">{{ blogpost.published_at() }} <a href="/blog/{{ blogpost.file_name() }}">permalink</a></h2> - <div class="tags">{% for tag in blogpost.tags().clone() %}<a - class="tag {% if filter_tags.contains(tag) %}active{% endif %}" href="/blog?filter={{ tag }}">{{ tag }}</a>{% + <div class="tags">{% for tag in blogpost.tags() %}{% let tag = tag.to_string() %}<a + class="tag {% if filter_tags.contains(tag) %}active{% endif %}" href="/blog?filter={{ tag }}">{{ tag + }}</a>{% endfor %}</div> <div class="blogpost-content"> {{ blogpost.content()|safe }} |