diff --git a/README.md b/README.md index aa34d3b..b53d7eb 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,15 @@ data 为 base64 URL 编码(将编码字符串中`/`替换为`_`,`+`替换为`- "template": "模板路径/网络地址", "delete": "", "rename": {"原文本": "新文本"}, - "group": false, "group-type": "selector", "sort": "name", "sort-type": "asc" } ``` +该 JSON 同时可用于 `convert` 的 `--config` 参数,以便本地生成 sing-box 配置。 +例如将上方 JSON 内容存放于 `config.json` 后执行 `sub2sing-box convert -c ./config.json` 即可生成 sing-box 配置,免去每次生成时重复设置参数 + ## Template 占位符 - ``: 插入所有节点标签 diff --git a/cmd/convert.go b/cmd/convert.go index 834781d..39c89a2 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -19,7 +19,6 @@ var ( output string delete string rename map[string]string - group bool groupType string sortKey string sortType string @@ -33,7 +32,6 @@ func init() { convertCmd.Flags().StringVarP(&output, "output", "o", "", "output file path") convertCmd.Flags().StringVarP(&delete, "delete", "d", "", "delete proxy with regex") convertCmd.Flags().StringToStringVarP(&rename, "rename", "r", nil, "rename proxy with regex") - convertCmd.Flags().BoolVarP(&group, "group", "g", false, "group proxies by country") convertCmd.Flags().StringVarP(&groupType, "group-type", "G", "selector", "group type, selector or urltest") convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "tag", "sort key, tag or num") convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "asc", "sort type, asc or desc") diff --git a/common/convert.go b/common/convert.go index 61e5de0..c62c0df 100644 --- a/common/convert.go +++ b/common/convert.go @@ -90,7 +90,13 @@ func Convert( return "", err } reg := regexp.MustCompile("\"<[A-Za-z]{2}>\"") - if reg.MatchString(templateDate) || strings.Contains(templateDate, constant.AllCountryTags) { + group := false + for _, v := range model.CountryEnglishName { + if strings.Contains(templateDate, v) { + group = true + } + } + if reg.MatchString(templateDate) || strings.Contains(templateDate, constant.AllCountryTags) || group { outbounds = AddCountryGroup(outbounds, groupType, sortKey, sortType) } var template model.Config