feat: add post title

This commit is contained in:
Patrick 2024-10-19 19:30:16 +02:00
parent 3092ce7f5f
commit 00d3f49445
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
2 changed files with 32 additions and 21 deletions

View file

@ -1,6 +1,6 @@
use copy_dir::copy_dir;
use std::fs::{create_dir_all, read_to_string, remove_file, write, File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Write};
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
use std::process::Stdio;
@ -52,6 +52,7 @@ struct Config {
#[derive(Debug, Default, Template)]
#[template(path = "post.md")]
struct PostTemplate {
title: String,
date: String,
date_title: String,
messages: Vec<Message>,
@ -161,7 +162,7 @@ async fn main() -> Result<()> {
let at = get_msg_attachments(&mut client, &v).await;
if text.is_none() && at.is_none() {
continue;
} else if sender != &config.allowed_sender {
} else if sender != config.allowed_sender {
println!("{:?}", sender);
send(
&client,
@ -180,21 +181,29 @@ async fn main() -> Result<()> {
if cmds.len() >= 2 && cmds[0] == "©" {
match cmds[1] {
"help" => {
let text = "
Available commands:
- post: Generate post for yesterday
- tz: change timezone
"
let text = "\nAvailable commands:\n - post: Generate post for yesterday\n - tz: change timezone\n"
.to_string();
send(&client, sender, text).await?;
}
"post" => {
if cmds.len() != 3 {
send(
&client,
sender,
"Wrong number of arguments.\nExpected: 1(title)".to_string(),
)
.await?;
} else {
let res = generate_post(&config, &mut client).await;
if let Ok(res) = res {
send(
&client,
sender,
format!("Generated blog post at: {}/{}", config.url, res),
format!(
"Generated blog post at: {}/{}",
config.url,
res.replace("[+:.]", "-").to_lowercase()
),
)
.await?;
} else {
@ -206,6 +215,7 @@ Available commands:
.await?;
}
}
}
"tz" => {
if cmds.get(2).is_some_and(|x| {
x.parse::<i32>()
@ -214,14 +224,15 @@ Available commands:
println!("{}", tz_data_path);
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&tz_data_path)?;
file.write_all(cmds[2].as_bytes())?;
config.timezone = cmds[2].to_string();
send(&client, sender, format!("Updated tz data")).await?;
send(&client, sender, "Updated tz data".to_string()).await?;
} else {
send(&client, sender, format!("Error parsing")).await?;
send(&client, sender, "Error parsing".to_string()).await?;
}
}
_ => {
@ -235,7 +246,7 @@ Available commands:
.append(true)
.create(true)
.open(format!("{}/texts.json", config.data_folder))?;
writeln!(file, "{}", v.to_string())?;
writeln!(file, "{}", v)?;
}
}
async fn send(client: &Client, sender: &str, msg: String) -> Result<()> {

View file

@ -1,10 +1,10 @@
+++
title = "Journal for {{ date_title }}"
title = "{{title}} ({{ date_title }})"
date = {{ date }}
draft = false
[taxonomies]
tags = ["Signal to blog"]
tags = ["Signal to blog" "Journal"]
+++
{% for msg in messages %}