-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
always sort assets by filename (Windows/Linux difference) #2236
Conversation
Looking at the WalkDir function, I don't know if it does case insensitive ordering, I'm guessing it doesn't from the source? Might be needed for Mac, I'll check later tonight. |
Good point. It uses case-sensitive sorting (checked both Windows and Linux), i.e.
Unpatched Windows builds do case-insensitive sorts. There's currently no toggle for this in WalkDir . An issue was followed by a PR, that was refused and in limbo since. In summary, sorting Unicode is complex, and the dev doesn't want more dependencies and suggests using Suggests using Walkdir |
We can just keep the default unsorted walkdir and sort it ourselves after lowercasing the filenames. I think it's what most people expect but I could be wrong! |
KISS then :) So something like this before returning
I'm new to Rust BTW ;) |
KISS is my motto. First one is fine |
Uses .to_str() to sort files and subfolders. The .unwrap() may need work or be replaced by unwrap_or_default(). Given earlier checks in the function it should work however.
OK. It now uses Note sure about |
Thanks it looks good. Do you know how to write tests in Rust? Otherwise I can do it. |
Great. Tests, no, but I can try. You can always replace it. This would require extending the test below (at least), creating additional files like zola/components/content/src/utils.rs Lines 78 to 98 in a3dd45f
|
Yep and since they will be sorted you can remove the loop in zola/components/content/src/utils.rs Line 95 in a3dd45f
|
Just dawned on me what you meant... at least I hope so :) Alternatively, see the now removed standalone check using
zola/components/content/src/utils.rs Line 108 in dec6815
|
Nice, thanks! |
* sort page.assets by filename Uses .to_str() to sort files and subfolders. The .unwrap() may need work or be replaced by unwrap_or_default(). Given earlier checks in the function it should work however. * add tests for assets sorting * fix rustfmt * use existing loop instead of windows * also check the non-recursive test * use .zip() and add assert msg
* sort page.assets by filename Uses .to_str() to sort files and subfolders. The .unwrap() may need work or be replaced by unwrap_or_default(). Given earlier checks in the function it should work however. * add tests for assets sorting * fix rustfmt * use existing loop instead of windows * also check the non-recursive test * use .zip() and add assert msg
* sort page.assets by filename Uses .to_str() to sort files and subfolders. The .unwrap() may need work or be replaced by unwrap_or_default(). Given earlier checks in the function it should work however. * add tests for assets sorting * fix rustfmt * use existing loop instead of windows * also check the non-recursive test * use .zip() and add assert msg
For me the
page.assets
items are sorted differently on Windows and Linux. Zola on Windows sorts assets alphabetically, for Linux the sorting is kinda arbitrary as shown below:It's no big deal, and could also be fixed using
page.assets | sort
, but this differing between platforms is not what one would expect.A small patch is attached. The patch modifies
find_related_assets
to use the walkdir optionsort_by_file_name
(docs hints that the order isn't guaranteed otherwise). Feel free to accept or reject the patch.Using
Zola version: 1.7.2
Windows 11 + Debian (PopOS 22.04)
Step to reproduce
Re-create the asset files using the scripts below. They're reversed, checking if Linux sorts by date (it does not).
Windows powershell
Linux/BSD