Skip to content

Commit

Permalink
Update the feed to use the latest RSS specification
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Aug 23, 2024
1 parent 3f15d88 commit 28643d1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
8 changes: 4 additions & 4 deletions src/models/articles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use serde::Serialize;
use sqlx::prelude::FromRow;
use tracing::info;
Expand All @@ -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<Utc>,
updated_at: DateTime<Utc>,
}

impl Article {
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Article {
.unwrap()
}

pub async fn get_latest_updated(db: &sqlx::MySqlPool) -> Option<NaiveDateTime> {
pub async fn get_latest_updated(db: &sqlx::MySqlPool) -> Option<DateTime<Utc>> {
sqlx::query_scalar("SELECT MAX(updated_at) FROM articles")
.fetch_one(db)
.await
Expand Down
6 changes: 3 additions & 3 deletions src/models/pages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use serde::Serialize;
use sqlx::prelude::FromRow;

Expand All @@ -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<Utc>,
pub updated_at: DateTime<Utc>,
}

impl Page {
Expand Down
12 changes: 6 additions & 6 deletions templates/feed.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ config.blog_name }}</title>
<link href="/feed" rel="self" />
<link href="{{ config.blog_url }}" />
<link href="{{ config.blog_url | concat_url('feed') }}" rel="self" type="application/rss+xml"/>
{% if updated_at %}
<updated_at>{{ updated_at }}</updated_at>
<updated>{{ updated_at }}</updated>
{% endif %}
<id>{{ config.blog_url }}</id>
{% for article in articles %}
<entry>
<title><![CDATA[{{ article.title }}]]></title>
<title>{{ article.title }}</title>
<author>
<name>{{ config.blog_author }}</name>
<uri>{{ config.blog_url }}</uri>
</author>
<link href="{{ config.blog_url }}/article/{{ article.id }}"/>
<link href="{{ config.blog_url | concat_url('article') }}/{{ article.id }}"/>
<published>{{ article.created_at }}</published>
<updated_at>{{ article.updated_at }}</updated_at>
<id>{{ config.blog_url }}/article/{{ article.id }}</id>
<updated>{{ article.updated_at }}</updated>
<id>{{ config.blog_url | concat_url('article') }}/{{ article.id }}</id>
<content type="html">
<![CDATA[{% autoescape false %}{{ article.content | md_to_html }}{% endautoescape %}]]>
</content>
Expand Down

0 comments on commit 28643d1

Please sign in to comment.