43 Commits

Author SHA1 Message Date
xfy
bdc9f0f711 chore(make): fix 目标新增 cargo fmt 与 dx fmt
自动修复流程此前只跑 biome format + cargo fix,缺少格式化收尾:
cargo fix 应用编译器建议会重写代码,dx fmt 会改写 rsx!,
两者都可能留下不符合 rustfmt 风格的输出。

现在按 Biome → cargo fix → cargo fmt → dx fmt 顺序执行,
两道格式化收尾保证最终文件状态整洁。
2026-07-15 17:50:00 +08:00
xfy
cbb8be7441 feat(make): 新增 docker-amd64 与 docker-apple 目标构建 x86_64 镜像
Some checks failed
CI / check (push) Has been cancelled
CI / build (push) Has been cancelled
docker target 只出当前宿主架构(Apple Silicon 上为 arm64),无法直接得到
x86 镜像;docker-multiarch 虽支持 amd64 但强制 --push 到 registry,无法本地
验证。补两个本地可用的 x86_64 构建 target:

- docker-amd64:docker buildx --platform linux/amd64 --load,走 QEMU 交叉仿真,
  产物进 Docker 本地 daemon,可直接 docker run / docker save。
- docker-apple:Apple Container CLI(macos 26 Tahoe)原生构建,无需 Docker Desktop,
  用 --arch(非 --platform)。

Dockerfile 本身按 dpkg --print-architecture 自适应选 musl target,无需修改。
2026-07-15 17:36:57 +08:00
xfy
8c88e82acd fix(docker): make server build arch-aware for multi-arch buildx
Cross-compiling x86_64-unknown-linux-musl from an arm64 buildx leg breaks
ring: cc-rs emits -m64 for the x86_64 target but hands it to Debian's
arm64 musl-gcc (shipped for host arch only), whose cc1 has no -m64 →
'cc1: error: unrecognized command-line option "-m64"'.

Each buildx platform leg now builds its own native musl target
(amd64→x86_64, arm64→aarch64) so musl-gcc and the target always match —
no cross-compiler, no QEMU for the compile step. The built binary is
staged at an arch-independent path so the scratch runtime stage can COPY
it without knowing which target was used.

Makefile gains a docker-multiarch target (buildx --platform
linux/amd64,linux/arm64 --push); 'make docker' now uses buildx --load
for local single-arch testing.
2026-07-10 11:26:03 +08:00
xfy
740afca05a chore: 在 lint 中添加类型检查并新增加载图标
- 在 Makefile 的 lint 目标中增加 `pnpm typecheck`
- 添加带渐变效果的旋转加载 SVG 图标
2026-07-03 11:36:24 +08:00
xfy
a47e1e6027 refactor(build): workspace 根迁移至 libs/,Makefile 整合 lint/fix
将 pnpm workspace 根从项目根移到 libs/,项目根保持纯 Rust,JS 工作区自治:
- package.json/pnpm-workspace.yaml/pnpm-lock.yaml/biome.json 迁入 libs/
- pnpm-workspace.yaml glob 从 'libs/*' 改为 '*'(已在 libs/ 内)
- biome.json 关闭 vcs.useIgnoreFile(libs/ 无独立 .gitignore,
  files.includes 已显式排除 node_modules/dist)
- Makefile 所有 pnpm/biome 调用加 'cd libs &&' 前缀

Makefile 同步整合 lint/fix(替代独立 clippy/fix target):
- make lint = biome check (libs) + cargo clippy
- make fix  = biome format --write (libs) + cargo fix
- 删除 8 个 build-*-incremental/build-* target,改为 build-libs 聚合 +
  build-<name> 用 pnpm --filter 单库便利 target

