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

View file

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