From 383c39897395d512b89dfcdb5094876621786b12 Mon Sep 17 00:00:00 2001 From: XOF Date: Mon, 15 Dec 2025 06:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20proxy/rewriter.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/rewriter.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/proxy/rewriter.go b/proxy/rewriter.go index 2891519..f8c2cd9 100644 --- a/proxy/rewriter.go +++ b/proxy/rewriter.go @@ -43,6 +43,20 @@ func (r *ContentRewriter) RewriteHTML(body []byte) ([]byte, error) { func (r *ContentRewriter) rewriteNode(n *html.Node) { if n.Type == html.ElementNode { + // 在 head 标签开始处插入 base 标签 + if n.Data == "head" && n.FirstChild != nil { + baseNode := &html.Node{ + Type: html.ElementNode, + Data: "base", + Attr: []html.Attribute{ + {Key: "href", Val: "/p/" + r.token + "/"}, + }, + } + baseNode.NextSibling = n.FirstChild + n.FirstChild.PrevSibling = baseNode + baseNode.Parent = n + n.FirstChild = baseNode + } attrs := map[string]bool{"href": true, "src": true, "action": true, "data": true} for i, attr := range n.Attr {