修复 biome 格式化回归:tiptap-editor/src/index.ts:83 的 sourceTextarea!.value
被 biome 误转为可选链 ?.,导致 TS2345(string | undefined 不匹配 string),
已还原为非空断言。
2026-07-02 18:02:52 +08:00
xfy
baf1e2a5f6 fix(build): make dev 一并生成 highlight.css
dev target 只跑 css(tailwind) 而不跑 highlight-css,导致 fresh clone 后
public/highlight.css 缺失——Dioxus.toml 虽引用该文件,但渲染器产出的
classed <span> 没有 stylesheet 着色,代码高亮静默失效。把 highlight-css
列入 dev 的前置依赖,与 build/build-linux 行为对齐。
2026-07-02 17:21:30 +08:00
xfy
1f8147f323 chore(make): dev 改用 make css 一次性构建 Tailwind 2026-07-02 14:07:57 +08:00
xfy
fba88639a9 fix(build): dx build 后用源文件还原 webp 产物
dx build 0.7.9 会把 public/ 下的 .webp 重编码成 VP8L 无损静图:
动画帧被完全丢弃(动图变静图),静图因 VP8L 无损反而膨胀 7-8 倍。
这与 Dioxus 文档承诺的「public/ 原样拷贝」不符,疑似 0.7.9 的 bug。

新增 restore-webp target:dx build 完成后遍历所有产物目录
(release/debug),用源 public/ 的同名 .webp 覆盖回去。
仅在 build / build-linux 末尾调用,build-freebsd 不受影响
(用 cargo 直出,部署直接用源 public/)。

上游修复后可移除该 target 及两处调用。
2026-07-01 18:22:45 +08:00
xfy
a4331bd813 feat(build): add FreeBSD x86_64 cross-compile support
方案 A(clang + lld + 本地 sysroot)。rustc 为 freebsd target 链接的系统库
(libc/libexecinfo/libgcc_s/libthr)及 sysinfo 依赖的 freebsd 专有库
(libkvm/libmemstat/libprocstat/libdevstat)需 FreeBSD 运行时,无法纯靠
clang+lld 无 sysroot 完成;故从 FreeBSD 15.1 base.txz 解出 crt 对象 + 系统库
到 .freebsd-sysroot/(gitignored,machine-local)。

- .cargo/config.toml: freebsd target 配置作为注释模板(sysroot 路径机器相关,
  不硬编码进仓库);linker 经 rustflags 的 -C linker=clang 设置,使 Makefile
  能用 CARGO_TARGET_*_RUSTFLAGS 环境变量整体注入。
- Makefile: 新增 freebsd-sysroot(幂等下载+解压 base.txz)与 build-freebsd
  (release server 二进制交叉编译)target。server 用 cargo 直出而非 dx CLI,
  因 dx 对该 target 的支持未经验证。
- .gitignore: 忽略 .freebsd-sysroot/。
- AGENTS.md: 补充构建命令说明。

实测 release 二进制 16MB,stripped ELF for FreeBSD 15.1,动态依赖均为
FreeBSD base 自带库(libc.so.7 libthr.so.3 libkvm.so.7 等)。
2026-07-01 13:40:00 +08:00
xfy
096345d2fe chore: add docker target to Makefile 2026-07-01 10:28:26 +08:00
xfy
c74e59485d feat(editor): add codemirror-editor subproject + Rust bridge
新建 libs/codemirror-editor(pnpm/Vite IIFE/@catppuccin/codemirror Catppuccin
Latte+Mocha 主题/@codemirror/lang-sql schema 补全/@replit/codemirror-vim),
输出 public/codemirror/。Rust 桥接 codemirror_bridge.rs 镜像 tiptap_bridge.rs
(Reflect::get 取对象字面量 + EditorHandle 持有闭包 + Drop→destroy)。
接入 Makefile/Dioxus.toml/.gitignore。

