diff --git a/fields/core/file/edit-component.tsx b/fields/core/file/edit-component.tsx index 5e74f899c..5fcb66265 100644 --- a/fields/core/file/edit-component.tsx +++ b/fields/core/file/edit-component.tsx @@ -47,12 +47,18 @@ type FieldOptions = { rename?: boolean | "safe" | "random"; }; -const FileTeaser = ({ file, config, onRemove, getFileIcon }: { +const FileTeaser = ({ file, config, mediaInput, onRemove, getFileIcon }: { file: string; config: Pick; + mediaInput?: string; onRemove?: () => void; getFileIcon: (file: string) => React.ReactNode; }) => { + const normalizedFile = file.replace(/^\.\//, '').replace(/^\//, ''); + const githubPath = mediaInput && !file.startsWith(mediaInput) && !file.startsWith('http') + ? `${mediaInput}/${normalizedFile}` + : file; + return ( <>
@@ -65,7 +71,7 @@ const FileTeaser = ({ file, config, onRemove, getFileIcon }: { )} - +
); @@ -351,6 +358,7 @@ const EditComponent = forwardRef((props: EditorProps, ref: React.Ref handleRemove(file.id)} getFileIcon={getFileIcon} readonly={isReadonly} @@ -361,7 +369,7 @@ const EditComponent = forwardRef((props: EditorProps, ref: React.Ref ) : (
- handleRemove(files[0].id)} getFileIcon={getFileIcon} /> + handleRemove(files[0].id)} getFileIcon={getFileIcon} />
) )} diff --git a/fields/core/image/edit-component.tsx b/fields/core/image/edit-component.tsx index 84245cd5b..90de7024b 100644 --- a/fields/core/image/edit-component.tsx +++ b/fields/core/image/edit-component.tsx @@ -47,11 +47,17 @@ type FieldOptions = { rename?: boolean | "safe" | "random"; }; -const ImageTeaser = ({ file, config, onRemove }: { +const ImageTeaser = ({ file, config, mediaInput, onRemove }: { file: string; config: Pick; + mediaInput?: string; onRemove?: () => void; }) => { + const normalizedFile = file.replace(/^\.\//, '').replace(/^\//, ''); + const githubPath = mediaInput && !file.startsWith(mediaInput) && !file.startsWith('http') + ? `${mediaInput}/${normalizedFile}` + : file; + return (
@@ -59,7 +65,7 @@ const ImageTeaser = ({ file, config, onRemove }: {
); }; @@ -300,6 +307,7 @@ const EditComponent = forwardRef((props: EditorProps, ref: React.Ref handleRemove(file.id)} readonly={isReadonly} /> @@ -312,7 +320,7 @@ const EditComponent = forwardRef((props: EditorProps, ref: React.Ref - handleRemove(files[0].id)} /> + handleRemove(files[0].id)} /> ) )} diff --git a/lib/config.ts b/lib/config.ts index 222bca1d4..5e400767d 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -240,6 +240,20 @@ const normalizeConfig = (configObject: any) => { delete configObjectCopy.navigation; } + if (Array.isArray(configObjectCopy.media) && Array.isArray(configObjectCopy.content)) { + configObjectCopy.media = configObjectCopy.media.map((mediaConfig: any) => { + if (mediaConfig.input == null || mediaConfig.input === "") { + const matchingContent = configObjectCopy.content.find( + (contentItem: any) => contentItem.name === mediaConfig.name + ); + if (matchingContent?.path) { + mediaConfig.input = matchingContent.path.replace(/^\/|\/$/g, ""); + } + } + return mediaConfig; + }); + } + return configObjectCopy; };