Skip to content

Copy published-subset files into ro-crate-preview-files/ during build - #28

Merged
benfoley merged 1 commit into
mainfrom
feature/publish-only-copy-files
Sep 21, 2026
Merged

benfoley merged 1 commit into
mainfrom
feature/publish-only-copy-files

Conversation

@benfoley

Copy link
Copy Markdown
Collaborator

Summary

  • "Publish subset only" (ro-crate-html-output's publishOnly option) already filters the metadata graph to just the published collections/objects/files (filterCrateToPublished), but never touched the actual files on disk — a folder holding just the generated preview still exposed every file, published or not.
  • New collectFilePaths(crate) collects the folder-relative @ids of every File entity that survives the filter (skipping externally-hosted files, same guard reconcileFileEntities uses in chaos2crate's crate.js).
  • New copyPublishedFilesToPreviewFolder(crate, dirHandle, log) copies each of those files into a fresh ro-crate-preview-files/ directory (wiping a stale one from a previous build first, same pattern as ro-crate-preview_html/), warning (not failing) on any file the crate references but the folder no longer has.
  • New rewriteToPreviewFilesFolder(html, assetMap) redirects every href="…"/src="…" and CSS url(…) reference to one of those files, from its normal crate-relative path to its copy — applied to the root ro-crate-preview.html and to every multipage file under ro-crate-preview_html/. It matches each known file path as one literal string rather than splitting at the first #/?, so a file whose own name contains one of those characters (real crates have these) still resolves correctly instead of being mistaken for a URL fragment/query.
  • ro-crate-preview-files is declared in the plugin's outputPaths, so it's automatically excluded from the next build's directory scan and cleaned up by the existing "delete plugin output before rebuilding" setting, the same as ro-crate-preview_html.
  • Deliberately scoped to the generated HTML only — ro-crate-metadata.json/.xlsx are unaffected, matching how publishOnly already worked before this change.

Test plan

  • New tests in chaos2crate's tests/test-publish-preview-files.mjs (this repo has no local test runner of its own — the sibling app's suite exercises it via the file:../c2c-plugins dependency) cover collectFilePaths, copyPublishedFilesToPreviewFolder (with faked FSA deps), and rewriteToPreviewFilesFolder, including a filename containing #.
  • chaos2crate's full npm test passes (one pre-existing, unrelated failure in test-default-profile.mjs that reproduces on its main branch too)
  • chaos2crate's npm run build passes against this branch (via the local file:../c2c-plugins link)

Closes #27

🤖 Generated with Claude Code

…the generated HTML at them

"Publish subset only" filtered the in-memory crate before rendering, but
left every file on disk untouched, so a folder holding just the generated
preview still exposed files that were meant to be filtered out. Now the
files that survive the filter are copied into ro-crate-preview-files/, and
every href/src/CSS url() reference the generated HTML makes to them is
rewritten to point at the copy, so the generated preview plus that one
folder is self-contained and safe to publish on its own.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

Publish subset only should copy its files, not just filter metadata

1 participant