注意:thememirror 不含 catppuccin 主题,改用官方 @catppuccin/codemirror@1.0.3
(导出 catppuccinLatte/catppuccinMocha)。
2026-06-29 18:24:38 +08:00
xfy
62fe87961f chore(build): add clippy and fix targets to Makefile
Some checks failed
CI / check (push) Failing after 5m19s
CI / build (push) Has been skipped
2026-06-29 15:55:51 +08:00
xfy
8ec4ecd310 chore: migrate JS subprojects from npm to pnpm
Some checks failed
CI / check (push) Failing after 4m41s
CI / build (push) Has been skipped
Switch tiptap-editor, lightbox, and yggdrasil-core from npm to pnpm.
Replace package-lock.json with pnpm-lock.yaml and update Makefile accordingly.
2026-06-29 10:35:04 +08:00
xfy
824ad5a3d3 chore(Makefile): remove build hints and start target
Build instructions have been moved to AGENTS.md.
The verbose echo messages and the standalone start target
are no longer needed.
2026-06-29 09:59:14 +08:00
xfy
18db852f30 fix(build): correct asset path resolution for local release build and remove duplicated resources 2026-06-26 18:35:48 +08:00
xfy
1e78c7f0f9 fix(doc): 修复 /doc 路由与 Dioxus 静态托管冲突的 panic
Dioxus 在 dev 用 nest_service("/doc", ServeDir) 托管 public/doc/ 目录,
手动在 static_routes 注册 /doc 会在 merge 时触发路由冲突 panic。

根因(dioxus-server serve_dir_cached):dev 模式对 public/ 下的目录用
nest_service 挂整个 ServeDir,注册了 /doc;我在 static_routes 加的
精确 /doc 路由与之同名冲突。

