[hexojs/hexo]{% asset_img plug [title] %} 的疑问

2023-12-20 830 views
1

开启 post_asset_folder: true
使用 hexo new testimg 新建文章
在自动建立的 testimg 目录里放了 test.jpg 图片文件

文章内容如下

{% asset_path test.jpg %}  
{% asset_img test.jpg [title] %}  
{% asset_link test.jpg [title] %}  

hexo s 情况下查看,发现链接为 http://localhost:4000/post/testimg.html/test.jpg
testimg.html 这个路径应该是不存在

在文章的三个标签后 加上空格,则页面有有几率能正确渲染(能正确访问这个不存在的路径)

使用 hexo g 命令 生成时,报错 FATAL ENOENT: no such file or directory, open 'I:\Portable\Code\blog\public\post\testimg.html\test.jpg' Error: ENOENT: no such file or directory, open 'I:\Portable\Code\blog\public\post\testimg.html\test.jpg' at Error (native)

回答

6

qq 20170324095648 qq 20170324095653 111

2

能否发下文章的markdown文件?

7

@NoahDragon 重现好像看运气,没有改动任何东西的情况下,刷新下会突然无法查看图片/突然可以看到图片

markdown里除了自己生成的一些时间标题信息外,只有

{% asset_path test.jpg %}
{% asset_img test.jpg [title] %}
{% asset_link test.jpg [title] %}

我这里关于这个情况的重现并不是100%的,在不改变文件的情况下,仅仅刷新网页都有时候结果不一样
另外有一点我很迷惑,我为什么生成的链接是 目录名+.html

比如我 hexo new test1 新建名字 test1.md 的文章
在开启 post_asset_folder: true 的情况下,生成的是 test1 这个文件夹, 而使用 {% asset_path test.jpg %} 返回的是 /post/test1.html/test.jpg (多了一个 .html)

但是在一些情况下,我访问 /post/test1.html/1.jpg 能够正常访问这个图片
在这种情况下,即使我手动建立 test1.html 文件夹,并且在里面放置 test.jpg 访问到的文件仍然是 test1 里的图片,而非真正放置在 /post/test1.html/1.jpg 的图片

如果有需要我可以将涉及到文件发到您的邮箱

3

我先照你的描述看下是否可以重现.

5

我的机子上显示正常,无法重现。可能跟文件夹名中有.html有关。能否贴下你的config.yml?

3

啊,这么一看我知道为什么了 我设置的标题是这样的 permalink: /post/:title.html

所以也就是这个是按照 :year/:month/:day/:title/ 这样的逻辑写的
(觉得这个逻辑怪怪的,如果自己修改了 permalink 就会出现这样很奇怪的现象)

感谢~

7

因为Hexo是将md文件生成一个index.html文件并放置到permalink的目录下,所以是无法也不需要添加后缀的。如果仍有问题可重开此issue。

7

您好,如果我想在一个新界面(hexo new page创建)的index.md使用{% asset_img example.jpg %}插入图片的话可以吗?可以的话example.jpg放在与index.md同层的index文件夹为什么图片不显示呢?