From 4f1d9f62e217e6b5d2a4465cebb08115f4bbc3e5 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 17 Feb 2022 21:29:55 -0800 Subject: [PATCH] Rebuild site upon image deletion --- src/commands/challenge.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 2888997..9654372 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -106,6 +106,13 @@ fn to_fullwidth(string: &str) -> String { fullwidth } +fn rebuild_site() { + Command::new("hugo") + .current_dir(get_hugo_path()) + .spawn() + .expect("Failed to rebuild site"); +} + #[command] async fn challenge(ctx: &Context, msg: &Message) -> CommandResult { msg.reply( @@ -148,7 +155,6 @@ async fn submit(ctx: &Context, msg: &Message) -> CommandResult { .await?; return Ok(()); } - let hugo_path = get_hugo_path(); let challenge_number = get_challenge_number(); let submission_images_dir = get_submission_images_dir(); @@ -254,10 +260,7 @@ async fn submit(ctx: &Context, msg: &Message) -> CommandResult { if invalid_types { message.push_str("\nSome of your attachments could not be uploaded; only **.png**, **.jpg**, and **.jpeg** files are permitted."); } - Command::new("hugo") - .current_dir(&hugo_path) - .spawn() - .expect("Failed to rebuild site"); + rebuild_site(); } else if invalid_types { message.push_str("Sorry, your submission could not be uploaded; only **.png**, **.jpg**, and **.jpeg** files are permitted."); } @@ -407,6 +410,7 @@ async fn imageDelete(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes submission["images"] = images.into(); } set_submission_data(submission_data); + rebuild_site(); msg.reply(&ctx.http, message).await?; return Ok(()); }