feat: SEO change history
This commit is contained in:
@@ -129,7 +129,7 @@ func (s *Service) SaveRecord(ctx context.Context, db *gorm.DB, in RecordWrite) (
|
||||
for locale, e := range existing {
|
||||
before[locale] = e
|
||||
}
|
||||
urls := s.recordURLs(ctx, in.Type.Key, in.ID)
|
||||
described := s.recordLocales(ctx, in.Type.Key, in.ID)
|
||||
touched := map[string]models.Entry{}
|
||||
for column, perLocale := range in.Values {
|
||||
for locale, value := range perLocale {
|
||||
@@ -153,8 +153,8 @@ func (s *Service) SaveRecord(ctx context.Context, db *gorm.DB, in RecordWrite) (
|
||||
continue
|
||||
}
|
||||
e.TypeKey = in.Type.Key
|
||||
if u, ok := urls[locale]; ok {
|
||||
e.URL = u
|
||||
if l, ok := described[locale]; ok {
|
||||
e.URL = l.URL
|
||||
}
|
||||
if e.ID == 0 {
|
||||
if err := db.Create(&e).Error; err != nil {
|
||||
@@ -164,10 +164,37 @@ func (s *Service) SaveRecord(ctx context.Context, db *gorm.DB, in RecordWrite) (
|
||||
return nil, nil, err
|
||||
}
|
||||
after[locale] = e
|
||||
var old map[string]any
|
||||
if stored {
|
||||
old = entryValues(existing[locale])
|
||||
}
|
||||
if err := s.Record(ctx, db, Change{
|
||||
Kind: models.SubjectEntry,
|
||||
SubjectID: EntrySubject(modelType, in.ID, locale),
|
||||
What: s.recordWhat(in.Type, in.ID, described[locale], locale),
|
||||
Before: old,
|
||||
After: entryValues(e),
|
||||
}); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
return before, after, nil
|
||||
}
|
||||
|
||||
// recordWhat is the history description of a record's SEO in a locale:
|
||||
// "SEO of <type> “<title>” (<locale>)".
|
||||
func (s *Service) recordWhat(typ pact.MenuItemType, id string, l pact.ContentLocale, locale string) string {
|
||||
title := l.Title
|
||||
if strings.TrimSpace(title) == "" {
|
||||
title = "#" + id
|
||||
}
|
||||
return s.Phrase("golem15.seo::lang.history.what_record", map[string]string{
|
||||
"type": s.Phrase(typ.Label, nil),
|
||||
"title": title,
|
||||
"locale": locale,
|
||||
})
|
||||
}
|
||||
|
||||
// entryEmpty reports whether no editable column of e carries a value.
|
||||
func entryEmpty(e models.Entry) bool {
|
||||
for _, column := range EntryColumns {
|
||||
@@ -178,10 +205,10 @@ func entryEmpty(e models.Entry) bool {
|
||||
return len(e.Data) == 0
|
||||
}
|
||||
|
||||
// recordURLs returns the record's public path per locale through its
|
||||
// content descriptor; an error or a missing registry answers none.
|
||||
func (s *Service) recordURLs(ctx context.Context, key, id string) map[string]string {
|
||||
out := map[string]string{}
|
||||
// recordLocales describes the record per locale through its content
|
||||
// descriptor; an error or a missing registry answers none.
|
||||
func (s *Service) recordLocales(ctx context.Context, key, id string) map[string]pact.ContentLocale {
|
||||
out := map[string]pact.ContentLocale{}
|
||||
reg := s.Registry()
|
||||
if reg == nil {
|
||||
return out
|
||||
@@ -191,7 +218,7 @@ func (s *Service) recordURLs(ctx context.Context, key, id string) map[string]str
|
||||
return out
|
||||
}
|
||||
for _, l := range rec.Locales {
|
||||
out[l.Locale] = l.URL
|
||||
out[l.Locale] = l
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user