question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative image paths

See original GitHub issue

Sorry but I’m completely confused by how Gridsome handles relative image paths.

Right now, the frontmatter in my markdown is image: /media/image.jpg, and the media directory exists at the root of my project.

<div v-for="{ node } in $static.allOrganization.edges" class="sponsor__item" :key="node.id">
  <g-image :src="node.logo" :alt="node.name" />
</div>

The expected values ends up in the resulting image tag, but the problem is that /media/image.jpg doesn’t exist.

How do I get Gridsome to point to this? Alternatively, can I get g-image to modify the the image path and point to the location instead?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
cco3commented, Jan 25, 2020

@hjvedvik Is there any way to specify images relative the src/ directory in the front matter? I was hoping image: ~/dir/image.jpg would work, but it doesn’t seem to.

3reactions
hjvedvikcommented, Aug 12, 2019

@freshyill When using absolute paths, Gridsome will look for a file located somewhere in the /static folder. So moving the /media folder to /static/media should make your images work. But keep in mind that images in the /static folder are not processed in any way, just copied to the /dist folder when building for production.

You can use relative paths like image: ./image.jpg to process them with the built-in image processor. The image path must be relative to the Markdown file referencing it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML File Paths - W3Schools
A relative file path points to a file relative to the current page. In the following example, the file path points to a...
Read more >
img tag not working with relative path in src - Stack Overflow
So when I have url like http://127.0.0.1:7777/www/ then all my relative urls working but then I use it as http://127.0.0.1:7777/www (no "/" at...
Read more >
Use Relative Paths for Linked Images - Access Image FAQ
Relative path vs. absolute path possible in storing pictures? db using photos - where to keep the photos. Relative Path does not work...
Read more >
HTML File Paths - Absolute and Relative File Paths - DataFlair
Learn file paths in HTML with types and examples - HTML Absolute path, relative paths-Same folder as current web-page file,Images in current folder,Folder ......
Read more >
KB405775: When an image is referenced using relative paths ...
A partial path is relative to the working directory of the user or application, so that a full absolute path does not need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found