keystatic icon indicating copy to clipboard operation
keystatic copied to clipboard

Feature Request: Change default save path of uploaded image in `fields.markdoc()` relative to entry

Open tresorama opened this issue 1 year ago • 1 comments

With this keystatic config

// in ./keystatic.config.ts

import { config, fields, collection } from '@keystatic/core';

export default config({
  storage: {
    kind: 'local',
  },
  collections: {
    post: collection({
      label: 'post',
      path: 'src/content/post/**/',
      schema: {
        //...
        content: fields.markdoc({
          label: 'Content',
          description: 'The content of the post',
        }),
      },
    }),
  },
});

Each new entry (post) is saved in src/content/post/<POST_SLUG>/index.mdoc. So far so good...

The content field has a Markdown editor UI where we can upload images, and these images will be saved to
src/content/post/<POST_SLUG>/content/<IMAGE.JPG>.

I need that instaed images can be saved in the root directory of the entry, not inside content subdiretory.
Like this src/content/post/<POST_SLUG>/<IMAGE.JPG>.

What I tried

  1. Adding options to fields.markdoc
content: fields.markdoc({
  label: 'Content',
  description: 'The content of the post',
  options: {
    image: {
     
     // This path is relative to root project, not entry directory
     // So it cannot do what i need
     directory: ".", 
      
      // This function receive only the filename of the image, not the save path.
      // i.e.
      // If image is saved in `content/<IMAGE.JPG>` this function `originalFilename` is `<IMAGE.JPG`>
      // So it cannot do what i need
      transformFilename(originalFilename) {
        return originalFilename;
      },
    }
  }
}),

What i'm requesting

Ability to define path where an image will be saved , relative to the entry directory. Or it is already possible ?

tresorama avatar Oct 31 '24 14:10 tresorama

+1 this would be very nice to have :))

levischouten avatar Nov 03 '24 01:11 levischouten