package classes import ( "strings" "git.golem15.com/golem15/sm-sitemap-plugin/models" "git.golem15.com/golem15/summercms/modules/pact" ) // MaxImagesPerURL is the most images one of an image sitemap lists // (Google's limit). const MaxImagesPerURL = 1000 // ImagesGroup is the file group of the image sitemaps: // sitemap-images-.xml. No content type may use it (ReservedSlugs). const ImagesGroup = "images" // PageImages lists the images of one locale of a record for the image // sitemap (D-31): the featured Image first, then Images in document order, // each a path on the site or an absolute http(s) URL (a protocol-relative // //host/... address is read as https). Another value (a data: or // javascript: URL, a relative path) is skipped, and an address is listed // once, compared as absolute on site. At most MaxImagesPerURL are kept. func PageImages(l pact.ContentLocale, site string) []string { out := []string{} seen := map[string]bool{} add := func(u string) { u = strings.TrimSpace(u) if strings.HasPrefix(u, "//") { u = "https:" + u } if u == "" || !models.AllowedAddress(u) { return } key := u if abs := Absolute(site, u); abs != "" { key = abs } if seen[key] || len(out) >= MaxImagesPerURL { return } seen[key] = true out = append(out, u) } add(l.Image) for _, img := range l.Images { add(img.URL) } return out }