Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tresorama opened this issue Oct 31, 2024 · 1 comment

Comments

@tresorama
Copy link

tresorama commented Oct 31, 2024

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 ?

@levischouten
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants