Copy published-subset files into ro-crate-preview-files/ during build - #28
Merged
Merged
Conversation
…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>
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
ro-crate-html-output'spublishOnlyoption) 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.collectFilePaths(crate)collects the folder-relative@ids of everyFileentity that survives the filter (skipping externally-hosted files, same guardreconcileFileEntitiesuses in chaos2crate'scrate.js).copyPublishedFilesToPreviewFolder(crate, dirHandle, log)copies each of those files into a freshro-crate-preview-files/directory (wiping a stale one from a previous build first, same pattern asro-crate-preview_html/), warning (not failing) on any file the crate references but the folder no longer has.rewriteToPreviewFilesFolder(html, assetMap)redirects everyhref="…"/src="…"and CSSurl(…)reference to one of those files, from its normal crate-relative path to its copy — applied to the rootro-crate-preview.htmland to every multipage file underro-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-filesis declared in the plugin'soutputPaths, 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 asro-crate-preview_html.ro-crate-metadata.json/.xlsxare unaffected, matching howpublishOnlyalready worked before this change.Test plan
tests/test-publish-preview-files.mjs(this repo has no local test runner of its own — the sibling app's suite exercises it via thefile:../c2c-pluginsdependency) covercollectFilePaths,copyPublishedFilesToPreviewFolder(with faked FSA deps), andrewriteToPreviewFilesFolder, including a filename containing#.npm testpasses (one pre-existing, unrelated failure intest-default-profile.mjsthat reproduces on its main branch too)npm run buildpasses against this branch (via the localfile:../c2c-pluginslink)Closes #27
🤖 Generated with Claude Code