修复: 网站预览资源路径+七牛目录层级
This commit is contained in:
@@ -898,7 +898,10 @@ var sa=Element.prototype.setAttribute;
|
||||
Element.prototype.setAttribute=function(n,v){if((n==='src'||n==='href'||n==='data'||n==='poster')&&typeof v==='string')v=rw(v);return sa.call(this,n,v);};
|
||||
try{var d=Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype,'src');Object.defineProperty(HTMLScriptElement.prototype,'src',{set:function(v){d.set.call(this,rw(v))},get:d.get,configurable:true});}catch(e){}
|
||||
try{var d2=Object.getOwnPropertyDescriptor(HTMLLinkElement.prototype,'href');Object.defineProperty(HTMLLinkElement.prototype,'href',{set:function(v){d2.set.call(this,rw(v))},get:d2.get,configurable:true});}catch(e){}
|
||||
})();
|
||||
try{var d3=Object.getOwnPropertyDescriptor(HTMLImageElement.prototype,'src');Object.defineProperty(HTMLImageElement.prototype,'src',{set:function(v){d3.set.call(this,rw(v))},get:d3.get,configurable:true});}catch(e){}
|
||||
try{var d4=Object.getOwnPropertyDescriptor(HTMLSourceElement.prototype,'src');Object.defineProperty(HTMLSourceElement.prototype,'src',{set:function(v){d4.set.call(this,rw(v))},get:d4.get,configurable:true});}catch(e){}
|
||||
try{var d5=Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype,'src');Object.defineProperty(HTMLIFrameElement.prototype,'src',{set:function(v){d5.set.call(this,rw(v))},get:d5.get,configurable:true});}catch(e){}
|
||||
})();
|
||||
</script>`
|
||||
|
||||
// 在 <head> 后立即插入(确保在任何其他脚本之前执行)
|
||||
|
||||
47
internal/filesystem/site_resource.go
Normal file
47
internal/filesystem/site_resource.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
htmlResRegex = regexp.MustCompile(`(?:src|href|data|poster)=["']([^"']+)["']`)
|
||||
htmlCssUrlRe = regexp.MustCompile(`url\(\s*["']?([^"')]+)["']?\s*\)`)
|
||||
)
|
||||
|
||||
// ExtractHtmlResources 从 HTML 内容提取资源路径
|
||||
func ExtractHtmlResources(html string) []string {
|
||||
seen := make(map[string]bool)
|
||||
var resources []string
|
||||
add := func(v string) {
|
||||
v = strings.TrimSpace(v)
|
||||
if v != "" && !seen[v] {
|
||||
seen[v] = true
|
||||
resources = append(resources, v)
|
||||
}
|
||||
}
|
||||
for _, m := range htmlResRegex.FindAllStringSubmatch(html, -1) {
|
||||
if len(m) > 1 {
|
||||
add(m[1])
|
||||
}
|
||||
}
|
||||
for _, m := range htmlCssUrlRe.FindAllStringSubmatch(html, -1) {
|
||||
if len(m) > 1 {
|
||||
add(m[1])
|
||||
}
|
||||
}
|
||||
return resources
|
||||
}
|
||||
|
||||
// ShouldSkipResource 判断资源路径是否应跳过
|
||||
func ShouldSkipResource(p string) bool {
|
||||
return strings.HasPrefix(p, "data:") ||
|
||||
strings.HasPrefix(p, "http://") ||
|
||||
strings.HasPrefix(p, "https://") ||
|
||||
strings.HasPrefix(p, "//") ||
|
||||
strings.HasPrefix(p, "#") ||
|
||||
strings.HasPrefix(p, "javascript:") ||
|
||||
strings.HasPrefix(p, "mailto:") ||
|
||||
strings.HasPrefix(p, "blob:")
|
||||
}
|
||||
Reference in New Issue
Block a user