call it with:
go run remove-script-tag.go **.html
| package main | |
| import ( | |
| "os" | |
| "regexp" | |
| "strings" | |
| ) | |
| func main() { | |
| for i := 0; i < len(os.Args); i++ { | |
| path := os.Args[i] | |
| scriptRe := regexp.MustCompile(`(?s)<script.*<\/script>`) | |
| endScriptRe := regexp.MustCompile(`</script>`) | |
| file, _ := os.ReadFile(path) | |
| text := string(file) | |
| result := scriptRe.ReplaceAllStringFunc(text, func(s string) string { | |
| index := endScriptRe.FindStringIndex(s) | |
| return strings.TrimSpace(s[index[1]:]) | |
| }) | |
| os.WriteFile(path, []byte(result), 0644) | |
| } | |
| } |