修复:
- main.rs: 移除手动注册的 /doc 与 /doc/ 重定向路由,交给 Dioxus 托管。
  文档深层路径 /doc/yggdrasil/* 由 ServeDir 直接服务。
- Makefile: doc 目标拷贝后额外生成 public/doc/index.html 重定向页,
  ServeDir 访问目录根时返回它,经 meta refresh + JS 跳转到
  yggdrasil/index.html,让裸路径 /doc 也能直达文档。
- build/clean 同步集成 make doc 与清理 public/doc。
2026-06-26 14:27:21 +08:00
xfy
a0067c73d6 chore(core): yggdrasil-core 接入构建管线与全局注入
Dioxus.toml 追加 yggdrasil-core 的 css/script;Makefile 加
build-core / build-core-incremental,接入 build/build-linux/dev/test。
2026-06-26 13:58:54 +08:00
xfy
2b5cd5f64f docs(makefile): cargo doc 默认使用 ayu 主题
通过 RUSTDOCFLAGS="--default-theme=ayu" 透传给 rustdoc,生成产物
根节点写入 data-theme="ayu"。默认值语义:浏览器未记住主题时生效。
2026-06-26 10:17:12 +08:00
xfy
96da2f27d5 docs: 补齐 tiptap_bridge 文档注释并新增 make doc 目标
- tiptap_bridge.rs: 为 wasm-bindgen 桥接层全部 19 处 pub 项补文档
  (JS 类型映射、getter/setter、EditorHandle::new、pub use 重导出)
- markdown.rs: 用反引号包裹注释内字面量 <span>,消除 rustdoc 警告
- Makefile: 新增 doc / doc-open,纯 binary crate 需 --document-private-items
  才能让内部模块进文档
2026-06-25 18:26:56 +08:00
xfy
05e2989278 build(lightbox): use npm install (npm 11 ci rejects cross-platform rolldawn optional deps) 2026-06-24 11:18:40 +08:00
xfy
adf9e9cf07 build: add build-lightbox targets, wire into build/build-linux/dev/test 2026-06-24 11:06:03 +08:00
xfy
368a651fa6 build: make test runs both cargo test and vitest 2026-06-24 10:14:20 +08:00
xfy
ef6a3f0da2 fix(home,editor): repair post card nested anchors and editor upload state
首页审查修复(home/post_card/image_viewer/search/home_skeleton):
- PostCard 消除嵌套 <a>:外层 Link 包裹改为绝对定位覆盖层链接,
  标题/摘要/封面降级为普通元素,标签用 z-10 叠在覆盖层之上并
  stop_propagation,整卡点击跳转文章详情。
- ImageViewer 新增 lightbox prop(默认 true),卡片封面传 false
  禁用灯箱以归一为单一跳转交互;文章详情页零改动。
- home.rs 越界页码守卫:分页仅在 total>0 渲染,避免 /page/9999
  出现孤立空分页;错误文案脱敏为"加载失败"。
- search.rs 错误文案脱敏为"搜索失败",与首页/标签页一致。
- HomeSkeleton 卡片 5→10,对齐 POSTS_PER_PAGE。

编辑器上传重构(write/tiptap_bridge):
- consume_upload_event 改用 upload_errors Vec 自身判重,移除
  seen_error_ids 副本状态;Signal 参数加 mut 修复 E0596 编译错误。
- make_upload_closure 构造阶段错误以 rejected Promise 返回而非
  panic,单张坏文件不再拖垮整个编辑器。
- write.rs 移除未用的 success signal,编辑保存后统一跳转 Posts,
  标签分隔符支持半角/全角逗号与分号,提取 META_*_CLASS 常量去重。
- Makefile dev 目标清理 static/ 目录。
2026-06-23 14:14:28 +08:00
xfy
ad0d884065 fix(makefile): disable SSR cache in dev to avoid stale rendered HTML
dx serve 热重载(重新编译代码)不会清除进程内的 IncrementalRenderer
缓存(DashMap<Uri, CachedHTML> in-process)。改了 SSR 渲染逻辑(如
markdown 渲染、组件结构)后,即使二进制重新编译了,dev server 仍返回
进程启动时缓存的旧 HTML,直到 TTL(默认 3600s)过期。

坑: Ctrl+C 重启 make dev 时,如果 dx serve 子进程没被真正杀掉(进程
PID 不变),内存缓存持续存在。表现为"代码改了但页面不变"。

修复: dev target 给 dx serve 加 SSR_CACHE_SECS=0,禁用 SSR 缓存。
每次请求都重新渲染,改代码立即生效。仅影响 dev,不影响生产构建。
2026-06-23 09:33:13 +08:00
xfy
6ff37322b2 feat(editor): add image upload to slash command and build tiptap in make dev
斜杠命令图片上传 + Makefile dev 构建修复

1. 斜杠命令接入图片上传管线
   - slash-command.ts: SlashCommand 扩展改为 Extension.create<Options>,
     新增 onImageUpload 选项;原单一"图片"命令拆成两个:
     · "上传图片"(📤): 仅在 onImageUpload 可用时出现,触发原生文件选择器
       (accept 限定 jpeg/png/gif/webp,与 upload 端点 MIME 一致),
       上传成功后 setImage 插入,失败 console.error(与 FileHandler 一致)
     · "图片链接"(🖼): 保留原 window.prompt URL 方式
   - index.ts: SlashCommand.configure({ onImageUpload }) 透传宿主回调,
     复用 write.rs 已注入的 /api/upload 管线,无需 Rust 端改动

2. Makefile: make dev 不再忽略 tiptap 构建
   - 根因: 原 dev target 只起 tailwindcss watch + dx serve,从不构建
     tiptap 编辑器,导致 dev server 始终 serve 上次 make build 残留的
     旧 editor.js(本次新增的"上传图片"命令在 dev 下永远不生效)
   - 新增 build-editor-incremental target (跳过 npm ci,直接 vite build,~1s)
   - dev 现在依赖 build-editor-incremental,启动前先增量构建编辑器

3. Makefile: clean 不再删 public/tiptap
   - public/tiptap 是跨子项目(npm)构建产物,删除后必须重跑 make build-editor
     (含 npm ci) 才能恢复;原 clean 会删它是陷阱(make clean && make dev
     会导致编辑器直接消失)。现在 clean 只清 Rust 产物和缓存
2026-06-22 14:18:05 +08:00
xfy
449a545886 security: fix critical issues from repository review
Some checks failed
CI / build (push) Has been cancelled
CI / check (push) Has been cancelled
P0 blockers:
- Fix migration numbering conflict and duplicate indexes
- Change comments.post_id FK to ON DELETE CASCADE
- Restrict public post detail endpoint to published posts only
- Fix rate-limiting IP extraction and fallback to ConnectInfo
- Harden HTML sanitizer: deny unknown URL schemes, restrict data URIs
- Remove session token from login response body
- Enforce image pixel/dimension limits on upload and serving

P1 high-risk:
- Validate uploads by magic bytes and decode GIF/WebP
- Add pagination/rate-limiting to search, tag posts, and comments
- Make first-admin registration and slug uniqueness check atomic
- HTML-escape comment author fields
- Improve HTML minify cache key and skip admin/error responses
- Add mobile navigation menu

P2 accessibility/quality:
- Associate form labels with inputs
- Key PostDetail article by slug to re-init scripts on navigation
- Improve image viewer keyboard accessibility
- Make theme toggle SSR-friendly and add aria-label
- Invalidate slug 404 cache on create and pending count on new comment
- Deduplicate tags case-insensitively

P3 cleanup:
- Remove unused tower-http dependency, expand make clean
- Configure DB pool timeouts and verified recycling
- Run background cleanup tasks immediately on startup
- Use SHA-256 for stable disk cache keys
- Log DB errors with Display instead of Debug
- Update README migration instructions

All tests pass (321), clippy clean, dx check clean.
2026-06-17 10:34:14 +08:00
xfy
0159b2321a fix(build): make build-linux produce a statically linked musl binary
- Work around Dioxus 0.7.9 leaking getrandom_backend=wasm_js cfg into
  the musl server build by disabling DX's auto flag and setting it only
  for wasm32 in .cargo/config.toml.
- Split build-linux into @client and @server steps so the server build
  can explicitly enable the server feature and target
  x86_64-unknown-linux-musl.
- Configure the musl linker to use x86_64-linux-musl-gcc.
2026-06-16 17:53:05 +08:00
xfy
b37e33dbf4 fix(build): 修复 Tailwind v4 与 Tiptap 编辑器构建
Tailwind v4 将 CLI 拆为独立包 @tailwindcss/cli,核心包 tailwindcss
不再带 bin,npx tailwindcss 会因找不到可执行入口而失败;即便改用
@tailwindcss/cli,npx 装到全局缓存,@import "tailwindcss" 仍解析不到
./node_modules/tailwindcss。回到直接调用 PATH 上的 tailwindcss 二进制
(brew 安装或 CI 的 npm i -g @tailwindcss/cli),这也是 v4 升级时的
原始设计。

build-editor 中 npm ci 受全局 --omit=dev 影响会跳过 vite,npx vite
退而拉取 latest(v8,不兼容)。改用 npm ci --include=dev 确保装上
lock 钉死的 vite@5.4.21,并以 npm run build 走本地 .bin/vite,避免
npx 版本漂移。
2026-06-16 10:53:37 +08:00
xfy
6fe7dc3ff5 build: use npx tailwindcss instead of global binary
Some checks failed
CI / check (push) Successful in 8m46s
CI / build (push) Has been cancelled
2026-06-12 18:09:20 +08:00
xfy
b72bc512c2 chore(make): use npm ci for tiptap editor to avoid lockfile drift 2026-06-12 16:27:12 +08:00
xfy
28d3ed998a chore: optimize release profile for fullstack and add linux static build target
- Change opt-level from 'z' to 3 for better runtime performance
- Use thin LTO for faster compilation with similar results
- Remove panic=abort and strip=true to preserve server debuggability
- Add --debug-symbols=false to dx build for smaller WASM
- Add build-linux target for static musl binary
2026-06-09 10:30:36 +08:00
xfy
4f368e6fb8 test: add 122 unit tests across 12 modules
Cover utils/text, api/slug, auth/password, auth/session,
models/post, models/user, api/auth validation, api/markdown,
api/image, highlight, api/rate_limit. Add make test target.
2026-06-09 09:25:44 +08:00
xfy
0dbd07198b fix: remove leftover --wasm-split flag from dx serve dev command
Amends the wasm-split rollback by also cleaning up the dev server
flag that was missed in the previous revert commit.
2026-06-04 17:46:44 +08:00
xfy
f81656bb18 revert: disable wasm-split due to fullstack SSR incompatibility
wasm-split is incompatible with Dioxus fullstack SSR/hydration.
The feature causes hydration failures because split WASM chunks
are not available during client-side hydration of server-rendered HTML.

Changes reverted:
- Remove wasm-split feature from dioxus and dioxus-router
- Remove --wasm-split flag from dx build in Makefile
2026-06-04 17:44:33 +08:00
xfy
73fd3c30e2 build: remove obsolete WASM path fix and tracked index.html 2026-06-04 17:34:12 +08:00
xfy
a282d1dd29 feat: enable wasm-split for route-based code splitting
Enable Dioxus 0.7 automatic WASM bundle splitting by route:

- Add wasm-split feature to dioxus and dioxus-router in Cargo.toml
- Add --wasm-split flag to dx build in Makefile
- Router definitions stay as plain #[route] — splitting is automatic

Dioxus 0.7.9 handles splitting automatically when the feature and
CLI flag are enabled. Per-route #[wasm_split] attributes are not
required (and not supported by this version's derive macro).
2026-06-04 17:32:00 +08:00
xfy
cd45ab17de build: simplify tiptap build by setting fixed output filename in vite config 2026-06-04 16:26:25 +08:00
xfy
aebdcd6d99 fix(build): fix WASM 404 in production by creating symlinks in wasm/ directory 2026-06-04 11:34:13 +08:00
xfy
11261836c7 feat: add syntect code highlighting with catppuccin themes
- Add syntect dependency (server feature, fancy-regex backend)
- Create highlight module with LazyLock globals for SyntaxSet + themes
- Intercept CodeBlock events in markdown rendering for syntax highlighting
- Update ammonia whitelist to allow span/pre/code class/style attributes
- Add generate_highlight_css binary for CSS generation
- Add highlight-css Makefile target (runs before tailwindcss)
- Import generated highlight.css in input.css
- Remove hardcoded code block colors, let catppuccin CSS take over
2026-06-03 11:52:58 +08:00
xfy
5d523fbfc7 添加 dev 监听 0.0.0.0 2026-05-26 23:59:31 +08:00
xfy
f6d60520eb 集成 Tiptap Markdown 编辑器到文章撰写页面
- 新增 libs/tiptap-editor/ 打包子项目(Tiptap Core + StarterKit + Markdown)
- 构建产物输出到 public/tiptap/
- 替换原有的 textarea + pulldown_cmark 预览为 WYSIWYG 编辑器
- Makefile 新增 build-editor target
- Dioxus.toml 引入 editor.js 和 editor.css

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 17:46:04 +08:00
xfy
c2d5619855 移除首页,将根路径重定向到登录页,添加注册链接
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 10:22:05 +08:00
xfy
390ab98b86 升级 Tailwind CSS 到 v4 并简化构建流程
- 将 input.css 从 v3 的 @tailwind 指令迁移到 v4 的 @import "tailwindcss"
- 删除 tailwind.config.js(v4 不再需要配置文件)
- 删除 package.json(完全使用本地 tailwindcss CLI)
- 重新构建 public/style.css 为 v4 格式
- 添加 Makefile 提供 dev/build/css/css-watch/clean 命令

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 09:59:42 +08:00