修复访客浏览轨迹延迟与排序,增加演示站

保留 SPA hash 以正确区分页面;延迟采集 title 避免慢一页;轨迹改为最新在上;补充 demo-shop 测试页与 Vite 静态路由。
This commit is contained in:
yml2213
2026-07-18 23:22:47 +08:00
parent 81852e0ddd
commit 970bae16d1
9 changed files with 651 additions and 44 deletions
+11 -2
View File
@@ -7,13 +7,22 @@ import (
)
func TestSanitizePageURL(t *testing.T) {
got := sanitizePageURL("https://shop.example.com/p/1?token=secret&ok=1#hash")
if got == "" || strings.Contains(got, "token=") || strings.Contains(got, "#") {
got := sanitizePageURL("https://shop.example.com/p/1?token=secret&ok=1#/cart")
if got == "" || strings.Contains(got, "token=") {
t.Fatalf("sanitize failed: %q", got)
}
if !strings.Contains(got, "ok=1") {
t.Fatalf("should keep ok param: %q", got)
}
// SPA hash 路由必须保留,否则换页轨迹会被去重丢掉
if !strings.Contains(got, "#/cart") {
t.Fatalf("should keep hash fragment for SPA: %q", got)
}
home := sanitizePageURL("http://localhost:5173/demo-shop/index.html#/")
cart := sanitizePageURL("http://localhost:5173/demo-shop/index.html#/cart")
if home == "" || cart == "" || home == cart {
t.Fatalf("hash pages must differ: home=%q cart=%q", home, cart)
}
if sanitizePageURL("javascript:alert(1)") != "" {
t.Fatal("reject javascript")
}