Market import: fill entries in from their websites
A list of just websites and relationships (url:, website:, or a bare address) can be imported with "Fill in the empty boxes from each website": each entry is filled in as on New entry, in the background a few at a time, and saved straight into the Market. Entries already there, by name or website, are skipped before their site is read; the plan's limit is kept. The import page shows the progress and each entry's result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,41 @@ type Entry struct {
|
||||
Prices []Price `json:"prices,omitempty" yaml:"prices,omitempty"` // their plans' prices, as checked
|
||||
}
|
||||
|
||||
// UnmarshalYAML reads an entry as written, and two shorter forms for a
|
||||
// list to be filled in from the websites: `url:` or `website:` for one
|
||||
// address, and a bare address in place of the whole entry.
|
||||
func (e *Entry) UnmarshalYAML(n *yaml.Node) error {
|
||||
if n.Kind == yaml.ScalarNode {
|
||||
*e = Entry{Websites: []string{n.Value}}
|
||||
return nil
|
||||
}
|
||||
type plain Entry // without this method
|
||||
var aux struct {
|
||||
plain `yaml:",inline"`
|
||||
URL string `yaml:"url"`
|
||||
Website string `yaml:"website"`
|
||||
}
|
||||
if err := n.Decode(&aux); err != nil {
|
||||
return err
|
||||
}
|
||||
*e = Entry(aux.plain)
|
||||
for _, u := range []string{aux.Website, aux.URL} {
|
||||
if u = strings.TrimSpace(u); u != "" && !containsFold(e.Websites, u) {
|
||||
e.Websites = append([]string{u}, e.Websites...)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func containsFold(list []string, s string) bool {
|
||||
for _, v := range list {
|
||||
if strings.EqualFold(strings.TrimSpace(v), s) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Normalize tidies an entry and checks it.
|
||||
func (e *Entry) Normalize() error {
|
||||
e.Name = strings.TrimSpace(e.Name)
|
||||
|
||||
Reference in New Issue
Block a user