I am creating blog with Jekyll and for the sake of organization I have decided to put the images under the folder: "assets/img/[post name]/". The folders look like this:
.
├── assets
│ ├── css
│ │ ├── BMFW.css
│ │ └── vs.css
│ └── img
│ └── 2021-05-23-Blog-presentation
│ └── test.jpg <--
├── _config.yml
├── Gemfile
├── Gemfile.lock
├── index.html
├── _layouts
│ ├── layout.html
│ └── post.html
├── _posts
│ └── 2021-05-23-Blog-presentation.md
├── README.md
└── script
└── cibuild
Seems that the page.name variable for some reason does not exist (I have checked it with {{page | inspect}}
) so I use this line to get the name of the post:
{{ page.path | replace: ".md","" | split: "/" | slice: -1 | }}
That means that if I want to display an image called test.jpg
I would write:

The only thing that changes from one image to another is the name of the image. So my question is: is there a way to set a base path, in my case {{ site.baseurl }}/assets/img/{{ page.path | replace: ".md","" | split: "/" | slice: -1 | }}/
, so I don't have to write the full path over and over again?
The ideal solution would be to just have to write 
or similar.
EDIT 1:
Just in case it is useful for anybody, what I am doing now is to put this line at the beginning of each blog entry:
{% assign media = site.baseurl | append: "assets/media/" | append: page.path | replace: ".md","" | replace: "_posts/","" %}
So then I can insert images just writing:

It is not a solution because I still have to put that line at the beginning of every post but is better than before.
EDIT 2:
I have looked to make some custom pluggin in Jekyll but I haven't found a way to get access to the page properties.
Another option was to create a custom tag that inserted the liquid code: {{site.baseurl | append: "assets/media/" | append: page.path | replace: ".md","" | replace: "_posts/","" }}
. The problem with this one is that once the custom tag has ben executed jekyll continues and does not execute the newly inserted liquid code.