ivarptr / yu-writer.site

A feature-rich, efficient text editor - Web Site
Apache License 2.0
1.2k stars 77 forks source link

图片路径问题 #579

Open liphy opened 4 years ago

liphy commented 4 years ago

Platform/操作系统类型 Windows

OS version/操作系统版本 Windows 10

Application version/应用程序的版本号 0.5.3

Describe the bug/错误描述 导入 hexo 博客,并且修改了「yulib.config」: "staticResourcePath": "source/images" 图片在source/images,md 文件在 source/_post 插入图片是这样:![11](11.jpg) 但是这样的路径在其他工具(比如 typora)里打开就不能正常显示。 如果格式是这样就可以在其他你工具正常显示:![11](../images/11.jpg)

不知道这个问题怎么更好地解决?怎么设置才能实现我要的效果?谢谢。

hemashushu commented 4 years ago

@liphy 根据 hexo 文档的示例,默认图片放在 source/images 文件夹里,然后使用绝对路径引用图片,如 ![](/images/hello.jpg)

因为 hexo 生成时实际上是直接把 source 文件夹的内容(以下划线开头的文件夹除外)直接复制到输出目录 public (这个目录将会作为网站的根目录),而文章则会放进例如 /public/2019/12/20/hello-world/index.html 这样的位置,所以引用资源时使用绝对路径比较方便。

因为 hexo 的直接复制 source 文件夹资源的这种策略,yulib.config 当中的 "staticResourcePath" 设置值应该为 "source",这样 Yu Writer 在预览时就知道 /images/hello.jpg 指向当前库的 /source/images/hello.jpg

至于其他 markdown 工具,除非专门适配了 hexo 的这样的规则,或者像 Yu Writer 这样可以设置资源映射路径,否则图片是没办法在预览时显示的。