Is your feature request related to a problem? Please describe.
I like to store captions with images and videos. Then, I use media snippets to insert a custom React component and set the caption value accordingly using placeholders.
Videos, however, do not have a caption field.
Here are a couple use cases where custom metadata is desirable:
I have an image that displays an art piece created by another person. In this image's metadata, I'd like to store the name of this person and a link to their webpage. Then, wherever I reuse this image, I can insert this data into the markup of my custom snippet via placeholders as a form of attribution.
Store a small generated Base64 encoded image string that can be used to display in-place of an image while it is loading.
Describe the solution you'd like
Ability to define fields on media files so that custom metadata could be attached.
This could be implemented similar to content types. where we could define our own media content types (e.g., image, generalVideo, courseVideo, textFile, etc.) and attach custom metadata to each type.
For the "image's author name and link" metadata example above, this could be a key-value pair field, or a contentRelationship field, where the metadata would be linked to a data file.
Describe alternatives you've considered
I considered storing caption text in the title field of a video but it feels hacky and would not be helpful if additional metadata needed to be attached.
**Is your feature request related to a problem? Please describe.**
I like to store captions with images and videos. Then, I use media snippets to insert a custom React component and set the caption value accordingly using placeholders.
Videos, however, do not have a caption field.

Here are a couple use cases where custom metadata is desirable:
- I have an image that displays an art piece created by another person. In this image's metadata, I'd like to store the name of this person and a link to their webpage. Then, wherever I reuse this image, I can insert this data into the markup of my custom snippet via placeholders as a form of attribution.
- Store a small generated Base64 encoded image string that can be used to display in-place of an image while it is loading.
**Describe the solution you'd like**
Ability to define [fields](https://frontmatter.codes/docs/content-creation/fields) on media files so that custom metadata could be attached.
This could be implemented similar to [content types](https://frontmatter.codes/docs/content-creation/content-types). where we could define our own media content types (e.g., image, generalVideo, courseVideo, textFile, etc.) and attach custom metadata to each type.
For the "image's author name and link" metadata example above, this could be a key-value pair field, or a contentRelationship field, where the metadata would be linked to a [data file](https://frontmatter.codes/docs/datafiles-view).
**Describe alternatives you've considered**
I considered storing caption text in the title field of a video but it feels hacky and would not be helpful if additional metadata needed to be attached.
<!-- github-sync-id:1899521542 -->
How would you like to set the content type for a media file? For instance, you have two images, one of the author, and one just an image for adding to your article. Both of these images are PNGs. How would you see the CMS selecting the right content type, or would it be an option to allow you to pick the content type from a dropdown first?
Thanks @polynook; this is a great idea.
How would you like to set the content type for a media file? For instance, you have two images, one of the author, and one just an image for adding to your article. Both of these images are PNGs. How would you see the CMS selecting the right content type, or would it be an option to allow you to pick the content type from a dropdown first?
<!-- github-comment-id:1723016476 -->
As this is a more significant task, I have created another task in which I have handled to show the caption field for video files: https://github.com/estruyf/vscode-front-matter/issues/669
<!-- github-comment-id:1723045533 -->
All images, videos (and other media files supported by Front Matter) uploaded to Front Matter would automatically have assigned a default media content type defined internally in Front Matter. Example for image:
{"name":"Image","fields":[{"title":"Title","name":"title","type":"string","required":false},{"title":"Caption","name":"caption","type":"string","required":false},{"title":"Alt text","name":"altText","type":"string","required":false},],// A regex pattern or some other algorithm for Front Matter to recognize which media fiels are images.
"fileType":"/(.*\.(?:png|svg|webp|avif))/",}
Optionally, if a user desires, they could override this content type for any image.
Custom media content type defintion in frontmatter.json:
"frontMatter.taxonomy.mediaContentTypes":[{"name":"Image","fields":[{"title":"Title","name":"title","type":"string","required":false},{"title":"Caption","name":"caption","type":"string","required":false},{"title":"Alt text","name":"altText","type":"string","required":true},{"title":"Blurred Placeholder","name":"blurredPlaceholder","type":"string",// i.e. the value generated and set by a media script and should not be editable by hand by a user in the UI
"editableInUI":false},// A new field that would allow defining key-value pairs
{"title":"Authors","name":"authors","type":"map","key":{"title":"Name","name":"name","type":"string","required":true},"value":{"title":"URL","name":"url","type":"string","required":true},},{"title":"Tags","name":"tags","type":"tags"},],// Define this media content type only for PNG images. This means that inside Media view, only PNG files would be able to be converted to this media type.
"fileType":"/(.*\.(?:png))/",}]
Then, in the Media view, we could select one or more images and assign a custom media content type to them. Then, when editing their metadata, we would see our own custom fields there instead of the default ones.
Then, I can use a media snippet to insert an image component into an MDX file:
"frontMatter.content.snippets":{"Image":{"description":"Custom Image","body":["<Figure>",// &mediaUrl would come from internally defined content type and would not be overridable by a custom media content type
" <Image src=\"[[&mediaUrl]]\" alt=\"[[altText]]\" placeholder=\"[[placeholder]]\" />"," <Caption>"," [[caption]]",// authors.key and authors.value would be values from the selected key-value pair inside the UI when adding media snippet to content.
" <Author name=\"[[authors.key]]\" url=\"[[authors.value]]\" />"" </Caption>","</Figure>"],"isMediaSnippet":true}}
In this implementation, a user could choose manually which images (or other media files) should belong to a specific media content type.
When inserting this image into content, the user wouldn't be able to choose which media content type they wish to insert, because otherwise, stored metadata associated with the previous media content type would be lost.
The workflow would essentially be this:
User needs to attach custom metadata to a media file that they store inside Front Matter public media folder (image, video, text file, .ts script, etc.).
User defines custom media type with relevant fields for required metadata.
In Media viewer, user selects the files they wish to have this custom metadata. Not every image file may need to have custom metadata, so the user selects only a few images they want to have this custom metadata and assigns them to use their custom defined media content type. Not selected image files are unaffected and still remain using the default media type.
(optionally, there could be a setting when defined a custom media content type to automatically assign a media file to a specific media content type on upload if the filename matches a certain regex pattern (e.g., the file is present in a certain folder, has a certain extension, etc.))
User clicks on the pencil icon on the selected image to edit its metadata and sees their custom defined fields.
This is how I envision this:
All images, videos (and other media files supported by Front Matter) uploaded to Front Matter would automatically have assigned a default `media content type` defined internally in Front Matter. Example for image:
```json
{
"name": "Image",
"fields": [
{
"title": "Title",
"name": "title",
"type": "string",
"required": false
},
{
"title": "Caption",
"name": "caption",
"type": "string",
"required": false
},
{
"title": "Alt text",
"name": "altText",
"type": "string",
"required": false
},
],
// A regex pattern or some other algorithm for Front Matter to recognize which media fiels are images.
"fileType": "/(.*\.(?:png|svg|webp|avif))/",
}
```
Optionally, if a user desires, they could override this content type for any image.
Custom `media content type` defintion in `frontmatter.json`:
```json
"frontMatter.taxonomy.mediaContentTypes": [
{
"name": "Image",
"fields": [
{
"title": "Title",
"name": "title",
"type": "string",
"required": false
},
{
"title": "Caption",
"name": "caption",
"type": "string",
"required": false
},
{
"title": "Alt text",
"name": "altText",
"type": "string",
"required": true
},
{
"title": "Blurred Placeholder",
"name": "blurredPlaceholder",
"type": "string",
// i.e. the value generated and set by a media script and should not be editable by hand by a user in the UI
"editableInUI": false
},
// A new field that would allow defining key-value pairs
{
"title": "Authors",
"name": "authors",
"type": "map",
"key": {
"title": "Name",
"name": "name",
"type": "string",
"required": true
},
"value": {
"title": "URL",
"name": "url",
"type": "string",
"required": true
},
},
{
"title": "Tags",
"name": "tags",
"type": "tags"
},
],
// Define this media content type only for PNG images. This means that inside Media view, only PNG files would be able to be converted to this media type.
"fileType": "/(.*\.(?:png))/",
}
]
```
Then, in the Media view, we could select one or more images and assign a custom `media content type` to them. Then, when editing their metadata, we would see our own custom fields there instead of the default ones.
Then, I can use a media snippet to insert an image component into an MDX file:
```json
"frontMatter.content.snippets": {
"Image": {
"description": "Custom Image",
"body": [
"<Figure>",
// &mediaUrl would come from internally defined content type and would not be overridable by a custom media content type
" <Image src=\"[[&mediaUrl]]\" alt=\"[[altText]]\" placeholder=\"[[placeholder]]\" />",
" <Caption>",
" [[caption]]",
// authors.key and authors.value would be values from the selected key-value pair inside the UI when adding media snippet to content.
" <Author name=\"[[authors.key]]\" url=\"[[authors.value]]\" />"
" </Caption>",
"</Figure>"
],
"isMediaSnippet": true
}
}
```
In this implementation, a user could choose manually which images (or other media files) should belong to a specific `media content type`.
When inserting this image into content, the user wouldn't be able to choose which `media content type` they wish to insert, because otherwise, stored metadata associated with the previous `media content type` would be lost.
The workflow would essentially be this:
1. User needs to attach custom metadata to a media file that they store inside Front Matter public media folder (image, video, text file, `.ts` script, etc.).
2. User defines `custom media type` with relevant fields for required metadata.
3. In Media viewer, user selects the files they wish to have this custom metadata. Not every image file may need to have custom metadata, so the user selects only a few images they want to have this custom metadata and assigns them to use their custom defined `media content type`. Not selected image files are unaffected and still remain using the default media type.
- (optionally, there could be a setting when defined a custom `media content type` to automatically assign a media file to a specific `media content type` on upload if the filename matches a certain regex pattern (e.g., the file is present in a certain folder, has a certain extension, etc.))
5. User clicks on the pencil icon on the selected image to edit its metadata and sees their custom defined fields.
<!-- github-comment-id:1723107188 -->
WIP
- [x] Create `frontMatter.media.contentTypes` setting
- [x] Show the media files according to the content type
- [x] Show the input form for the media metadata based on the content type
- [x] Allow snippets to use the new fields
- [x] Allow to extend the configuration with the new setting
- [x] Allow to spit the configuration (check if correctly merged)
- [x] Update the documentation
- [x] Generate schema on documentation
- [x] Support more field types (start with string)
```json
{
"frontMatter.media.contentTypes": [
{
"name": "default",
"fileTypes": null,
"fields": [
{
"title": "Title",
"name": "title",
"type": "string"
},
{
"title": "Caption",
"name": "caption",
"type": "string"
},
{
"title": "Alt text",
"name": "alt",
"type": "string"
}
]
},
{
"name": "jpg",
"fileTypes": [
"jpg"
],
"fields": [
{
"title": "Title",
"name": "title",
"type": "string"
},
{
"title": "Caption",
"name": "caption",
"type": "string"
},
{
"title": "Author",
"name": "author",
"type": "string",
"single": true
}
]
}
]
}
```
<!-- github-comment-id:1931783458 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Is your feature request related to a problem? Please describe.
I like to store captions with images and videos. Then, I use media snippets to insert a custom React component and set the caption value accordingly using placeholders.
Videos, however, do not have a caption field.
Here are a couple use cases where custom metadata is desirable:
Describe the solution you'd like
Ability to define fields on media files so that custom metadata could be attached.
This could be implemented similar to content types. where we could define our own media content types (e.g., image, generalVideo, courseVideo, textFile, etc.) and attach custom metadata to each type.
For the "image's author name and link" metadata example above, this could be a key-value pair field, or a contentRelationship field, where the metadata would be linked to a data file.
Describe alternatives you've considered
I considered storing caption text in the title field of a video but it feels hacky and would not be helpful if additional metadata needed to be attached.
Thanks @polynook; this is a great idea.
How would you like to set the content type for a media file? For instance, you have two images, one of the author, and one just an image for adding to your article. Both of these images are PNGs. How would you see the CMS selecting the right content type, or would it be an option to allow you to pick the content type from a dropdown first?
As this is a more significant task, I have created another task in which I have handled to show the caption field for video files: https://github.com/estruyf/vscode-front-matter/issues/669
This is how I envision this:
All images, videos (and other media files supported by Front Matter) uploaded to Front Matter would automatically have assigned a default
media content typedefined internally in Front Matter. Example for image:Optionally, if a user desires, they could override this content type for any image.
Custom
media content typedefintion infrontmatter.json:Then, in the Media view, we could select one or more images and assign a custom
media content typeto them. Then, when editing their metadata, we would see our own custom fields there instead of the default ones.Then, I can use a media snippet to insert an image component into an MDX file:
In this implementation, a user could choose manually which images (or other media files) should belong to a specific
media content type.When inserting this image into content, the user wouldn't be able to choose which
media content typethey wish to insert, because otherwise, stored metadata associated with the previousmedia content typewould be lost.The workflow would essentially be this:
.tsscript, etc.).custom media typewith relevant fields for required metadata.media content type. Not selected image files are unaffected and still remain using the default media type.media content typeto automatically assign a media file to a specificmedia content typeon upload if the filename matches a certain regex pattern (e.g., the file is present in a certain folder, has a certain extension, etc.))Thanks @polynook for your insights!
WIP
frontMatter.media.contentTypessettingDocumented: https://beta.frontmatter.codes/docs/media-view#metadata