Skip to content

Add colocated media paths handling#381

Open
Spr-Aachen wants to merge 2 commits into
hunvreus:mainfrom
Spr-Aachen:dev
Open

Add colocated media paths handling#381
Spr-Aachen wants to merge 2 commits into
hunvreus:mainfrom
Spr-Aachen:dev

Conversation

@Spr-Aachen

Copy link
Copy Markdown

Issue

This is how my config looks like

media:
  - name: posts
    input: src/content/posts
    output: /src/content/posts

content:
  - name: posts
    path: src/content/posts
    fields:
      - { name: cover, type: image, options: {media: posts} }

The media files in my project stored in the same folder as the markdown content, which is a common pattern in Astro.
However, when I write cover: "./cover.jpg" in frontmatter (relative to the markdown file), the View on GitHub link in the editor incorrectly points to xxx/blob/main/cover.jpg instead of xxx/blob/main/src/content/posts/guide/cover.jpg.

Solution

Add mediaInput prop to FileTeaser and ImageTeaser components to handle relative media paths properly.
Comparing to the previous PR, this solution comes with minus changes to the code files.

I understand the documentation recommends to use a central folder, but many users prefer colocated media and it has been proved to work with Decap CMS. So I still hope this could be supported.

Spr-Aachen and others added 2 commits April 1, 2026 21:42
Modify lib/config.ts to automatically fill media.input from the corresponding content.path

---------

Co-authored-by: Foxie <118339251+Foxie-404@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

2 participants