fetch content for item description
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
This commit is contained in:
parent
56c87aa3c0
commit
61b94eb43e
1 changed files with 43 additions and 26 deletions
|
@ -64,15 +64,25 @@ struct Post {
|
|||
date: Date,
|
||||
url: String,
|
||||
desc: Option<String>,
|
||||
content: Option<String>,
|
||||
}
|
||||
|
||||
impl Hash for Post {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
impl Post {
|
||||
// Fetch the file content
|
||||
fn fetch_content(&mut self) {
|
||||
let blog_dir = "data/blog";
|
||||
let ext = ".md";
|
||||
|
||||
if let Some(file) = read_file(&format!("{blog_dir}/{}{ext}", self.url)) {
|
||||
file.content.hash(state)
|
||||
self.content = Some(file.content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Post {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
if let Some(content) = &self.content {
|
||||
content.hash(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +141,7 @@ fn get_posts(location: &str) -> Vec<Post> {
|
|||
}
|
||||
}),
|
||||
desc: file_metadata.description,
|
||||
content: None,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<Post>>()
|
||||
|
@ -232,30 +243,36 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
|||
..Image::default()
|
||||
}),
|
||||
items: posts
|
||||
.iter()
|
||||
.map(|p| Item {
|
||||
title: Some(p.title.to_owned()),
|
||||
link: Some(format!("{}/blog/p/{}", link_to_site, p.url)),
|
||||
description: p.desc.to_owned(),
|
||||
guid: Some(Guid {
|
||||
value: format!("urn:hash:{}", {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
p.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
.iter_mut()
|
||||
.map(|p| {
|
||||
// Get post data
|
||||
p.fetch_content();
|
||||
|
||||
// Build item
|
||||
Item {
|
||||
title: Some(p.title.to_owned()),
|
||||
link: Some(format!("{}/blog/p/{}", link_to_site, p.url)),
|
||||
description: p.content.to_owned(),
|
||||
guid: Some(Guid {
|
||||
value: format!("urn:hash:{}", {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
p.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}),
|
||||
permalink: false,
|
||||
}),
|
||||
permalink: false,
|
||||
}),
|
||||
pub_date: Some(
|
||||
NaiveDateTime::parse_from_str(
|
||||
&format!("{}-{}-{} 13:12:00", p.date.day, p.date.month, p.date.year),
|
||||
"%d-%m-%Y %H:%M:%S",
|
||||
)
|
||||
.unwrap()
|
||||
.and_local_timezone(Europe::Paris)
|
||||
.unwrap()
|
||||
.to_rfc2822(),
|
||||
),
|
||||
..Item::default()
|
||||
pub_date: Some(
|
||||
NaiveDateTime::parse_from_str(
|
||||
&format!("{}-{}-{} 13:12:00", p.date.day, p.date.month, p.date.year),
|
||||
"%d-%m-%Y %H:%M:%S",
|
||||
)
|
||||
.unwrap()
|
||||
.and_local_timezone(Europe::Paris)
|
||||
.unwrap()
|
||||
.to_rfc2822(),
|
||||
),
|
||||
..Item::default()
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
atom_ext: Some(AtomExtension {
|
||||
|
|
Loading…
Reference in a new issue