Thinkmill / Thinkmill/keystatic

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

Open
#1,344 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
2.4k
Forks
159
Avg merge
21h 41m
Merged PRs (30d)
2

Description

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 ?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the keystatic.config.ts example and trace the fields.markdoc image options to where uploaded files are assigned their directory. Check how the entry path and content subdirectory are determined. Done means supporting an entry-relative image path that saves files in src/content/post/<POST_SLUG>/ rather than its content subdirectory, with coverage for the configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
content
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.