diff --git a/src/app.rs b/src/app.rs index f96eea3..d267cbb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -95,6 +95,13 @@ impl AppState { } }); env.add_filter("to_lowercase", |value: &str| value.to_lowercase()); + env.add_filter("concat_url", |value: &str, uri: &str| { + if value.ends_with("/") { + format!("{}{}", value, uri) + } else { + format!("{}/{}", value, uri) + } + }); Ok(Self { config, env, db }) } diff --git a/src/models/articles.rs b/src/models/articles.rs index 6523d7a..f950547 100644 --- a/src/models/articles.rs +++ b/src/models/articles.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use serde::Serialize; use sqlx::prelude::FromRow; use tracing::info; @@ -9,8 +9,8 @@ pub struct Article { title: String, pub content: String, pub tags: String, - pub created_at: NaiveDateTime, - updated_at: NaiveDateTime, + pub created_at: DateTime, + updated_at: DateTime, } impl Article { @@ -59,7 +59,7 @@ impl Article { .unwrap() } - pub async fn get_latest_updated(db: &sqlx::MySqlPool) -> Option { + pub async fn get_latest_updated(db: &sqlx::MySqlPool) -> Option> { sqlx::query_scalar("SELECT MAX(updated_at) FROM articles") .fetch_one(db) .await diff --git a/src/models/pages.rs b/src/models/pages.rs index d089912..30b5ff9 100644 --- a/src/models/pages.rs +++ b/src/models/pages.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use serde::Serialize; use sqlx::prelude::FromRow; @@ -7,8 +7,8 @@ pub struct Page { id: i32, pub title: String, pub content: String, - pub created_at: NaiveDateTime, - pub updated_at: NaiveDateTime, + pub created_at: DateTime, + pub updated_at: DateTime, } impl Page { diff --git a/templates/feed.xml b/templates/feed.xml index 0c3e1b3..78f4f35 100755 --- a/templates/feed.xml +++ b/templates/feed.xml @@ -1,23 +1,24 @@ {{ config.blog_name }} - + {% if updated_at %} - {{ updated_at }} + {{ updated_at }} {% endif %} - {{ config.blog_url }} + + {{ config.blog_url | concat_url('') }} {% for article in articles %} - <![CDATA[{{ article.title }}]]> + {{ article.title }} {{ config.blog_author }} {{ config.blog_url }} - + {{ article.created_at }} - {{ article.updated_at }} - {{ config.blog_url }}/article/{{ article.id }} + {{ article.updated_at }} + {{ config.blog_url | concat_url('article') }}/{{ article.id }}