更新 proxy/rewriter.go

This commit is contained in:
XOF
2025-12-15 06:54:42 +08:00
parent a39914ad45
commit 383c398973

View File

@@ -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 {