getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.43k stars 941 forks source link

Custom site root doesn't work on Windows #1361

Open southerntofu opened 3 years ago

southerntofu commented 3 years ago

From the forums

Windows 10, zola 0.13.0

It appears the -r flag is broken on Windows, at least with absolute links, like so:

zola.exe -r "D:\Dev\Zola\zola-clean-blog" build
Keats commented 3 years ago

This feels like https://github.com/getzola/zola/blob/master/src/main.rs#L15-L20 should work 🤔

Keats commented 3 years ago

Is it still happening with 0.14?

warsus commented 2 years ago

I had the same problem on master branch [0] and did a little analysis. It appears to me that (at least in my case) the problem might be that the windows canonical path looks like this:

root_dir: \?\C:\Users\user\my_site

My guess is the questionmark in the prefix will later be interpreted as a globbing character. Tera::parse will create no matches then.

I kinda confirmed this by removing the "canonicalize" call in the root_dir assignment, which fixed the problem for me.

let root_dir = match matches.value_of("root").unwrap() {
    "." => env::current_dir().unwrap(),
    path => PathBuf::from(path)
        .canonicalize()
        .unwrap_or_else(|_| panic!("Cannot find root directory: {}", path)),
}; 

[0] commit 9946506e1c363a35f097a7b220c613f77a989c43 (HEAD -> master, origin/master, origin/HEAD)

Keats commented 2 years ago

@warsus thanks for digging! I can't remember why we're canonicalizing it to be honest. If you can do a PR with that change on the next branch, I'll test on macos.

warsus commented 2 years ago

@Keats Sure i will try to do a PR later today. Also i think my assumption about the questionmark was not completly right. But i still think it's something about the \? prefix, might do some further digging in the tera lib afterwards.