Open ChanryLimmy opened 2 years ago
This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Unstale
Same request here
With the post_asset_folder
option in hexo, it seems natural to store those images inside the post_asset_folder
, and just use the relative path when writing, which offers a much better markdown preview experience
@ChanryLimmy code doesn't seem to work for me, I modified it a little, and the following code works fine for me. Others can refer to it.
"hexo-renderer-marked@^5.0.0",
if (!/^(#|\/\/|http(s)?:)/.test(href) && !relative_link && prependRoot) {
if (!href.startsWith('/') && !href.startsWith('\\') && postPath) {
const PostAsset = hexo.model('PostAsset');
// findById requires forward slash
// ***************** Add the following code *******************
const fixPostPath = join(postPath, '../');
const asset = PostAsset.findById(join(fixPostPath, href.replace(/\\/g, '/')));
// const asset = PostAsset.findById(join(postPath, href.replace(/\\/g, '/')));
// ************************** End *****************************
// asset.path is backward slash in Windows
if (asset) href = asset.path.replace(/\\/g, '/');
}
href = url_for.call(hexo, href);
}
@SukkaW This issue has been put on hold for a long time, and #225 have not been closed yet. Is there any suggestion for us to end this problem?
I have written a plugin to solve this, hexo-relative-link
I made a pr #271 and hopefully this solves the issue. More tests are welcome!
Background
u know when we use other md editor write a post, the img with relative path is like this
![makabaka](postname/1.jpg)
, but here in hexo-render-marked i must use![makabaka](1.jpg)
if the config like this:it means there must be one side between md editor & hexo can't see the pic.
My solution
i opened
node_modules -> hexo-render-marked -> lib -> render.js
and change the image part (between the *** lines):it works. so the following is my suggests about this product experience
Feature Request
tks a lot!