2.0.3的一个Bug
Closed this issue · 1 comments
woshiamiaojiang commented
New in 2.0.3: featured_image can now be an URL starts with http:// or https://.
尝试在featured_image设置图片,发现图片如果是http或者https链接的,文章详情里可以正常显示。但是首页的文章列表中图片显示失败,原因是图片路径被解析成了/年/月/日/文章名+Url的形式。应该是详情里兼容了,首页文章列表的图片没有做兼容处理。
justzerock commented
刚使用这个主题,也发现了这个问题,确实文章模版post.ejs
里面有个getFeaturedImage()
方法处理了http与https链接,但是首页的index.ejs
没有处理
我就直接把文章页的方法小改下拿到首页用了
index.ejs 添加方法
<%
function getFeaturedImage(item) {
var featuredImage = item.featured_image;
if (!featuredImage) return '';
if (featuredImage.startsWith("http://") || featuredImage.startsWith("https://")) return featuredImage;
return config.root + item.path + featuredImage;
}
%>
index.ejs 图片部分修改后:
<% if(item.featured_image){ %>
<div class="post-item-image-wrapper">
<div class="post-item-image"
style="background-image: url('<%= getFeaturedImage(item) %>')"></div>
</div>
<% } %>