Search code examples
gatsbyasciidocasciidoctor

How to get image file from local directory by gatsby-transformer-asciidoc?


I use gatsby-transformer-asciidoc and write image::<some-name>[] in .adoc. But I haven't could get images.

Dirctory structure

---images
 |  |-cheetah.png
 |-posts
 |  |-test.adoc
 |-src
 |-gatsby-config.js
 |-gatsby-node.js
 :

gatsby-config.js plugin

plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      attributes: {
        imagesdir: `/images`,
      },
    },
  },
]

test.adoc

 :
image::cheetah.png[]
 :

But I haven't get the image.

And I test an another plugin strucure.

gatsby-config.js

plugins: [
  {
    resolve: `gatsby-transformer-asciidoc`,
    options: {
      attributes: {
        imagesdir: `${__dirname}/images`,
      },
    },
  },
]

But I could not.

Please save me!


Solution

  • Here's one solution, maybe not the better one but it works for me.

    You can put your images in a static/images folder at the root of your project, that way, you can use the default imagesdir attribute and it will work.

    Meaning your directory structure would be

     |-static
     |  |-images
     |    |-cheetah.png
     |-posts
     |  |-test.adoc
     |-src
     |-gatsby-config.js
     |-gatsby-node.js
     :
    

    and your config

    plugins: [
      {
        resolve: `gatsby-transformer-asciidoc`,
        options: {
          attributes: {},
        },
      },
    ]