mirror of
https://github.com/SagerNet/sing-geosite.git
synced 2025-02-06 12:52:42 +08:00
Merge category-*@cn to cn
This commit is contained in:
parent
563f703dde
commit
fc71b5c331
41
main.go
41
main.go
@ -239,6 +239,45 @@ func filterTags(data map[string][]geosite.Item) {
|
|||||||
os.Stderr.WriteString("merged " + strings.Join(mergedCodeMap, ",") + "\n")
|
os.Stderr.WriteString("merged " + strings.Join(mergedCodeMap, ",") + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mergeTags(data map[string][]geosite.Item) {
|
||||||
|
var codeList []string
|
||||||
|
for code := range data {
|
||||||
|
codeList = append(codeList, code)
|
||||||
|
}
|
||||||
|
var cnCodeList []string
|
||||||
|
for _, code := range codeList {
|
||||||
|
codeParts := strings.Split(code, "@")
|
||||||
|
if len(codeParts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if codeParts[1] != "cn" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(codeParts[0], "category-") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(codeParts[0], "-cn") || strings.HasSuffix(codeParts[0], "-!cn") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cnCodeList = append(cnCodeList, code)
|
||||||
|
}
|
||||||
|
newMap := make(map[geosite.Item]bool)
|
||||||
|
for _, item := range data["cn"] {
|
||||||
|
newMap[item] = true
|
||||||
|
}
|
||||||
|
for _, code := range cnCodeList {
|
||||||
|
for _, item := range data[code] {
|
||||||
|
newMap[item] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newList := make([]geosite.Item, 0, len(newMap))
|
||||||
|
for item := range newMap {
|
||||||
|
newList = append(newList, item)
|
||||||
|
}
|
||||||
|
data["cn"] = newList
|
||||||
|
println("merged cn categories: " + strings.Join(cnCodeList, ","))
|
||||||
|
}
|
||||||
|
|
||||||
func generate(release *github.RepositoryRelease, output string, cnOutput string, ruleSetOutput string) error {
|
func generate(release *github.RepositoryRelease, output string, cnOutput string, ruleSetOutput string) error {
|
||||||
vData, err := download(release)
|
vData, err := download(release)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -249,6 +288,7 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
filterTags(domainMap)
|
filterTags(domainMap)
|
||||||
|
mergeTags(domainMap)
|
||||||
outputPath, _ := filepath.Abs(output)
|
outputPath, _ := filepath.Abs(output)
|
||||||
os.Stderr.WriteString("write " + outputPath + "\n")
|
os.Stderr.WriteString("write " + outputPath + "\n")
|
||||||
outputFile, err := os.Create(output)
|
outputFile, err := os.Create(output)
|
||||||
@ -263,7 +303,6 @@ func generate(release *github.RepositoryRelease, output string, cnOutput string,
|
|||||||
cnCodes := []string{
|
cnCodes := []string{
|
||||||
"cn",
|
"cn",
|
||||||
"geolocation-!cn",
|
"geolocation-!cn",
|
||||||
"category-companies@cn",
|
|
||||||
}
|
}
|
||||||
cnDomainMap := make(map[string][]geosite.Item)
|
cnDomainMap := make(map[string][]geosite.Item)
|
||||||
for _, cnCode := range cnCodes {
|
for _, cnCode := range cnCodes {
|
||||||
|
Loading…
Reference in New Issue
Block a user