fix unmatched cwd

This commit is contained in:
lachrymaLF 2025-03-12 02:21:25 -04:00
parent 276d175cf9
commit 0ce1d2c05e
11 changed files with 27 additions and 15 deletions

4
.gitignore vendored
View file

@ -1,3 +1,3 @@
target/
bin/
out/
example_site/bin/
example_site/out/

View file

@ -4,12 +4,18 @@ kpw_compose-ng
# Run the example
Make sure you [have the Rust toolchain installed](https://www.rust-lang.org/learn/get-started).
```sh
# precompile stb
cd lib
sh build.sh
# Build compost
cargo build -r
# go back and build
cd..
cargo run
# Move binary to example site
cp target/release/compost example_site/
cd example_site
# precompile stb headers
sh lib/build.sh
# run compost
./compost
```
Built pages will be in /out.
Built pages will be in example_site/out.

View file

@ -1,3 +1,4 @@
#!/bin/bash
cd "$(dirname "$0")"
echo "Compiling STB's image I/O library..."
gcc -c ./*.c -I ../include/ -lm

View file

@ -1,3 +1,4 @@
use std::env::{current_exe, set_current_dir};
use std::fs::{create_dir, remove_file, remove_dir_all, read_to_string, write};
use std::path::Path;
use std::process::Command;
@ -177,6 +178,9 @@ fn main() -> Result<(), std::io::Error> {
let copy_year = chrono::Utc::now().year();
let default_thumb = "https://lachrymal.net/thumbnails/default.png";
let dir = current_exe().unwrap().parent().unwrap().to_owned();
set_current_dir(&dir).unwrap();
println!(" ______ __
/ ____/___ ____ ___ ____ ____ _____/ /_
/ / / __ \\/ __ `__ \\/ __ \\/ __ \\/ ___/ __/
@ -184,13 +188,13 @@ fn main() -> Result<(), std::io::Error> {
\\____/\\____/_/ /_/ /_/ .___/\\____/____/\\__/
/_/ ");
println!("Processing...");
println!("Processing directory {}...", dir.display());
println!("=============");
remove_dir_all(output_dir)?;
create_dir(output_dir).unwrap();
remove_dir_all(c_dir)?;
create_dir(c_dir).unwrap();
let _ = remove_dir_all(output_dir);
create_dir(output_dir).expect("Could not create output directory for pages.");
let _ = remove_dir_all(c_dir);
create_dir(c_dir).expect("Could not create output directory for C.");
let pages: Vec<_> = glob(content_dir.join("*").to_str().unwrap()).unwrap().collect();
pages.into_par_iter().for_each(|page| compose(
@ -207,7 +211,8 @@ fn main() -> Result<(), std::io::Error> {
if sync_to_docroot {
println!("Updating website...");
println!("===================");
for html in glob(docroot_dir.join("*.html").to_str().unwrap()).unwrap() {
for html in glob(docroot_dir.join("*.html").to_str().unwrap())
.expect("The docroot directory could not be found... You may need to recompile.") {
match html {
Ok(path) => remove_file(path).unwrap(),
Err(e) => eprintln!("{:?}", e),