From 76fb8e6c0861682c92a0ed49c3271aaa91fc5c4a Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Sun, 19 Mar 2023 16:45:03 -0600 Subject: [PATCH] Put media in correct place for export --- index.html | 2 -- src/main.rs | 11 ++++++++--- src/render.rs | 8 ++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index c3f6d2e..2a1f81c 100644 --- a/index.html +++ b/index.html @@ -13,5 +13,3 @@ - - diff --git a/src/main.rs b/src/main.rs index 6f7db1a..1bdfa03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ fn generate() -> Result<(), Ærror> { { let output_str = render_ssr(outbox, author, archive_time)?; - println!("{}", output_str); + fs::write("out/index.html", output_str); copy_items( &mut vec!["resources/"], @@ -76,10 +76,12 @@ fn generate() -> Result<(), Ærror> { fn setup_dirs(args: &GeneratorOptions) -> Result<(), crate::error::Ærror> { let output_dir = Path::new(&args.output_dir); + let media_dir = output_dir.join("media"); // Create output dir if !output_dir.exists() { fs::create_dir(output_dir)?; + fs::create_dir(media_dir)?; } else if !output_dir.read_dir()?.next().is_none() && !args.overwrite { return Err(Ærror::new(format!( "Output directory {} exists but --overwrite not given", @@ -88,6 +90,7 @@ fn setup_dirs(args: &GeneratorOptions) -> Result<(), crate::error::Ærror> { } else { fs::remove_dir_all(output_dir)?; fs::create_dir(output_dir)?; + fs::create_dir(media_dir)?; } Ok(()) @@ -98,6 +101,8 @@ fn read_archive( ) -> Result<(String, String, DateTime), crate::error::Ærror> { #[cfg(not(debug_assertions))] let path = &args.archive_file; + let output_dir = Path::new(&args.output_dir); + let media_dir = output_dir.join("media"); let tar; @@ -151,11 +156,11 @@ fn read_archive( "avatar.png" => { #[cfg(not(debug_assertions))] - file.unpack_in(&args.output_dir)?; + file.unpack_in(&media_dir)?; } "header.png" => { #[cfg(not(debug_assertions))] - file.unpack_in(&args.output_dir)?; + file.unpack_in(&media_dir)?; } _ => (), }; diff --git a/src/render.rs b/src/render.rs index 8f888bb..cd82902 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,6 +1,6 @@ use chrono::DateTime; use futures::executor; -use yew::{function_component, html, Html, Renderer, ServerRenderer, AttrValue}; +use yew::{function_component, html, AttrValue, Html, Renderer, ServerRenderer}; #[cfg(debug_assertions)] use console_error_panic_hook::set_once as set_panic_hook; @@ -25,9 +25,13 @@ pub fn render_ssr( author: Person, archive_time: DateTime, ) -> Result { + let output_template = include_str!("../index.html"); let output_string = executor::block_on(render_async(outbox, author, archive_time)); - Ok(output_string) + Ok(output_template.replace( + "", + &output_string, + )) } #[cfg(debug_assertions)]