依据 Dioxus 0.7 optimizing 指南做两项改进: - 为数据驱动列表渲染补全显式 key(13 处,9 个文件): home/archives/tags/search 文章与标签列表、post_card/post_footer 标签、header 桌面/移动导航、admin dashboard/posts/write 列表。 使用各类型稳定唯一字段(post.id / tag / tag.name / item.label / err.id / year_group.year / month_group.month_en)作为 key, 让 Dioxus diff 正确识别元素身份。骨架屏 for _ in 0..N 静态占位 循环与已带 key 的评论树/admin 行不动。 - [profile.release] 加 panic = "abort":WASM 去掉 unwind 元数据减小 体积;server 端错误处理走 Result+?(见 error.rs),不依赖 panic unwind,无副作用。 其余文件为本机格式化(单行折叠/多行展开),一并提交。 验证:dx check 通过、cargo test 405 passed。
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
//! 文章页脚组件
|
||
//!
|
||
//! 展示文章标签、上一篇/下一篇导航与返回首页链接。
|
||
|
||
use dioxus::prelude::*;
|
||
use dioxus::router::components::Link;
|
||
|
||
use crate::components::post::post_nav_links::PostNavLinks;
|
||
use crate::models::post::Post;
|
||
use crate::router::Route;
|
||
|
||
/// 文章页脚组件。
|
||
///
|
||
/// Props:
|
||
/// - `post`:文章数据模型
|
||
///
|
||
/// 展示内容包括:
|
||
/// - 文章标签云,链接到对应标签详情页
|
||
/// - 相邻文章导航(如有)
|
||
/// - 返回首页链接
|
||
#[component]
|
||
pub fn PostFooter(post: Post) -> Element {
|
||
let tags = post.tags.clone();
|
||
|
||
rsx! {
|
||
footer { class: "post-footer",
|
||
if !tags.is_empty() {
|
||
ul { class: "post-tags",
|
||
for tag in tags.into_iter() {
|
||
li { key: "{tag}",
|
||
Link {
|
||
to: Route::TagDetail {
|
||
tag: tag.clone(),
|
||
},
|
||
"{tag}"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if post.prev_post.is_some() || post.next_post.is_some() {
|
||
PostNavLinks { prev: post.prev_post, next: post.next_post }
|
||
}
|
||
|
||
div { class: "back-to-home",
|
||
Link { to: Route::Home {}, "← 返回首页" }
|
||
}
|
||
}
|
||
}
|
||
}
|