parent
0ce8ddd96e
commit
78dde7bba3
@ -0,0 +1,30 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="CssUnknownProperty" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myCustomPropertiesEnabled" value="false" />
|
||||
<option name="myIgnoreVendorSpecificProperties" value="true" />
|
||||
<option name="myCustomPropertiesList">
|
||||
<value>
|
||||
<list size="0" />
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myValues">
|
||||
<value>
|
||||
<list size="7">
|
||||
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
||||
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
||||
<item index="2" class="java.lang.String" itemvalue="comment" />
|
||||
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
||||
<item index="4" class="java.lang.String" itemvalue="embed" />
|
||||
<item index="5" class="java.lang.String" itemvalue="script" />
|
||||
<item index="6" class="java.lang.String" itemvalue="rss-button" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myCustomValuesEnabled" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,33 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use crate::m20230205_022300_create_settings::Settings;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Settings::Table)
|
||||
.add_column(ColumnDef::new(Alias::new("site_url")).text().not_null())
|
||||
.add_column(ColumnDef::new(Alias::new("site_description")).text())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Settings::Table)
|
||||
.drop_column(Alias::new("site_url"))
|
||||
.drop_column(Alias::new("site_description"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
use crate::entities::{prelude::*, *};
|
||||
use crate::AppState;
|
||||
use sea_orm::*;
|
||||
|
||||
use axum::extract::State;
|
||||
use axum::http::{header, StatusCode};
|
||||
use axum::response::IntoResponse;
|
||||
use rss::{ChannelBuilder, ItemBuilder};
|
||||
|
||||
pub(crate) async fn build_rss(state: State<AppState>) -> impl IntoResponse {
|
||||
let settings: settings::Model = match Settings::find()
|
||||
.filter(settings::Column::Id.eq("current"))
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to get site settings!")
|
||||
{
|
||||
Some(settings) => settings,
|
||||
None => panic!("Missing \"current\" settings in database!"),
|
||||
};
|
||||
|
||||
let posts: Vec<post::Model> = Post::find()
|
||||
.filter(post::Column::Draft.eq(false))
|
||||
.order_by_desc(post::Column::Published)
|
||||
.all(&state.db_conn)
|
||||
.await
|
||||
.expect("Failed to load posts!");
|
||||
|
||||
let channel = ChannelBuilder::default()
|
||||
.generator("Kyanite".to_owned())
|
||||
.title(settings.site_name)
|
||||
.link(&settings.site_url)
|
||||
.description(settings.site_description.unwrap_or(settings.site_header))
|
||||
.items(
|
||||
posts
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
ItemBuilder::default()
|
||||
.guid(rss::Guid {
|
||||
value: f.id,
|
||||
permalink: false,
|
||||
})
|
||||
.title(f.title)
|
||||
.description(f.summary)
|
||||
.pub_date(f.published.format("%a, %d %b %Y %H:%M:%S GMT").to_string())
|
||||
.link(format!("{}/post/{}", settings.site_url, f.slug))
|
||||
.build()
|
||||
})
|
||||
.collect::<Vec<rss::Item>>(),
|
||||
)
|
||||
.build();
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
[(header::CONTENT_TYPE, "application/rss+xml")],
|
||||
channel.to_string(),
|
||||
)
|
||||
}
|
Loading…
Reference in new issue