feat: use deref for article view to access original article data.
This commit is contained in:
parent
feec637439
commit
34cf55762b
@ -121,15 +121,24 @@ pub mod view {
|
||||
use crate::models::article::Article;
|
||||
use pulldown_cmark::{html, Parser};
|
||||
use serde::Serialize;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ArticleView<'a> {
|
||||
pub article: &'a Article,
|
||||
article: &'a Article,
|
||||
pub timestamp: i64,
|
||||
pub markdown_content: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl<'a> Deref for ArticleView<'a> {
|
||||
type Target = Article;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.article
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArticleView<'a> {
|
||||
pub fn from(article: &'a Article) -> ArticleView {
|
||||
let content_split: Vec<_> = article.body.split("<!--more-->").collect();
|
||||
|
@ -22,11 +22,11 @@ pub fn rss_(data: web::Data<RubbleData>) -> impl Responder {
|
||||
.map(ArticleView::from)
|
||||
.map(|item| {
|
||||
ItemBuilder::default()
|
||||
.title(item.article.title.clone())
|
||||
.link(format!("{}{}", setting.url, item.article.link()))
|
||||
.description(item.description)
|
||||
.content(item.markdown_content)
|
||||
.pub_date(item.article.publish_at.to_string())
|
||||
.title(item.title.clone())
|
||||
.link(format!("{}{}", setting.url, item.link()))
|
||||
.description(item.description.clone())
|
||||
.content(item.markdown_content.clone())
|
||||
.pub_date(item.publish_at.to_string())
|
||||
.build()
|
||||
.unwrap()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user