Skip to content
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

Relative require from frontmatter #539

Closed
chrisdmacrae opened this issue Nov 6, 2016 · 3 comments
Closed

Relative require from frontmatter #539

chrisdmacrae opened this issue Nov 6, 2016 · 3 comments

Comments

@chrisdmacrae
Copy link

Including images in the markdown automatically resolves the images in the rendered component. However, including an image in the frontmatter simply passes the string to the template, page, component, etc.

I am using a component to render a list of pages, and I want an image stored relative to the md file that is specified in the frontmatter to be rendered by the component without having to hardcode the path resolving logic into the component (trying to keep it DRY).

Is there a good way of resolving the relative filepath to a rendered page so that I can require the image in the development bundle?

@KyleAMathews
Copy link
Contributor

The very quick answer is to create a context module with all your images in them and then in your md wrapper reference the filepath to pull in the image path.

https://webpack.github.io/docs/context.html

I might add this to the blog starter soon as it's a pretty common request.

I'll add an actual code sample when I have time or just add it to the blog starter.

@jbolda
Copy link
Contributor

jbolda commented Jun 3, 2017

This should be covered in 1.0 I would think. Closing unless you have anything else.

@jbolda jbolda closed this as completed Jun 3, 2017
@anandrikka
Copy link

@chrisdmacrae Hi, I'm also facing similar issue. Did you resolved it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants