Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用相对路径时遇到的两个问题 #114

Closed
Yesterday17 opened this issue May 19, 2020 · 3 comments
Closed

使用相对路径时遇到的两个问题 #114

Yesterday17 opened this issue May 19, 2020 · 3 comments
Assignees
Labels

Comments

@Yesterday17
Copy link

我目前的博客是同时解析两个域名的,所以很多东西(包括资源文件)都会使用相对路径以方便不同域名访问,如 /wp-contents/xxx。但是我发现现在相对路径下有两个问题:

灯箱无法正常使用

问题出在 post.js 的 338-339 行:

var imgHref = $(this).parent("a").attr('href').split('.')
imgHref.pop();

当使用相对路径时,imgHref 就会在 339 行 pop 之后变成 [],因此灯箱就不可用了。
我个人暂时的解决方案是 if (imgHref.length > 2) imgHref.pop();

无法正常显示文章卡片

问题出在 post.js 的 226 行,它使用了 url 来获取 Element,但 url 是从 HTML 中获得的绝对路径,而 187 行设置的却是 mdxposturl,也就是用户配置的路径,对我来说也就是相对路径,因此会出现这样的错误:

image

@yrccondor yrccondor self-assigned this May 19, 2020
@yrccondor yrccondor added the bug label May 19, 2020
@yrccondor
Copy link
Owner

我自己开发时由于使用的都是绝对路径,没有注意到😅
我大概会慢慢重写 js 了orz

这几天在考试,这个问题过几天修复。

@yrccondor
Copy link
Owner

其中第一个问题,这段代码的本意是移除地址末尾的拓展名以适应 WordPress 自动生成的多个分辨率的图像,应该与是否为绝对路径无关,你方便检查一下并你的图片具体路径是怎么样的吗?

@Yesterday17
Copy link
Author

hmm 玄学 现在找不到涉事文章了 暂时先不用管了吧(

顺带多嘴一句,split 那三行可以换成 imgHref.replace(/\.[^.]+$/, '-')(逃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants