mirror of
https://github.com/YGGverse/flarumdown.git
synced 2026-03-31 08:45:28 +00:00
implement original references, gen time, fix special chars escape
This commit is contained in:
parent
4bbb4e79b2
commit
02a7697b49
2 changed files with 32 additions and 1 deletions
|
|
@ -25,4 +25,8 @@ pub struct Config {
|
|||
/// Generate index file with given name
|
||||
#[arg(short, long)]
|
||||
pub index: Option<String>,
|
||||
|
||||
/// Append reference to original source (mirrors)
|
||||
#[arg(short, long)]
|
||||
pub refer: Vec<String>,
|
||||
}
|
||||
|
|
|
|||
29
src/main.rs
29
src/main.rs
|
|
@ -119,8 +119,27 @@ fn main() -> Result<()> {
|
|||
path
|
||||
})?;
|
||||
for discussion in &discussions {
|
||||
file.write_all(format!("* [{}]({}.md)\n", discussion.title, discussion.id).as_bytes())?;
|
||||
file.write_all(
|
||||
format!(
|
||||
"* [{}]({}.md)\n",
|
||||
discussion
|
||||
.title
|
||||
.replace("[", "\\[")
|
||||
.replace("]", "\\]")
|
||||
.replace("(", "\\(")
|
||||
.replace(")", "\\)"),
|
||||
discussion.id
|
||||
)
|
||||
.as_bytes(),
|
||||
)?;
|
||||
}
|
||||
let mut footer = Vec::new();
|
||||
footer.push("\n---\n".into());
|
||||
footer.push(format!("Generated at {}\n", Utc::now()));
|
||||
for refer in &config.refer {
|
||||
footer.push(format!("* {refer}"));
|
||||
}
|
||||
file.write_all(footer.join("\n").as_bytes())?
|
||||
}
|
||||
|
||||
for discussion in discussions {
|
||||
|
|
@ -176,6 +195,14 @@ fn main() -> Result<()> {
|
|||
}
|
||||
content.push("---\n".into())
|
||||
}
|
||||
content.push(format!("Generated at {}\n", Utc::now()));
|
||||
for refer in &config.refer {
|
||||
content.push(format!(
|
||||
"* {}/d/{}",
|
||||
refer.trim_end_matches("/"),
|
||||
discussion.id
|
||||
));
|
||||
}
|
||||
content.join("\n")
|
||||
});
|
||||
page.join("\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue