Fixes and improvements: clean, Windows URLs, and deterministic scan order - #154
Merged
Conversation
The prepublish lifecycle script is deprecated and is not run by npm publish or yarn npm publish, so a publish from a machine with a stale dist/ would ship old code. prepack is run by both npm and Yarn before packing, guaranteeing a fresh build on every publish. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The workflow previously triggered only on changes under gallery/**, so PRs touching common/ (which every package depends on) or themes/ ran no CI at all. Remove the path filter and add lint + format checks for the modern theme. Also fix a formatting issue in MainLayout.astro that the newly enabled theme format check caught. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Several URLs that end up in the generated HTML or in gallery.json were built with path functions, which use backslashes on Windows: - getSubgalleryThumbnailPath joined the sub-gallery thumbnail URL with path.join, producing broken links like sub\gallery\images\x.avif - getRelativePath returned path.relative output unchanged - the build command concatenated --base-url and --thumbs-base-url with path.relative directly, which also dropped the separator between the base URL and the subdirectory unless the base URL had a trailing slash - init stored sub-gallery paths with native separators Add toUrlPath and joinUrl helpers to the common theme utilities, use them at every point where a filesystem path becomes a URL, and cover the behavior with tests (including backslash inputs as produced on Windows). Map marked to its CJS-compatible UMD build in the Jest config so tests can import the common theme barrel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The clean command previously deleted the entire gallery/ directory, including gallery.json with all user-curated titles, descriptions and section organization, without any confirmation. Clean now only removes generated files (index.html, thumbnails, built assets) by default. A new --all option removes gallery.json as well, guarded by a confirmation prompt that can be skipped with --force. In non-interactive environments --all requires --force so automation never hangs or deletes curated content unintentionally. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
scanDirectory returned files in raw fs.readdir order, which depends on the file system (effectively arbitrary on some platforms), so the photo order in a new gallery was non-deterministic. Sort media files and sub-gallery directories by name with numeric-aware comparison so IMG_2.jpg sorts before IMG_10.jpg. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6b9ae74ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # common/src/theme/paths.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A batch of five independent fixes and improvements (the "top 5").
1. Deterministic scan order
scanDirectoryreturned files in rawfs.readdirorder, which is filesystem-dependent and effectively arbitrary on some platforms, making the photo order in a new gallery non-deterministic. Media files and sub-gallery directories are now sorted by name with numeric-aware comparison, soIMG_2.jpgsorts beforeIMG_10.jpg.2. Preserve gallery.json by default when cleaning
spg cleanpreviously deleted the entiregallery/directory, includinggallery.jsonwith the user's curated titles, descriptions and sections. It now removes only generated files (index.html, thumbnails, built assets) and preserves gallery.json. A new--allflag also removes gallery.json, guarded by a confirmation prompt (-f/--forceskips it; in a non-TTY it refuses without--force).3. Forward slashes in generated URLs on Windows
Paths built with
path.joinuse backslashes on Windows, which are invalid URL separators. AddedtoUrlPath/joinUrlhelpers and applied them to generated relative and thumbnail URLs, so galleries built on Windows produce valid URLs.4. Run CI checks for all packages
The PR check workflow only ran for changes under
gallery/**. It now runs on every PR (path filter removed) and also lints and formatsthemes/modern.5. Build on
prepackinstead of deprecatedprepublishprepublishis deprecated and no longer runs onnpm publish. Switched the build hook toprepackfor thegalleryandcommonpackages so the published artifacts are always built.Tests
scan.test.ts,clean.test.ts,url-paths.test.ts, plus additions togallery.test.ts.