add another domain

This commit is contained in:
Gianni Carafa
2023-11-05 22:32:13 +01:00
parent 7b519c7016
commit a6ee6aebfc
2 changed files with 43 additions and 7 deletions

View File

@@ -164,7 +164,7 @@ func applyRules(domain string, path string, body string) string {
if rule.Domain != domain {
continue
}
if rule.Path != "" && !strings.HasPrefix(path, rule.Path) {
if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) {
continue
}
for _, regexRule := range rule.RegexRules {
@@ -180,7 +180,6 @@ func applyRules(domain string, path string, body string) string {
doc.Find(injection.Position).ReplaceWithHtml(injection.Replace)
}
if injection.Append != "" {
log.Println("Appending", injection.Append)
doc.Find(injection.Position).AppendHtml(injection.Append)
}
if injection.Prepend != "" {
@@ -202,10 +201,10 @@ type Rule struct {
}
type RuleSet []struct {
Domain string `yaml:"domain"`
Path string `yaml:"path,omitempty"`
GoogleCache bool `yaml:"googleCache,omitempty"`
RegexRules []Rule `yaml:"regexRules"`
Domain string `yaml:"domain"`
Paths []string `yaml:"paths,omitempty"`
GoogleCache bool `yaml:"googleCache,omitempty"`
RegexRules []Rule `yaml:"regexRules"`
Injections []struct {
Position string `yaml:"position"`
Append string `yaml:"append"`
@@ -213,3 +212,12 @@ type RuleSet []struct {
Replace string `yaml:"replace"`
} `yaml:"injections"`
}
func StringInSlice(s string, list []string) bool {
for _, x := range list {
if strings.HasPrefix(s, x) {
return true
}
}
return false
}