package classes import ( "strings" "git.golem15.com/golem15/sm-seo-plugin/models" "gorm.io/gorm" ) // The resolve actions of the redirect stage. const ( ActionRedirect = "redirect" ActionGone = "gone" ) // exactRedirect returns the exact redirect whose source is path, nil when // there is none. func exactRedirect(db *gorm.DB, path string) (*models.Redirect, error) { var rows []models.Redirect if err := db.Where("match = ? AND source = ?", models.RedirectExact, path).Limit(1).Find(&rows).Error; err != nil { return nil, err } if len(rows) == 0 { return nil, nil } return &rows[0], nil } // RedirectValues are a redirect's values for history. func RedirectValues(r models.Redirect) map[string]any { return map[string]any{ "source": r.Source, "match": r.Match, "target": r.Target, "status": r.Status, "query": r.Query, "ignore_case": r.IgnoreCase, "trailing_slash": r.TrailingSlash, "origin": r.Origin, "note": r.Note, } } // redirectWhat is the history description of a redirect. func (s *Service) redirectWhat(r models.Redirect) string { return s.Phrase("golem15.seo::lang.history.what_redirect", map[string]string{"url": r.Source}) } // samePath reports whether target names path on this site: the path // itself, or an absolute URL on the site URL with that path. func (s *Service) samePath(target, path string) bool { target = strings.TrimSpace(target) if target == path { return true } site := s.SiteURL() return site != "" && target == site+path }