From 017649481612cfe12b6127ac8cac3afdcd7ab796 Mon Sep 17 00:00:00 2001 From: miyuko Date: Thu, 27 Aug 2026 01:51:08 +0100 Subject: [PATCH] Treat wildcard domains and preview domains as public suffixes. --- src/analysis.go | 7 +------ src/domains.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/domains.go diff --git a/src/analysis.go b/src/analysis.go index 19082d7..bc19945 100644 --- a/src/analysis.go +++ b/src/analysis.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "strings" - - "golang.org/x/net/publicsuffix" ) type StorageSize struct { @@ -32,10 +30,7 @@ func AnalyzeStorage(ctx context.Context) ([]*StorageSize, error) { thinStats := []*StorageSize{} getStats := func(domain string) *storageData { - eTLDPlusOne, err := publicsuffix.EffectiveTLDPlusOne(domain) - if err == nil { - domain = eTLDPlusOne - } + domain = EffectiveTLDPlusOne(domain) if _, found := thickStats[domain]; !found { thickStats[domain] = &storageData{ siteBlobs: map[string]int64{}, diff --git a/src/domains.go b/src/domains.go new file mode 100644 index 0000000..cdb2fb2 --- /dev/null +++ b/src/domains.go @@ -0,0 +1,29 @@ +package git_pages + +import ( + "slices" + "strings" + + "golang.org/x/net/publicsuffix" +) + +func EffectiveTLDPlusOne(domain string) string { + domainParts := strings.Split(domain, ".") + for _, pattern := range wildcards { + for _, suffix := range [][]string{pattern.PreviewDomain, pattern.Domain} { + if len(domainParts) < len(suffix)+1 { + continue + } + if slices.Equal(domainParts[len(domainParts)-len(suffix):], suffix) { + return strings.Join(domainParts[len(domainParts)-len(suffix)-1:], ".") + } + } + } + + result, err := publicsuffix.EffectiveTLDPlusOne(domain) + if err == nil { + return result + } + + return domain +}