Skip to content

Commit

Permalink
documentation: Add new rule-set
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 15, 2024
1 parent 1396bde commit 1ad506c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 11 deletions.
80 changes: 80 additions & 0 deletions docs/configuration/shared/rule-set.md
Original file line number Diff line number Diff line change
@@ -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-<geoip/geosite>` or `MetaCubeX/meta-rules-dat`.

#### path

Branch and directory path, `rule-set` or `sing/geo/<geoip/geosite>`.

#### prefix

File prefix, `geoip-` or `geosite-`.

#### rule-set

RuleSet name list.
9 changes: 7 additions & 2 deletions docs/configuration/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```json
{
"name": "",
"extend": "",

// Global

Expand Down Expand Up @@ -83,6 +84,10 @@

Profile name.

#### extend

Extend from another profile.

#### log

Log configuration, see [Log](https://sing-box.sagernet.org/configuration/log/).
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions option/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions template/render_geo_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ 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,
Tag: ruleSet.GitHubOptions.Prefix + code,
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,
Expand Down

0 comments on commit 1ad506c

Please sign in to comment.