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,11 +243,16 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
|||
..Image::default()
|
||||
}),
|
||||
items: posts
|
||||
.iter()
|
||||
.map(|p| Item {
|
||||
.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.desc.to_owned(),
|
||||
description: p.content.to_owned(),
|
||||
guid: Some(Guid {
|
||||
value: format!("urn:hash:{}", {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
|
@ -256,6 +272,7 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
|||
.to_rfc2822(),
|
||||
),
|
||||
..Item::default()
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
atom_ext: Some(AtomExtension {
|
||||
|
|
Loading…
Reference in a new issue