更新 proxy/rewriter.go

This commit is contained in:
XOF
2025-12-15 06:57:59 +08:00
parent 383c398973
commit 0cb3d165bc

View File

@@ -43,20 +43,6 @@ func (r *ContentRewriter) RewriteHTML(body []byte) ([]byte, error) {
func (r *ContentRewriter) rewriteNode(n *html.Node) { func (r *ContentRewriter) rewriteNode(n *html.Node) {
if n.Type == html.ElementNode { 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} attrs := map[string]bool{"href": true, "src": true, "action": true, "data": true}
for i, attr := range n.Attr { for i, attr := range n.Attr {