👉 Note: 11ty & Nunjucks.

What we want?

Tools

You will need to install the following tools. Depending on your working style, you can choose one or both of them.

Setting up your project structure

Below is an example of the folder structure on my website. Read this section to understand why this structure is important for all parts work together.

dinhanhthi.com
|- _built/ # The output folder (11ty renders markdown files to this)
|- .eleventy.js
|- notes/
  |- blog/ # contains all markdown files
     |- 2022-06-25-name-of-post.md
  |- img_post/ # contains all images
     |- 2022-06-25-name-of-post/ # the same name as markdown file
        |- figure-1.png
        |- figure-2.png

Some remarks,

Setting up .eleventy

You need to make 11ty recognize "blog" and "img_post".

module.exports = function (eleventyConfig) {
  // For images
  eleventyConfig.addPassthroughCopy({ "notes/img_post": "img_post" });

  return {
		// other settings
    dir: {
      input: ".",
      output: "_built",
    },
  };
}

Setting up VSCode

Make sure you have the Markdown All in One and Markdown Image extensions already installed.

Go to Makdown Image settings: