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.

Resolve assets in markdown content

See original GitHub issue

I would like to know if it’s possible to have the webpack assets resolution inside of markdown content ? To display webpack handeled’s images.

Reproduction link: https://codesandbox.io/s/dawn-snowflake-fv7l4?file=/content/post.md

  1. I have an image in the assets folder
  2. I link the image in the md file ![](~/assets/photo.jpg) (or <img src="~/assets/photo.jpg"> in html) the same way I would have in a component template

I’m not interested in putting files in the static folder since there is no compression and no hash for cache-busting.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:52
  • Comments:98 (8 by maintainers)

github_iconTop GitHub Comments

50reactions
davydnorriscommented, Jul 19, 2020

Is it possible to store the images under the content directory itself instead of in the assets directory? Then you could create a structure like:

content/articles/my-new-article/index.md content/articles/my-new-article/img/pic1.jpg content/articles/my-new-article/img/pic2.jpg content/articles/my-new-article/img/pic3.jpg

which would keep all the content together.

34reactions
MuhaddiMucommented, Jul 28, 2020

@davydnorris suggestion was helpful to me

I created a global Image component to work around with that and stored my images inside the /content/blog/my-blog-slug/images/

<template>
  <img :src="imgSrc()" :alt="alt" />
</template>

<script>
export default {
  props: {
    src: {
      type: String,
      required: true
    },
    alt: {
      type: String,
      required: true
    }
  },
  methods: {
    imgSrc() {
      try {
        return require(`~/content${this.src}`)
      } catch (error) {
        return null
      }
    }
  }
}
</script>

Make sure to register this component globally. Inside components/global/Image.vue and set the components:true in nuxt.config.js

<image
          v-if="blog.Featured_Image"
          :src="blog.dir + '/images/' + blog.Featured_Image"
          :alt="blog.Title"
        >
</image>

Inside Markdown:

<image src="/blog/my-blog-slug/images/Scripts.png" alt="Scripts"></image>

I hope this will be helpful to someone. 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets - Docusaurus
Sometimes you want to link to assets (e.g. docx files, images...) directly from Markdown files, and it is convenient to co-locate the asset...
Read more >
How do I display local image in markdown? - Stack Overflow
The best solution is to provide a path relative to the folder where the md document is located. Probably a browser is in...
Read more >
Asset Folders - Hexo
Global Asset FolderAssets are non-post files in the source folder, ... Referencing images or other assets using normal markdown syntax and ...
Read more >
Working with Images in Markdown & MDX - Gatsby
... of markdown or MDX , insertion of images can enhance the content. ... as the markdown files, sourcing and resolving the images...
Read more >
Asset Handling - VuePress
Sometimes you may need to provide static assets that are not directly referenced in any of your Markdown or theme components (for example, ......
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 Hashnode Post

No results found