feat: image sitemap files (tracer)
- 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
This commit is contained in:
@@ -27,6 +27,15 @@ const errFrontendURL = "golem15.sitemap::lang.errors.frontend_url"
|
||||
// the last rebuild asked for from the admin. The Phase 17 columns
|
||||
// (frontend_url, priorities, tiers, the update manifest) stay in the table
|
||||
// and are no longer read (D-32).
|
||||
//
|
||||
// The image and News sitemaps, IndexNow and the HTML sitemap (D-31, D-34):
|
||||
// ImagesEnabled lists the sitemap-images files, NewsEnabled sitemap-news.xml
|
||||
// with NewsPublication (empty: app.name) and NewsSources (type:<key> and
|
||||
// category:<key>:<id> values; empty: every article type). IndexNowEnabled
|
||||
// notifies api.indexnow.org with IndexNowKey after each rebuild, and the
|
||||
// last answer is IndexNowLastAt, IndexNowLastCount and IndexNowLastStatus.
|
||||
// HTMLEnabled serves the HTML sitemap API, HTMLPaths is the site's HTML
|
||||
// sitemap address per locale and HTMLPageSize the links per page.
|
||||
type Settings struct {
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
SiteURL *string `gorm:"column:site_url"`
|
||||
@@ -37,6 +46,19 @@ type Settings struct {
|
||||
NumberedSize *int `gorm:"column:numbered_size"`
|
||||
BuiltAt *time.Time `gorm:"column:built_at"`
|
||||
RebuildRequestedAt *time.Time `gorm:"column:rebuild_requested_at"`
|
||||
|
||||
ImagesEnabled bool `gorm:"column:images_enabled"`
|
||||
NewsEnabled bool `gorm:"column:news_enabled"`
|
||||
NewsPublication *string `gorm:"column:news_publication"`
|
||||
NewsSources lagoon.Jsonable[[]string] `gorm:"column:news_sources"`
|
||||
IndexNowEnabled bool `gorm:"column:indexnow_enabled"`
|
||||
IndexNowKey *string `gorm:"column:indexnow_key"`
|
||||
IndexNowLastAt *time.Time `gorm:"column:indexnow_last_at"`
|
||||
IndexNowLastCount *int `gorm:"column:indexnow_last_count"`
|
||||
IndexNowLastStatus *int `gorm:"column:indexnow_last_status"`
|
||||
HTMLEnabled bool `gorm:"column:html_enabled"`
|
||||
HTMLPaths lagoon.Jsonable[map[string]string] `gorm:"column:html_paths"`
|
||||
HTMLPageSize int `gorm:"column:html_page_size"`
|
||||
}
|
||||
|
||||
// DefaultFileSize is the number of addresses per sitemap file when the
|
||||
@@ -151,7 +173,55 @@ func AllowedFrontendURL(u string) bool {
|
||||
|
||||
// DefaultSettings is the settings read when no row is stored.
|
||||
func DefaultSettings() Settings {
|
||||
return Settings{ID: 1, FileSize: DefaultFileSize}
|
||||
return Settings{ID: 1, FileSize: DefaultFileSize, ImagesEnabled: true, HTMLEnabled: true, HTMLPageSize: DefaultHTMLPageSize}
|
||||
}
|
||||
|
||||
// The HTML sitemap's links per page: DefaultHTMLPageSize when not stored,
|
||||
// MinHTMLPageSize to MaxHTMLPageSize when set (UI-SPEC C26).
|
||||
const (
|
||||
DefaultHTMLPageSize = 150
|
||||
MinHTMLPageSize = 50
|
||||
MaxHTMLPageSize = 500
|
||||
)
|
||||
|
||||
// DefaultHTMLPaths are the HTML sitemap's addresses when none is stored.
|
||||
func DefaultHTMLPaths() map[string]string {
|
||||
return map[string]string{"pl": "/mapa-strony", "en": "/sitemap"}
|
||||
}
|
||||
|
||||
// EffectiveHTMLPageSize is the stored page size, or DefaultHTMLPageSize
|
||||
// when it is outside MinHTMLPageSize..MaxHTMLPageSize.
|
||||
func (s Settings) EffectiveHTMLPageSize() int {
|
||||
if s.HTMLPageSize < MinHTMLPageSize || s.HTMLPageSize > MaxHTMLPageSize {
|
||||
return DefaultHTMLPageSize
|
||||
}
|
||||
return s.HTMLPageSize
|
||||
}
|
||||
|
||||
// EffectiveHTMLPaths are the stored HTML sitemap addresses without blank
|
||||
// ones, or DefaultHTMLPaths when none is stored.
|
||||
func (s Settings) EffectiveHTMLPaths() map[string]string {
|
||||
out := map[string]string{}
|
||||
for locale, path := range s.HTMLPaths.Get() {
|
||||
if p := strings.TrimSpace(path); p != "" && strings.TrimSpace(locale) != "" {
|
||||
out[locale] = p
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return DefaultHTMLPaths()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Sources returns the News sources without blank values.
|
||||
func (s Settings) Sources() []string {
|
||||
var out []string
|
||||
for _, v := range s.NewsSources.Get() {
|
||||
if v = strings.TrimSpace(v); v != "" {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -32,11 +32,23 @@ type Alternate struct {
|
||||
Href string `json:"href"`
|
||||
}
|
||||
|
||||
// Ref points at a record: Type is its content type key and ID the record's
|
||||
// ID within it (pact.ContentRef as stored in parent_refs).
|
||||
type Ref struct {
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// URL is one row of the slot table golem15_sitemap_urls (D-30): an address
|
||||
// of a content type's record in one locale, or an additional address. Grp
|
||||
// and FileNo place it in the file sitemap-<grp>-<file_no>.xml; FileNo is
|
||||
// nil until the address is numbered. ExcludedReason is "" for a listed
|
||||
// address; a row left out keeps its FileNo, so its file keeps a hole.
|
||||
// Images are the page's image addresses (D-31), ImageFileNo the number of
|
||||
// its sitemap-images file (nil while it has none). Kind is the content
|
||||
// type's kind (pact.ContentKindArticle and the others), PublishedAt the
|
||||
// record's first publication and ParentRefs its parents, for the News
|
||||
// sitemap and the HTML sitemap.
|
||||
type URL struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey"`
|
||||
Grp string `gorm:"column:grp"`
|
||||
@@ -50,6 +62,10 @@ type URL struct {
|
||||
LastMod *time.Time `gorm:"column:lastmod"`
|
||||
Alternates lagoon.Jsonable[[]Alternate] `gorm:"column:alternates"`
|
||||
Images lagoon.Jsonable[[]string] `gorm:"column:images"`
|
||||
ImageFileNo *int `gorm:"column:image_file_no"`
|
||||
Kind string `gorm:"column:kind"`
|
||||
PublishedAt *time.Time `gorm:"column:published_at"`
|
||||
ParentRefs lagoon.Jsonable[[]Ref] `gorm:"column:parent_refs"`
|
||||
ExcludedReason string `gorm:"column:excluded_reason"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user