From 01ef5543ff46c85feaf07e76e03398db7718a0da Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sat, 17 May 2025 09:23:09 +0800 Subject: perf: remove unnecessary fancybox helper script Former-commit-id: 1df5202592eb9ea3d46bc347511c1e68ae5bbeeb --- assets/js/fancybox.js | 39 --------------------------------------- layouts/partials/scripts.html | 5 +---- 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 assets/js/fancybox.js diff --git a/assets/js/fancybox.js b/assets/js/fancybox.js deleted file mode 100644 index 15b70e48..00000000 --- a/assets/js/fancybox.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * fancybox.js - * - initialize fancybox library - * - automatically wrap images - */ - -document.addEventListener("DOMContentLoaded", function () { - document - .querySelectorAll(".markdown-body img:not(figure img, .no-fancybox)") - .forEach((img) => { - if (img.closest("figure")) return; // 跳过已经在
内的 - - let src = img.getAttribute("src"); - let alt = img.getAttribute("alt") || ""; // 获取 alt 作为 title - - // 创建 标签包裹 - let link = document.createElement("a"); - link.setAttribute("href", src); - link.setAttribute("data-fancybox", "gallery"); // Fancybox 组 - link.setAttribute("data-caption", alt); // 设置 title - link.setAttribute("aria-label", alt); // 辅助功能优化 - - // 创建
并添加

- let figcaption = document.createElement("figcaption"); - let captionTitle = document.createElement("h4"); - captionTitle.textContent = alt; - figcaption.appendChild(captionTitle); - - // 创建
并包裹 +
- let figure = document.createElement("figure"); - figure.appendChild(link); - figure.appendChild(figcaption); - - // 替换原始 img - img.parentNode.insertBefore(figure, img); - link.appendChild(img); // 将 img 插入 - }); -}); -Fancybox.bind("[data-fancybox]"); diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index e523c046..e7f1c454 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -10,10 +10,7 @@ {{- if or (in .Section "posts") (in .Section "cards") (in .Section "library") (eq .Type "single") }} - {{- $fancybox := resources.Get "js/fancybox.js" | minify }} - {{- if $fancybox }} - - {{- end }} + {{- end }}