You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a really common requirement to have subdirectories for each and every MDX content, where different assets, such as images and components can be coupled.
It is possible to configure contentlayer to load the MDX files in this manner, however it is not currently possible to allow for relative imports of assets, such that:
---title: My post---importComponentfrom'./Component';
<Component />

Upon investigating, I found that the cwd given to mdx-bundler is the same as contentDirPath. However, if the MDX file is deeply nested, resolving images and components in the same directory will not work. For example if contentDirPath is /content, but the MDX file is under /content/some-subdir/some-post/index.mdx, any references in the MDX file will be looked in /content.
More precisely: if the MDX file references  or import Component from './Component, those files will try to be resolved from /content, and not /content/some-subdir/some-post where they actually are.
@gergelypap I had originally requested the config function in the related issue so folks could config the cwd like you're describing, but could also use the single fixed cwd as contentlayer does currently.
Considering it more, I'd actually consider the current behavior of contentlayer a bug, since it renders most md / mdx preview tools broken w/r/t image previews of markdown images using relative paths.
@schickling If you're willing to look at a PR using this approach I can finish it up with tests and submit. This would effectively close out #8 and this issue.
Activity
mshick commentedon Jul 15, 2022
@gergelypap I had originally requested the config function in the related issue so folks could config the
cwdlike you're describing, but could also use the single fixedcwdascontentlayerdoes currently.Considering it more, I'd actually consider the current behavior of
contentlayera bug, since it renders mostmd/mdxpreview tools broken w/r/t image previews of markdown images using relative paths.I've forked the repo and have the changes in place, minus tests. https://github.com/mshick/contentlayer/blob/main/packages/%40contentlayer/core/src/markdown/mdx.ts#L34-L40
@schickling If you're willing to look at a PR using this approach I can finish it up with tests and submit. This would effectively close out #8 and this issue.
mshick commentedon Jul 15, 2022
I went ahead and submitted the PR — I figure we can discuss whether it's the right approach there. #270
mshick commentedon Aug 2, 2022
@gergelypap #270 was merged. Perhaps you can test it out and see if it satisfies your issue?
schickling commentedon Aug 5, 2022
This should be addressed with the
0.2.7release. 🎉