From 1ad506c3820a08c10a9069bf1db9862f55508195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 15 May 2024 21:47:52 +0800 Subject: [PATCH] documentation: Add new rule-set --- docs/configuration/shared/rule-set.md | 80 +++++++++++++++++++++++++++ docs/configuration/template.md | 9 ++- mkdocs.yml | 2 + option/template.go | 10 ++-- template/render_geo_resources.go | 5 +- 5 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 docs/configuration/shared/rule-set.md diff --git a/docs/configuration/shared/rule-set.md b/docs/configuration/shared/rule-set.md new file mode 100644 index 0000000..51230d0 --- /dev/null +++ b/docs/configuration/shared/rule-set.md @@ -0,0 +1,80 @@ +# RuleSet + +RuleSet generate configuration. + +### Structure + +=== "Default" + + ```json + { + "type": "", // optional + + ... // Default Fields + } + ``` + +=== "GitHub" + + ```json + { + "type": "github", + "repository": "", + "path": "", + "rule-set": [] + } + ``` + +=== "Example" + + ```json + { + "type": "github", + "repository": "SagerNet/sing-geosite", + "path": "rule-set", + "prefix": "geosite-", + "rule-set": [ + "apple", + "microsoft", + "openai" + ] + } + ``` + +=== "Example (Clash.Meta repository)" + + ```json + { + "type": "github", + "repository": "MetaCubeX/meta-rules-dat", + "path": "sing/geo/geosite", + "prefix": "geosite-", + "rule-set": [ + "apple", + "microsoft", + "openai" + ] + } + ``` + +### Default Fields + +See [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/). + +### GitHub Fields + +#### repository + +GitHub repository, `SagerNet/sing-` or `MetaCubeX/meta-rules-dat`. + +#### path + +Branch and directory path, `rule-set` or `sing/geo/`. + +#### prefix + +File prefix, `geoip-` or `geosite-`. + +#### rule-set + +RuleSet name list. diff --git a/docs/configuration/template.md b/docs/configuration/template.md index fc9a326..06996bd 100644 --- a/docs/configuration/template.md +++ b/docs/configuration/template.md @@ -3,6 +3,7 @@ ```json { "name": "", + "extend": "", // Global @@ -83,6 +84,10 @@ Profile name. +#### extend + +Extend from another profile. + #### log Log configuration, see [Log](https://sing-box.sagernet.org/configuration/log/). @@ -249,13 +254,13 @@ Custom [GeoSite](https://sing-box.sagernet.org/configuration/route/geosite/) tem #### custom_rule_set -List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/). +List of [RuleSet](/configuration/shared/rule-set/). Default rule sets will not be generated if not empty. #### post_rule_set -List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/). +List of [RuleSet](/configuration/shared/rule-set/). Will be applied after default rule sets. diff --git a/mkdocs.yml b/mkdocs.yml index 501dcaf..df2d4db 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -50,6 +50,8 @@ nav: - Template: configuration/template.md - Profile: configuration/profile.md - User: configuration/user.md + - Shared: + - RuleSet: configuration/shared/rule-set.md markdown_extensions: - pymdownx.inlinehilite - pymdownx.snippets diff --git a/option/template.go b/option/template.go index 863a230..81c8ffa 100644 --- a/option/template.go +++ b/option/template.go @@ -113,12 +113,10 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error { } type GitHubRuleSetOptions struct { - Owner string `json:"owner,omitempty"` - Repo string `json:"repo,omitempty"` - Branch string `json:"branch,omitempty"` - Path string `json:"path,omitempty"` - Prefix string `json:"prefix,omitempty"` - RuleSet option.Listable[string] `json:"rule_set,omitempty"` + Repository string `json:"repository,omitempty"` + Path string `json:"path,omitempty"` + Prefix string `json:"prefix,omitempty"` + RuleSet option.Listable[string] `json:"rule_set,omitempty"` } func (t Template) DisableIPv6() bool { diff --git a/template/render_geo_resources.go b/template/render_geo_resources.go index a53d2c7..b15d08e 100644 --- a/template/render_geo_resources.go +++ b/template/render_geo_resources.go @@ -117,6 +117,7 @@ func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet downloadURL = "https://raw.githubusercontent.com/" branchSplit = "/" } + for _, code := range ruleSet.GitHubOptions.RuleSet { result = append(result, boxOption.RuleSet{ Type: C.RuleSetTypeRemote, @@ -124,10 +125,8 @@ func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet Format: C.RuleSetFormatBinary, RemoteOptions: boxOption.RemoteRuleSet{ URL: downloadURL + - ruleSet.GitHubOptions.Owner + "/" + - ruleSet.GitHubOptions.Repo + + ruleSet.GitHubOptions.Repository + branchSplit + - ruleSet.GitHubOptions.Branch + "/" + ruleSet.GitHubOptions.Path + code + ".srs", DownloadDetour: downloadDetour,