template creator
This commit is contained in:
parent
614a7389e8
commit
b0168c05be
4 changed files with 238 additions and 8 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -36,27 +36,45 @@ fn main() -> io::Result<()> {
|
|||
channel.link = "https://mdf.farm".to_string();
|
||||
channel.description = "morbius text wow".to_string();
|
||||
channel.generator = Some("Rakabaka's tooling".to_string());
|
||||
channel.items = posts.iter().enumerate().map(|(i, (body, metadata))| {
|
||||
let guid = metadata.get("title").map(|title|
|
||||
channel.items = posts.iter().map(|(body, metadata)| {
|
||||
let guid = metadata.get("guid").map(|guid|
|
||||
GuidBuilder::default()
|
||||
.value(title)
|
||||
.permalink(true)
|
||||
.value(guid)
|
||||
.permalink(false)
|
||||
.build()
|
||||
);
|
||||
ItemBuilder::default()
|
||||
.title(metadata.get("title").map(|title| title.clone()))
|
||||
.description(Some(body.clone()))
|
||||
.pub_date(metadata.get("pubDate").map(|title| title.clone()))
|
||||
.link(format!("https://mdf.farm/#guid"))
|
||||
.link(metadata.get("guid").map(|g| format!("https://mdf.farm/#{g}")))
|
||||
.guid(guid)
|
||||
.build()
|
||||
}).collect();
|
||||
print!("{}", channel);
|
||||
},
|
||||
"html" => {
|
||||
print!("{}", posts.iter().enumerate().map(|(i, (body, metadata))| format!("<div class=\"blogpost\" id=post{i}>{body}</div>")).collect::<Vec<String>>().concat())
|
||||
print!("{}", posts.iter().enumerate().map(|(i, (body, metadata))| {
|
||||
let guid = metadata.get("guid").unwrap_or(&i.to_string()).clone();
|
||||
let title = metadata.get("title").map(|title| format!("<h1>{title}</h1>")).unwrap_or("".to_string());
|
||||
let pub_date = metadata.get("pubDate").map(|pub_date| format!("<i>{pub_date}</i>")).unwrap_or("".to_string());
|
||||
format!("<div class=\"blogpost\" id={guid}>{title}{body}{pub_date}</div>")
|
||||
}).collect::<Vec<String>>().concat())
|
||||
},
|
||||
_ => eprintln!("need to specify 'rss' or 'html'"),
|
||||
"new" => {
|
||||
eprint!("title: ");
|
||||
let mut title = String::new();
|
||||
io::stdin().read_line(&mut title).unwrap();
|
||||
|
||||
eprint!("author: ");
|
||||
let mut author = String::new();
|
||||
io::stdin().read_line(&mut author).unwrap();
|
||||
|
||||
let pub_date = chrono::Utc::now();
|
||||
|
||||
print!("title: {title}author: {author}pubDate: {pub_date}");
|
||||
},
|
||||
_ => eprintln!("need to specify 'rss', 'html' or 'new'"),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue