feat: address-change 301 (tracer)
- golem15_seo_redirects table and Redirect model - AddressChanged: old -> new 301 in the save transaction, earlier redirects pointed at the new address, self-loops dropped - the SEO tab save compares descriptor URLs with the entry URLs and answers the redirects.auto_created notice - resolve answers redirect with the absolute target for an exact source
This commit is contained in:
@@ -46,19 +46,22 @@ const (
|
||||
SourceDefault = "default"
|
||||
)
|
||||
|
||||
// Result is the effective SEO of one URL. Action is ok or not_found; Status
|
||||
// is the HTTP status the frontend should answer with. URL is the absolute
|
||||
// URL of the page (path and kept query on the site URL). Sources maps each
|
||||
// value name (title, description, canonical, robots, og_title,
|
||||
// og_description, og_image) to where it came from.
|
||||
// Result is the effective SEO of one URL. Action is ok, not_found,
|
||||
// redirect or gone; Status is the HTTP status the frontend should answer
|
||||
// with. URL is the absolute URL of the page (path and kept query on the
|
||||
// site URL). Sources maps each value name (title, description, canonical,
|
||||
// robots, og_title, og_description, og_image) to where it came from.
|
||||
type Result struct {
|
||||
Action string `json:"action"`
|
||||
Status int `json:"status"`
|
||||
URL string `json:"url"`
|
||||
Locale string `json:"locale"`
|
||||
Staging bool `json:"staging"`
|
||||
SEO *SEO `json:"seo"`
|
||||
Sources map[string]string `json:"-"`
|
||||
Action string `json:"action"`
|
||||
Status int `json:"status"`
|
||||
// Location is the absolute address a redirect answer sends the visitor
|
||||
// to; absent on every other action.
|
||||
Location string `json:"location,omitempty"`
|
||||
URL string `json:"url"`
|
||||
Locale string `json:"locale"`
|
||||
Staging bool `json:"staging"`
|
||||
SEO *SEO `json:"seo"`
|
||||
Sources map[string]string `json:"-"`
|
||||
// TypeKey and RecordID name the record behind the URL, "" when none.
|
||||
TypeKey string `json:"-"`
|
||||
RecordID string `json:"-"`
|
||||
@@ -357,6 +360,13 @@ func (r *Resolver) Resolve(ctx context.Context, rawURL string) (Result, error) {
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
redirect, err := exactRedirect(db, path)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
if redirect != nil {
|
||||
return r.redirectAnswer(svc.SiteURL()+path, *redirect), nil
|
||||
}
|
||||
key, match, rec, err := r.lookup(ctx, path)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
@@ -557,6 +567,19 @@ func (r *Resolver) resolveAt(ctx context.Context, db *gorm.DB, settings models.S
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// redirectAnswer is the answer of a matched redirect: gone for a 410,
|
||||
// else redirect with the rule's status and its target absolute on the
|
||||
// site URL.
|
||||
func (r *Resolver) redirectAnswer(self string, rule models.Redirect) Result {
|
||||
res := Result{URL: self, Staging: r.Service.Staging(), Sources: map[string]string{}}
|
||||
if rule.Status == models.Status410 {
|
||||
res.Action, res.Status = ActionGone, models.Status410
|
||||
return res
|
||||
}
|
||||
res.Action, res.Status, res.Location = ActionRedirect, rule.Status, AbsoluteURL(r.Service.SiteURL(), rule.Target)
|
||||
return res
|
||||
}
|
||||
|
||||
// rawQueryOf returns the raw query of the resolver input.
|
||||
func rawQueryOf(raw string) string {
|
||||
u, err := url.Parse(strings.TrimSpace(raw))
|
||||
|
||||
Reference in New Issue
Block a user