generate .md postfix

This commit is contained in:
yggverse 2026-03-19 19:33:24 +02:00
parent 1c0df42fb4
commit abb082dac2
2 changed files with 29 additions and 8 deletions

View file

@ -19,7 +19,7 @@ pub struct Discussion {
pub first_post_id: i64,
pub created_at: DateTime<Utc>,
pub title: String,
//pub slug: String,
pub slug: String,
}
pub struct Post {
@ -73,7 +73,7 @@ impl Database {
first_post_id: row.get(2)?,
created_at: row.get(3)?,
title: row.get(4)?,
//slug: row.get(5)?,
slug: row.get(5)?,
})
})?
.collect()

View file

@ -33,6 +33,7 @@ pub struct Discussion {
pub id: i64,
pub created_at: DateTime<Utc>,
pub title: String,
pub slug: String,
pub posts: Vec<Post>,
}
@ -108,6 +109,7 @@ fn main() -> Result<()> {
id: discussion.id,
created_at: discussion.created_at,
title: discussion.title,
slug: discussion.slug,
posts,
})
}
@ -142,7 +144,7 @@ fn main() -> Result<()> {
file.write_all(footer.join("\n").as_bytes())?
}
for discussion in discussions {
for discussion in &discussions {
let mut file = File::create_new({
let mut path = PathBuf::from(&config.target);
path.push(format!("{}.md", discussion.id));
@ -154,7 +156,7 @@ fn main() -> Result<()> {
page.push(format!("# {}\n", discussion.title.trim()));
page.push({
let mut content = Vec::new();
for post in discussion.posts {
for post in &discussion.posts {
content.push(format!(
"_@{} / {}{}_\n",
users.get(&post.user_id).unwrap().username,
@ -164,10 +166,29 @@ fn main() -> Result<()> {
.unwrap_or_default()
));
let mut uploads = HashSet::new();
content.push(post_format(&convert(
content.push({
let mut post = post_format(&convert(
pre_format(&post.content, &mut uploads).trim(),
None,
)?));
)?);
for d in &discussions {
post = post
.replace(
&format!("](/d/{}-{})", d.id, d.slug),
&format!("]({}.md)", d.id),
)
.replace(
&format!("](d/{}-{})", d.id, d.slug),
&format!("]({}.md)", d.id),
)
.replace(
&format!("]({}-{})", d.id, d.slug),
&format!("]({}.md)", d.id),
)
.replace(&format!("]({})", d.id), &format!("]({}.md)", d.id))
}
post
});
for upload in &uploads {
let path_source = {
let mut p = PathBuf::from(&config.upload);