Skip to content

Commit

Permalink
Feat: implement new inclusion syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Apr 2, 2021
1 parent 60cae87 commit c2d1eaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- name: Append attribute rules
if: ${{ env.NeedToSync }}
run: |
echo "include:geolocation-!cn@cn" >> ./domain-list-community/data/cn
echo "include:geolocation-cn@!cn" >> ./domain-list-community/data/geolocation-\!cn
echo "include:geolocation-!cn @cn" >> ./domain-list-community/data/cn
echo "include:geolocation-cn @!cn" >> ./domain-list-community/data/geolocation-\!cn
- name: Get dependencies and run
if: ${{ env.NeedToSync }}
Expand Down
15 changes: 9 additions & 6 deletions listinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type ListInfo struct {
// NewListInfo return a ListInfo
func NewListInfo() *ListInfo {
return &ListInfo{
HasInclusion: false,
InclusionAttributeMap: make(map[fileName][]attribute),
FullTypeList: make([]*router.Domain, 0, 10),
KeywordTypeList: make([]*router.Domain, 0, 10),
Expand Down Expand Up @@ -123,11 +122,15 @@ func (l *ListInfo) parseDomain(domain string, rule *router.Domain) error {
case 1: // Inclusion without attribute
// Use '@' as the placeholder attribute for 'include:filename'
l.InclusionAttributeMap[filename] = append(l.InclusionAttributeMap[filename], attribute("@"))
case 2: // Inclusion with attribute
// Added in this format: '@cn'
l.InclusionAttributeMap[filename] = append(l.InclusionAttributeMap[filename], attribute("@"+strings.TrimSpace(kv2[1])))
default:
return errors.New("invalid format for inclusion: " + domain)
default: // Inclusion with attribute(s)
// support new inclusion syntax, eg: `include:google @cn @gfw`
for _, attr := range kv2[1:] {
attr = strings.ToLower(strings.TrimSpace(attr))
if attr != "" {
// Added in this format: '@cn'
l.InclusionAttributeMap[filename] = append(l.InclusionAttributeMap[filename], attribute("@"+attr))
}
}
}
default: // line begins with "full" / "domain" / "regexp" / "keyword"
rule.Value = strings.ToLower(ruleVal)
Expand Down

0 comments on commit c2d1eaa

Please sign in to comment.