Repository navigation
Replies: 2 comments 1 reply
Will figure out how Netlify/Decap CMS handles this. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Use case
A custom field type that stores several files derived from one image:
{ original, tiny, optimized, aspectRatio }. The control takes the upload, generates a 50px WebP thumbnail and a resized WebP in the browser, and stores all three paths plus the aspect ratio.Problem
Custom controls receive
value,field,forID,classNameWrapper,entryandonChange, but have no way to hand a file to the CMS.getFieldType('image')returnsundefined, so the built-in control can't be wrapped either.The only workaround is committing the files from a
preSavehook with the backend token read fromlocalStorage['sveltia-cms.user']. That also means re-fetching and parsing the config to findrepo,branchandpublish_mode, and reproducing thecms/<collection>/<slug>branch naming. It's fragile, produces an extra commit per save, and can't work with Open Authoring.Why this looks like a small change
The save pipeline already ignores field type.
createBaseSavingEntryDatascans every string in the flattened entry content for blob URLs, including strings nested in object values, and uploads any blob whoseFileis indraft.files. The only thing missing is a way to write todraft.files, which today only the built-in File/Image editor does (services/contents/fields/file/process.js).Proposal
A control prop that registers a file with the draft and returns a blob URL:
On save, the blob URLs are replaced with public paths, and the files are committed with the entry. That would happen in the same commit and on the same branch as the entry, with the usual folder resolution, file naming and dedup. An optional second argument for the target folder would be nice but isn't required, since the field's or collection's media folder is a sensible default.
For comparison, Decap passes undocumented
onPersistMediaandmediaPathsprops to widgets for similar purposes. A documented equivalent would cover this and similar custom fields.All reactions