From f88d83b0ad0153949093e4267b410f61845e5115 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 23 Jun 2026 15:45:30 +0800 Subject: [PATCH] feat(post-content): load lightbox.js and init gallery eval both post-content.js (copy) and lightbox.js (lightbox + lazy-load), then call __initLightbox over ['.post-content', '.entry-cover'] so both in-content images (gallery) and the cover (single) are wired up. --- src/components/post/post_content.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/post/post_content.rs b/src/components/post/post_content.rs index f19d4d8..e4cddfe 100644 --- a/src/components/post/post_content.rs +++ b/src/components/post/post_content.rs @@ -10,14 +10,17 @@ use dioxus::prelude::*; /// - `content_html`:服务端渲染的文章 HTML 字符串 /// /// 关键行为: -/// - 在 `target_arch = "wasm32"` 环境下执行 `post-content.js` 并调用初始化函数, -/// 用于处理代码块、图片点击等前端交互 +/// - 在 `target_arch = "wasm32"` 环境下执行 `post-content.js`(代码块复制)与 +/// `lightbox.js`(图片灯箱 + 懒加载),并调用各自的初始化函数。 #[component] pub fn PostContent(content_html: String) -> Element { #[cfg(target_arch = "wasm32")] use_effect(move || { let _ = js_sys::eval(include_str!("../../../public/js/post-content.js")); + let _ = js_sys::eval(include_str!("../../../public/js/lightbox.js")); let _ = js_sys::eval("window.__initPostContent('.post-content')"); + // 正文图组成图集;封面(.entry-cover)单张模式,由 PostCover 标记 data-single。 + let _ = js_sys::eval("window.__initLightbox(['.post-content', '.entry-cover'])"); }); rsx! {