From 5cfa9ced6749c3b25964c161b311232e91378993 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 27 Jul 2023 01:12:17 +0200 Subject: [PATCH] fix: build Signed-off-by: kjuulh --- build.sh | 2 +- ci/src/main.rs | 2 +- src/main.rs | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 3fa092e..5168945 100755 --- a/build.sh +++ b/build.sh @@ -6,4 +6,4 @@ cargo build popd || exit -./ci/target/debug/ci +dagger run ./ci/target/debug/ci diff --git a/ci/src/main.rs b/ci/src/main.rs index 7a0f2b0..cabb2fa 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -16,7 +16,7 @@ async fn main() -> eyre::Result<()> { .build()?, ); - let variants = vec![/*"linux/amd64", */ "linux/arm64"]; + let variants = vec!["linux/amd64"]; // "linux/arm64"]; let platform_variants = Arc::new(Mutex::new(Vec::new())); tokio_scoped::scope(|s| { diff --git a/src/main.rs b/src/main.rs index eb116f1..2fafdb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,17 @@ async fn main() -> eyre::Result<()> { .arg(clap::Arg::new("repo").long("repo").required(true)) .arg(clap::Arg::new("path").long("path").required(true)) .arg(clap::Arg::new("out").long("out").required(true)) + .arg( + clap::Arg::new("static-out") + .long("static-out") + .required(false), + ) .get_matches(); let repo = matches.get_one::("repo").unwrap(); let path = matches.get_one::("path").unwrap(); let out = matches.get_one::("out").unwrap(); + let static_out = matches.get_one::("static-out"); tracing::info!(repo = repo, path = path, out = out, "pulling articles"); @@ -56,7 +62,7 @@ async fn main() -> eyre::Result<()> { let out_dir = PathBuf::from(out); tokio::fs::create_dir_all(&out_dir).await?; - let mut dir = tokio::fs::read_dir(repo_dir).await?; + let mut dir = tokio::fs::read_dir(&repo_dir).await?; while let Some(file) = dir.next_entry().await? { if let Ok(ft) = file.file_type().await { @@ -66,6 +72,7 @@ async fn main() -> eyre::Result<()> { let (frontmatter, content) = extract_frontmatter(file_str)?; let transformed_frontmatter = transform_frontmatter(frontmatter)?; + let content = content.replace("assets/", "/assets/"); let new_article = format!("{}\n{}", transformed_frontmatter, content); let mut out_file = out_dir.clone(); @@ -76,6 +83,34 @@ async fn main() -> eyre::Result<()> { } } + if let Some(static_out) = static_out { + let mut assets_dir = repo_dir.clone(); + assets_dir.push("assets"); + tracing::info!( + asserts_dir = assets_dir.display().to_string(), + "reading assets" + ); + + match tokio::fs::read_dir(&assets_dir).await { + Ok(mut dir) => { + tokio::fs::create_dir_all(static_out).await?; + while let Some(file) = dir.next_entry().await? { + if let Ok(_file_type) = file.file_type().await { + let from = file.path(); + let to = PathBuf::from(static_out).join(file.file_name()); + tracing::info!( + from = from.display().to_string(), + to = to.display().to_string(), + "moving file" + ); + tokio::fs::rename(from, to).await?; + } + } + } + Err(e) => tracing::error!(error = e.to_string(), "failed to read dir"), + } + } + Ok(()) }