Skip to content

Commit

Permalink
Add format field to rule-providers in clash config based on file exte…
Browse files Browse the repository at this point in the history
…nsion (#641)
  • Loading branch information
jimlee2048 committed Feb 14, 2024
1 parent eef5328 commit 3b41a7e
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/generator/template/templates.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,17 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
if (url.ends_with(".list") || url.ends_with(".txt")) {
base_rule["rule-providers"][yaml_key]["format"] = "text";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".list";
}
else if (url.ends_with(".yaml") || url.ends_with(".yml")) {
base_rule["rule-providers"][yaml_key]["format"] = "yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
else {
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}
Expand All @@ -510,7 +520,17 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
if (url.ends_with(".list") || url.ends_with(".txt")) {
base_rule["rule-providers"][yaml_key]["format"] = "text";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".list";
}
else if (url.ends_with(".yaml") || url.ends_with(".yml")) {
base_rule["rule-providers"][yaml_key]["format"] = "yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
else {
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}
Expand All @@ -523,7 +543,17 @@ int renderClashScript(YAML::Node &base_rule, std::vector<RulesetContent> &rulese
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
else
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlSafeBase64Encode(url);
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
if (url.ends_with(".list") || url.ends_with(".txt")) {
base_rule["rule-providers"][yaml_key]["format"] = "text";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".list";
}
else if (url.ends_with(".yaml") || url.ends_with(".yml")) {
base_rule["rule-providers"][yaml_key]["format"] = "yaml";
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
else {
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
}
if(interval)
base_rule["rule-providers"][yaml_key]["interval"] = interval;
}
Expand Down

0 comments on commit 3b41a7e

Please sign in to comment.