diff --git a/docs/configuration/template.md b/docs/configuration/template.md index 2593df7..c930d42 100644 --- a/docs/configuration/template.md +++ b/docs/configuration/template.md @@ -55,6 +55,7 @@ "custom_geoip": {}, "custom_geosite": {}, "custom_rule_set": [], + "post_custom_rule_set": [], // Experimental @@ -242,6 +243,12 @@ List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/). Default rule sets will not be generated if not empty. +#### post_custom_rule_set + +List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/). + +Will be applied after default rule sets. + #### disable_cache_file Don't generate `cache_file` related options. diff --git a/option/template.go b/option/template.go index 9590f37..e497292 100644 --- a/option/template.go +++ b/option/template.go @@ -50,6 +50,7 @@ type Template struct { CustomGeoIP *option.GeoIPOptions `json:"custom_geoip,omitempty"` CustomGeosite *option.GeositeOptions `json:"custom_geosite,omitempty"` CustomRuleSet []option.RuleSet `json:"custom_rule_set,omitempty"` + PostCustomRuleSet []option.RuleSet `json:"post_custom_rule_set,omitempty"` // Experimental DisableCacheFile bool `json:"disable_cache_file,omitempty"` diff --git a/template/render_geo_resources.go b/template/render_geo_resources.go index 4fa890e..1c080af 100644 --- a/template/render_geo_resources.go +++ b/template/render_geo_resources.go @@ -38,52 +38,55 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio DownloadDetour: downloadDetour, } } - } else if len(t.CustomRuleSet) == 0 { - var ( - downloadURL string - downloadDetour string - branchSplit string - ) - if t.EnableJSDelivr { - downloadURL = "https://testingcf.jsdelivr.net/gh/" - if t.DirectTag != "" { - downloadDetour = t.DirectTag + } else { + if len(t.CustomRuleSet) == 0 { + var ( + downloadURL string + downloadDetour string + branchSplit string + ) + if t.EnableJSDelivr { + downloadURL = "https://testingcf.jsdelivr.net/gh/" + if t.DirectTag != "" { + downloadDetour = t.DirectTag + } else { + downloadDetour = DefaultDirectTag + } + branchSplit = "@" } else { - downloadDetour = DefaultDirectTag + downloadURL = "https://raw.githubusercontent.com/" + branchSplit = "/" + } + options.Route.RuleSet = []option.RuleSet{ + { + Type: C.RuleSetTypeRemote, + Tag: "geoip-cn", + Format: C.RuleSetFormatBinary, + RemoteOptions: option.RemoteRuleSet{ + URL: downloadURL + "SagerNet/sing-geoip" + branchSplit + "rule-set/geoip-cn.srs", + DownloadDetour: downloadDetour, + }, + }, + { + Type: C.RuleSetTypeRemote, + Tag: "geosite-geolocation-cn", + Format: C.RuleSetFormatBinary, + RemoteOptions: option.RemoteRuleSet{ + URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-cn.srs", + DownloadDetour: downloadDetour, + }, + }, + { + Type: C.RuleSetTypeRemote, + Tag: "geosite-geolocation-!cn", + Format: C.RuleSetFormatBinary, + RemoteOptions: option.RemoteRuleSet{ + URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-!cn.srs", + DownloadDetour: downloadDetour, + }, + }, } - branchSplit = "@" - } else { - downloadURL = "https://raw.githubusercontent.com/" - branchSplit = "/" - } - options.Route.RuleSet = []option.RuleSet{ - { - Type: C.RuleSetTypeRemote, - Tag: "geoip-cn", - Format: C.RuleSetFormatBinary, - RemoteOptions: option.RemoteRuleSet{ - URL: downloadURL + "SagerNet/sing-geoip" + branchSplit + "rule-set/geoip-cn.srs", - DownloadDetour: downloadDetour, - }, - }, - { - Type: C.RuleSetTypeRemote, - Tag: "geosite-geolocation-cn", - Format: C.RuleSetFormatBinary, - RemoteOptions: option.RemoteRuleSet{ - URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-cn.srs", - DownloadDetour: downloadDetour, - }, - }, - { - Type: C.RuleSetTypeRemote, - Tag: "geosite-geolocation-!cn", - Format: C.RuleSetFormatBinary, - RemoteOptions: option.RemoteRuleSet{ - URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-!cn.srs", - DownloadDetour: downloadDetour, - }, - }, } + options.Route.RuleSet = append(options.Route.RuleSet, t.PostCustomRuleSet...) } }