Skip to content

Fixes and improvements: clean, Windows URLs, and deterministic scan order - #154

Merged
haltakov merged 6 commits into
mainfrom
improvements/top-5
Jun 13, 2026
Merged

Fixes and improvements: clean, Windows URLs, and deterministic scan order#154
haltakov merged 6 commits into
mainfrom
improvements/top-5

Conversation

@haltakov

@haltakov haltakov commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

A batch of five independent fixes and improvements (the "top 5").

1. Deterministic scan order

scanDirectory returned files in raw fs.readdir order, 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, so IMG_2.jpg sorts before IMG_10.jpg.

2. Preserve gallery.json by default when cleaning

spg clean previously deleted the entire gallery/ directory, including gallery.json with 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 --all flag also removes gallery.json, guarded by a confirmation prompt (-f/--force skips it; in a non-TTY it refuses without --force).

3. Forward slashes in generated URLs on Windows

Paths built with path.join use backslashes on Windows, which are invalid URL separators. Added toUrlPath/joinUrl helpers 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 formats themes/modern.

5. Build on prepack instead of deprecated prepublish

prepublish is deprecated and no longer runs on npm publish. Switched the build hook to prepack for the gallery and common packages so the published artifacts are always built.

Tests

  • scan.test.ts, clean.test.ts, url-paths.test.ts, plus additions to gallery.test.ts.

haltakov and others added 5 commits June 12, 2026 21:19
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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread gallery/src/modules/clean/index.ts
@haltakov haltakov changed the title Improvements Fixes and improvements: clean, Windows URLs, and deterministic scan order Jun 13, 2026
@haltakov
haltakov merged commit 82d1566 into main Jun 13, 2026
1 check passed
@haltakov
haltakov deleted the improvements/top-5 branch June 13, 2026 22:20
@haltakov
haltakov restored the improvements/top-5 branch June 13, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant