Compare commits

..

No commits in common. "62fe87961fb008c1492729910fb52b306c5fa5c0" and "369b4838a3f394ffeff4c73911090bdecbb18f59" have entirely different histories.

15 changed files with 202 additions and 204 deletions

View File

@ -1,4 +1,4 @@
.PHONY: dev build build-linux css css-watch clean build-editor build-editor-incremental build-lightbox build-lightbox-incremental build-core build-core-incremental highlight-css test doc doc-open start clippy fix
.PHONY: dev build build-linux css css-watch clean build-editor build-editor-incremental build-lightbox build-lightbox-incremental build-core build-core-incremental highlight-css test doc doc-open start
build:
@$(MAKE) build-editor
@ -75,12 +75,6 @@ test:
@cd libs/lightbox && pnpm test
@cd libs/yggdrasil-core && pnpm test
clippy:
@cargo clippy --all-targets --all-features -- -D warnings
fix:
@cargo fix --allow-dirty
# 只编译当前 crate 的文档(--no-deps 跳过依赖,--document-private-items
# 让纯 binary crate 的内部模块/私有项也进文档,否则页面基本是空的)。
# RUSTDOCFLAGS 把 rustdoc 的 --default-theme=ayu 透传过去——cargo doc 本身

View File

@ -707,4 +707,3 @@
}
/* ========== Blur-up 渐进图片加载(已移入 @layer components ========== */
@source "./src/**/*.{rs,html}";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 452 KiB

View File

@ -147,20 +147,13 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>, parent_indent: Option<i
class: "block text-sm font-medium text-paper-secondary mb-1",
"内容 *"
}
div { class: "relative bg-paper-entry rounded-lg",
textarea {
id: "comment-content-{id_suffix}",
class: "{INPUT_CLASS} !bg-transparent relative z-10 peer block min-h-[100px] resize-y",
class: "{INPUT_CLASS} min-h-[100px] resize-y",
value: "{content_md}",
disabled: submitting(),
oninput: move |e| content_md.set(e.value()),
}
img {
src: "/images/xiantiaoxiaogou_03.webp",
alt: "",
class: "absolute bottom-1.5 right-1.5 w-24 pointer-events-none opacity-60 peer-focus:opacity-10 transition-opacity duration-300 z-0",
}
}
}
p { class: "text-xs text-paper-tertiary", "支持 Markdown 语法" }

View File

@ -77,7 +77,7 @@ pub fn CommentItem(comment: PublicComment, post_id: i32) -> Element {
}
div {
class: "prose prose-sm dark:prose-invert max-w-none text-paper-secondary md-content",
class: "prose prose-sm dark:prose-invert max-w-none text-paper-secondary",
dangerous_inner_html: comment.content_html.as_deref().unwrap_or(""),
}

View File

@ -207,7 +207,6 @@ pub fn FilterTabs(
let mut indicator_style = use_signal(|| "left: 0px; width: 0px; opacity: 0;".to_string());
let id_prefix = use_hook(|| TAB_GROUP_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst));
#[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))]
let update_indicator = move |active: String| {
spawn(async move {
#[cfg(target_arch = "wasm32")]
@ -255,7 +254,11 @@ pub fn FilterTabs(
button {
id: "tab-{id_prefix}-{value}",
key: "{value}",
class: if active_value == *value { "cursor-pointer px-4 py-2 text-sm font-medium text-paper-primary transition-colors" } else { "cursor-pointer px-4 py-2 text-sm font-medium text-paper-secondary hover:text-paper-primary transition-colors" },
class: if active_value == *value {
"cursor-pointer px-4 py-2 text-sm font-medium text-paper-primary transition-colors"
} else {
"cursor-pointer px-4 py-2 text-sm font-medium text-paper-secondary hover:text-paper-primary transition-colors"
},
onclick: {
let v = value.to_string();
move |_| {

View File

@ -336,25 +336,25 @@ mod tests {
fn relative_label_hours() {
let (label, _) = relative_label_from_millis(60 * 60_000, ISO);
assert_eq!(label, "1 小时前");
let (label, _) = relative_label_from_millis(3 * 3_600_000, ISO);
let (label, _) = relative_label_from_millis(3 * 3600_000, ISO);
assert_eq!(label, "3 小时前");
let (label, _) = relative_label_from_millis(23 * 3_600_000, ISO);
let (label, _) = relative_label_from_millis(23 * 3600_000, ISO);
assert_eq!(label, "23 小时前");
}
#[test]
fn relative_label_days() {
let (label, _) = relative_label_from_millis(24 * 3_600_000, ISO);
let (label, _) = relative_label_from_millis(24 * 3600_000, ISO);
assert_eq!(label, "1 天前");
let (label, _) = relative_label_from_millis(7 * 24 * 3_600_000, ISO);
let (label, _) = relative_label_from_millis(7 * 24 * 3600_000, ISO);
assert_eq!(label, "7 天前");
let (label, _) = relative_label_from_millis(29 * 24 * 3_600_000, ISO);
let (label, _) = relative_label_from_millis(29 * 24 * 3600_000, ISO);
assert_eq!(label, "29 天前");
}
#[test]
fn relative_label_falls_back_to_date_over_30_days() {
let (label, absolute) = relative_label_from_millis(60 * 24 * 3_600_000, ISO);
let (label, absolute) = relative_label_from_millis(60 * 24 * 3600_000, ISO);
assert_eq!(label, "2026-06-22");
assert_eq!(absolute, "2026-06-22");
}

View File

@ -325,20 +325,16 @@ fn main() {
// 配置增量渲染缓存,默认缓存 3600 秒,可通过 SSR_CACHE_SECS 覆盖。
// 注意src/ssr_cache.rs 中的世代号是未来就绪基础设施,当前并不会使
// Dioxus 0.7 的 SSR 缓存实际失效Dioxus 未暴露相应 API。在 API 可用
// 之前SSR_CACHE_SECS 仍是唯一有效的兜底 TTL——它就是内容写入后
// SSR 页面可见滞后的上界。
let ssr_cache_secs = std::env::var("SSR_CACHE_SECS")
// 之前SSR_CACHE_SECS 仍是唯一有效的兜底 TTL。
let config = ServeConfig::builder().incremental(
dioxus::server::IncrementalRendererConfig::default().invalidate_after(
std::time::Duration::from_secs(
std::env::var("SSR_CACHE_SECS")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(3600);
tracing::info!(
ssr_cache_secs,
"增量渲染缓存生效(写入后内容可见滞后的上界);\
SSR "
);
let config = ServeConfig::builder().incremental(
dioxus::server::IncrementalRendererConfig::default()
.invalidate_after(std::time::Duration::from_secs(ssr_cache_secs)),
.unwrap_or(3600),
),
),
);
// SSR 世代号中间件:把当前全局世代号注入请求扩展,并对 GET 请求的

View File

@ -17,7 +17,26 @@ pub fn About() -> Element {
h1 { class: "text-4xl font-bold text-paper-primary tracking-tight", "关于" }
}
article { class: "prose dark:prose-invert max-w-none text-paper-content leading-relaxed",
p { "世界……遗忘我……" }
p { "Yggdrasil 是一个以文字为主的简约博客系统。" }
p {
"它使用 Rust + Dioxus 构建,采用 PostgreSQL 作为数据库,支持 Markdown 写作、标签管理和暗色模式。"
}
h2 { class: "text-xl font-bold text-paper-primary mt-8 mb-4", "技术栈" }
ul { class: "list-disc pl-5 space-y-1",
li { "Rust + Dioxus 0.7 (全栈 Web 框架)" }
li { "PostgreSQL + tokio-postgres (数据库)" }
li { "Tailwind CSS (样式)" }
li { "Tiptap Editor (富文本编辑器)" }
li { "pulldown-cmark (Markdown 渲染)" }
}
h2 { class: "text-xl font-bold text-paper-primary mt-8 mb-4", "特性" }
ul { class: "list-disc pl-5 space-y-1",
li { "Markdown 写作与实时预览" }
li { "文章标签与归档" }
li { "暗色/亮色主题切换" }
li { "响应式设计" }
li { "文章搜索" }
}
}
}
}

View File

@ -99,7 +99,7 @@ pub fn PostsPage(page: i32) -> Element {
action: EmptyStateAction {
label: "写文章".to_string(),
to: Route::Write {},
},
}
}
} else {
div { class: "{ADMIN_TABLE_CLASS}",

View File

@ -106,6 +106,7 @@ pub fn TrashPage(page: i32) -> Element {
// 自动清理配置卡片(抽取为子组件 AutoPurgeSettings见文件末尾
AutoPurgeSettings { settings }
// 批量操作栏(选中时显示)
if !selected_ids().is_empty() {
div { class: "flex items-center gap-3 p-3 bg-paper-theme rounded-lg",
@ -213,7 +214,7 @@ pub fn TrashPage(page: i32) -> Element {
}
}
th { class: "px-4 py-3 font-medium", "标题" }
th { class: "px-4 py-3 font-medium", "原状态" }
th { class: "px-4 py-3 font-medium", "原状态" } // 底部:清空回收站 + 分页
th { class: "px-4 py-3 font-medium w-28", "删除时间" }
th { class: "px-4 py-3 font-medium w-24 text-center", "剩余" }
th { class: "px-4 py-3 font-medium w-32 text-right", "操作" }
@ -424,7 +425,11 @@ fn AutoPurgeSettings(settings: Signal<TrashSettings>) -> Element {
// 设置面板(可折叠带平滑动画)
div {
class: "grid transition-all duration-300 ease-in-out",
style: if settings_panel_open() { "grid-template-rows: 1fr; opacity: 1; pointer-events: auto;" } else { "grid-template-rows: 0fr; opacity: 0; pointer-events: none;" },
style: if settings_panel_open() {
"grid-template-rows: 1fr; opacity: 1; pointer-events: auto;"
} else {
"grid-template-rows: 0fr; opacity: 0; pointer-events: none;"
},
div { class: "overflow-hidden min-h-0",
div { class: "border-t border-paper-border p-5 space-y-6",
// 开关行:启用自动清理
@ -660,6 +665,8 @@ fn TrashRow(
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_auto_purge_settings_has_transition_class() {
let full_code = include_str!("trash.rs");

View File

@ -458,13 +458,8 @@ fn write_editor(post_id: Option<i32>) -> Element {
// h-[60vh]随窗口高度自适应min-h-[400px]:窗口过矮时仍可用。
div { class: "h-[60vh] min-h-[400px] flex flex-col my-4",
div {
class: "relative group flex-1 min-h-0 w-full border border-[var(--color-paper-border)] rounded-xl overflow-hidden bg-[var(--color-paper-entry)] shadow-[0_2px_8px_rgba(0,0,0,0.04)] dark:shadow-none",
class: "flex-1 min-h-0 w-full border border-[var(--color-paper-border)] rounded-xl overflow-hidden bg-[var(--color-paper-entry)] shadow-[0_2px_8px_rgba(0,0,0,0.04)] dark:shadow-none",
id: "tiptap-editor",
img {
src: "/images/xiantiaoxiaogou_03.webp",
alt: "",
class: "absolute bottom-1.5 right-1.5 opacity-60 group-focus-within:opacity-10 transition-opacity duration-300 pointer-events-none z-0",
}
}
}
@ -661,7 +656,9 @@ fn CoverUploader(cover_image: Signal<String>, cover_uploading: Signal<bool>) ->
// —— 上传中:骨架占位 + 文案 ——
if cover_uploading() {
div { class: "absolute inset-0 flex flex-col items-center justify-center gap-3 bg-[var(--color-paper-tertiary)]/30 animate-pulse",
span { class: "text-sm text-[var(--color-paper-secondary)]", "上传中..." }
span { class: "text-sm text-[var(--color-paper-secondary)]",
"上传中..."
}
}
}
@ -715,7 +712,9 @@ fn CoverUploader(cover_image: Signal<String>, cover_uploading: Signal<bool>) ->
}
// 底部渐变遮罩 + "更换封面"提示hover 出现)。
div { class: "absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-black/50 to-transparent opacity-0 group-hover/cover:opacity-100 transition-opacity flex items-end justify-center pb-2 pointer-events-none",
span { class: "text-xs text-white/90", "点击下方区域可重新上传" }
span { class: "text-xs text-white/90",
"点击下方区域可重新上传"
}
}
}

View File

@ -54,7 +54,7 @@ fn TagsContent() -> Element {
rsx! {
EmptyState {
title: "暂无标签",
description: "当前还没有任何标签。",
description: "当前还没有任何标签。"
}
}
} else {
@ -76,9 +76,7 @@ fn TagsContent() -> Element {
tag: tag.name.clone(),
},
"{tag.name}"
sup { class: "ml-1 text-sm text-paper-secondary",
"{tag.post_count}"
}
sup { class: "ml-1 text-sm text-paper-secondary", "{tag.post_count}" }
}
}
}
@ -132,7 +130,7 @@ fn TagDetailContent(tag: String) -> Element {
rsx! {
EmptyState {
title: "暂无文章",
description: "该标签下还没有发布任何文章。",
description: "该标签下还没有发布任何文章。"
}
}
} else {

View File

@ -41,21 +41,10 @@ static GLOBAL_GENERATION: LazyLock<AtomicU64> = LazyLock::new(AtomicU64::default
pub struct SsrGeneration(pub u64);
/// 原子递增并返回新的全局世代号。
///
/// 任何文章写入操作都会调用本函数,标记 SSR 渲染结果已过期。当前 Dioxus 0.7
/// 不读取此世代号(详见模块文档),实际失效仍依赖 `SSR_CACHE_SECS` 兜底 TTL。
/// 此处打一条 info 日志,既证明写入路径已执行,也提醒部署者此处存在滞后——
/// 避免"我改了文章怎么没变"被误判成 DB/发布链路问题。
pub fn bump_global_generation() -> u64 {
let new = GLOBAL_GENERATION
GLOBAL_GENERATION
.fetch_add(1, Ordering::SeqCst)
.wrapping_add(1);
tracing::info!(
new_generation = new,
"SSR 世代号已递增写入路径触发。注意Dioxus 0.7 不读取此值,\
SSR SSR_CACHE_SECS "
);
new
.wrapping_add(1)
}
/// 返回当前全局世代号。

View File

@ -181,14 +181,15 @@ pub fn ThemeToggle() -> Element {
let x = coords.x;
let y = coords.y;
// JS 从 DOM 现状推导目标主题(不传 isDark),避免与 Signal 状态不同步。
let _ = js_sys::eval(
&format!(
let _ = js_sys::eval(&format!(
"if (window.__startThemeTransition) \
window.__startThemeTransition({x}, {y});", // theme.set 推迟到动画结束:其触发的 Dioxus 微任务重渲染会打断 VT。
window.__startThemeTransition({x}, {y});",
x = x,
y = y,
),
);
));
// theme.set 推迟到动画结束:其触发的 Dioxus 微任务重渲染会打断 VT。
// gen 确保连续点击只有最新回调 set。JS 已自治切换 dark class,
// 动画完成后再更新 Dioxus 状态,避免组件重渲染可能带来的干扰
let gen = click_gen() + 1;
click_gen.set(gen);
let mut theme_clone = theme;