Skip to content

Commit

Permalink
fix: 修复图片alt为空时Fancybox caption输出undefined的问题 (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquausora authored Sep 9, 2024
1 parent 8d2394a commit faae66b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/tags/fancybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function buidImgFancybox(content, group) {
let imgList = html.match(/<img.*?>/g) || [];
imgList.forEach(item => {
const url = (item.match(/\ssrc=['"](.*?)['"]/) || [])[1];
const alt = (item.match(/\salt=['"](.*?)['"]/) || [])[1];
const alt = (item.match(/\salt=['"](.*?)['"]/) || [])[1] || '';
const newItem = item.replace('img', 'img fancybox itemprop="contentUrl"'); // 避免出现重复替换,打个标
const result = `<div class='fancybox'><a class='fancybox' itemscope itemtype="https://schema.org.cn/ImageObject" itemprop="url" href='${url}' data-fancybox='${group}' data-caption='${alt}'>${newItem}</a>${buidAlt(imageTags || alt)}</div>`;
html = html.replace(item, result.trim());
Expand Down

0 comments on commit faae66b

Please sign in to comment.