diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..ac2b23f --- /dev/null +++ b/.cargo/config @@ -0,0 +1,2 @@ +[target.x86_64-pc-windows-msvc] +rustflags = ["-C", "target-feature=+crt-static"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bbe53de..70f2598 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,16 +17,20 @@ jobs: upload-assets: strategy: matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest + include: + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest + - target: x86_64-pc-windows-msvc + os: windows-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: taiki-e/upload-rust-binary-action@v1 with: bin: srv + target: ${{ matrix.target }} tar: unix zip: windows env: diff --git a/Cargo.lock b/Cargo.lock index e265d53..5d32730 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1904,6 +1904,7 @@ dependencies = [ "sha2", "tera", "toml", + "urlencoding", ] [[package]] @@ -2381,6 +2382,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b90931029ab9b034b300b797048cf23723400aa757e8a2bfb9d748102f9821" + [[package]] name = "v_escape" version = "0.15.0" diff --git a/Cargo.toml b/Cargo.toml index 0c5c0b6..7551677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ serde = "1" sha2 = "0.9" tera = "1" toml = "0.5" +urlencoding = "2.1" [profile.release] lto = true diff --git a/src/main.rs b/src/main.rs index c29781d..833c801 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,9 +180,9 @@ struct File { } #[derive(serde::Serialize)] -struct IndexContext<'r> { - title: &'r str, - paths: Vec<&'r str>, +struct IndexContext { + title: String, + paths: Vec, dirs: Vec, files: Vec, } @@ -211,7 +211,7 @@ fn render_index( } let show_dot_files = var("DOTFILES").unwrap_or("false".to_string()) == "true"; let mut context = IndexContext { - title: "", + title: "".to_string(), paths: vec![], dirs: vec![], files: vec![], @@ -220,6 +220,9 @@ fn render_index( if path == "" { continue; } + let path = + urlencoding::decode(path).unwrap_or(std::borrow::Cow::Borrowed("[Parse URL Error]")); + let path = path.into_owned(); context.paths.push(path); } match read_dir(&dir.path) { @@ -276,7 +279,7 @@ fn render_index( } } } - context.title = context.paths.last().unwrap_or(&"/"); + context.title = context.paths.last().unwrap_or(&"/".to_string()).to_string(); context.dirs.sort(); context.files.sort(); let content = tera::Context::from_serialize(&context); @@ -632,7 +635,11 @@ async fn main() -> std::io::Result<()> { } else { process_time }); - let content = blue.value(data[4]); + let content = blue.value( + urlencoding::decode(data[4]) + .unwrap_or(std::borrow::Cow::Borrowed("[Parse URL Error]")) + .into_owned(), + ); return writeln!( buf, "[{}] {} | {} | {} | {}",