- migration 202610280004: image_file_no, kind, published_at and parent_refs on the slot table; the image, News, IndexNow and HTML sitemap settings - the rebuild stores each page's featured and body images (absolute on the site, deduplicated, at most 1000) and numbers the rows with images into sitemap-images-<n>.xml with the per-type files' stable rules - the index lists the image files while images_enabled is on; the files route serves them with image:image and image:loc only
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
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 <url> of an image sitemap lists
|
|
// (Google's limit).
|
|
const MaxImagesPerURL = 1000
|
|
|
|
// ImagesGroup is the file group of the image sitemaps:
|
|
// sitemap-images-<n>.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
|
|
}
|