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.
This commit is contained in:
parent
bace31933f
commit
f88d83b0ad
@ -10,14 +10,17 @@ use dioxus::prelude::*;
|
|||||||
/// - `content_html`:服务端渲染的文章 HTML 字符串
|
/// - `content_html`:服务端渲染的文章 HTML 字符串
|
||||||
///
|
///
|
||||||
/// 关键行为:
|
/// 关键行为:
|
||||||
/// - 在 `target_arch = "wasm32"` 环境下执行 `post-content.js` 并调用初始化函数,
|
/// - 在 `target_arch = "wasm32"` 环境下执行 `post-content.js`(代码块复制)与
|
||||||
/// 用于处理代码块、图片点击等前端交互
|
/// `lightbox.js`(图片灯箱 + 懒加载),并调用各自的初始化函数。
|
||||||
#[component]
|
#[component]
|
||||||
pub fn PostContent(content_html: String) -> Element {
|
pub fn PostContent(content_html: String) -> Element {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use_effect(move || {
|
use_effect(move || {
|
||||||
let _ = js_sys::eval(include_str!("../../../public/js/post-content.js"));
|
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')");
|
let _ = js_sys::eval("window.__initPostContent('.post-content')");
|
||||||
|
// 正文图组成图集;封面(.entry-cover)单张模式,由 PostCover 标记 data-single。
|
||||||
|
let _ = js_sys::eval("window.__initLightbox(['.post-content', '.entry-cover'])");
|
||||||
});
|
});
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user