Thinkmill / keystatic

First class CMS experience, TypeScript API, Markdown & YAML/JSON based, no DB
https://keystatic.com
MIT License
1.12k stars 76 forks source link

Incorrect path to image in mdoc file #560

Open tiwka19 opened 1 year ago

tiwka19 commented 1 year ago

If I want to add images inside a post, the path to the image = file name. However, all new images added to the post are in the path post slug folder/content, so I get the "Could not resolve image" error

simonswiss commented 1 year ago

Hey! This is something you can improve with the directory and publicPath options on the image fields:

https://keystatic.com/docs/fields/image#storage-options

Example:

avatar: fields.image({
  label: 'Avatar',
  description: 'The avatar for this user',
  // This will output the images in the "public" directory
  directory: 'public/images/avatars',
  publicPath: '/images/avatars/'
})

With the code above, the file path output in your posts would be /images/avatars/{post_slug}/avatar.jpeg

Hope it helps!

tiwka19 commented 1 year ago

Hey! This is something you can improve with the directory and publicPath options on the image fields:

https://keystatic.com/docs/fields/image#storage-options

Example:

avatar: fields.image({
  label: 'Avatar',
  description: 'The avatar for this user',
  // This will output the images in the "public" directory
  directory: 'public/images/avatars',
  publicPath: '/images/avatars/'
})

With the code above, the file path output in your posts would be /images/avatars/{post_slug}/avatar.jpeg

Hope it helps!

No, I mean if you attach additional images in the content field

florian-lefebvre commented 1 year ago

It can also be customized like so:

    document: fields.document({
      label: 'Document',
      images: {
        directory: "...",
        publicPath: "...",
      },
    }),
devnomic commented 9 months ago

@florian-lefebvre Thanks, it works. This need to be set as default when creating new project via cli.

ikx94 commented 1 month ago

Contributor

Document is deprecated and "markdoc" field is recommended. But markdoc doesn't support setting image upload directory, so it's not really usable at the moment.

stefanprobst commented 1 month ago

@ikx94 the markdoc/mdx field does allow setting image options:

content: fields.mdx({
  label: "Content",
  options: {
    image: {
      publicPath: "/assets/",
      directory: "public/assets/",
    },
  },
});
ikx94 commented 1 month ago

@ikx94 the markdoc/mdx field does allow setting image options:

content: fields.mdx({
  label: "Content",
  options: {
    image: {
      publicPath: "/assets/",
      directory: "public/assets/",
    },
  },
});

Cool, good to know. Thank you.

One question, is there any way to adjust image sizing when added through editor?

stefanprobst commented 1 month ago

is there any way to adjust image sizing when added through editor?

i don't think this is possible currently. you could open a new issue with a feature request?