-
Notifications
You must be signed in to change notification settings - Fork 198
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
Support relative imports of MDX assets #266
Comments
@gergelypap I had originally requested the config function in the related issue so folks could config the Considering it more, I'd actually consider the current behavior of 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. |
I went ahead and submitted the PR — I figure we can discuss whether it's the right approach there. #270 |
@gergelypap #270 was merged. Perhaps you can test it out and see if it satisfies your issue? |
This should be addressed with the |
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.
Example file structure:
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:
(Image loading is discussed in #11 though.)
UPDATE:
Upon investigating, I found that the
cwd
given tomdx-bundler
is the same ascontentDirPath
. However, if the MDX file is deeply nested, resolving images and components in the same directory will not work. For example ifcontentDirPath
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
![](./image.jpg)
orimport Component from './Component
, those files will try to be resolved from/content
, and not/content/some-subdir/some-post
where they actually are.https://github.com/contentlayerdev/contentlayer/blob/main/packages/%40contentlayer/core/src/markdown/mdx.ts#L45 -> should really be:
cwd: path.join(cwd, rawDocumentData.flattenedPath)
.This simple change solved this issue for me. I will make more tests and perhaps submit a PR on this.
The text was updated successfully, but these errors were encountered: