diff --git a/.golangci.yml b/.golangci.yml index ee7037f..68e0c4e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,8 +22,6 @@ output: linters: fast: true - enable: - - goimports # all available settings of specific linters linters-settings: diff --git a/util/channel.go b/util/channel.go index 990f886..7b18330 100644 --- a/util/channel.go +++ b/util/channel.go @@ -380,9 +380,12 @@ func CreateChannelPage(channel *Channel, projectRoot string) error { return nil } -// AddVideo adds a video to the channel page and saves it -func (cp *ChannelPage) AddVideo(id, projectRoot string) error { - cp.Videos = append(cp.Videos, id) +// AddVideo adds a new video to the channel page and saves it +func (cp *ChannelPage) AddVideo(id string, projectRoot string) error { + if !contains(cp.Videos, id) { + cp.Videos = append(cp.Videos, id) + } + err := cp.save(projectRoot) if err != nil { return err @@ -407,3 +410,13 @@ func (cp *ChannelPage) save(projectRoot string) error { return nil } + +// https://ispycode.com/GO/Collections/Arrays/Check-if-item-is-in-array +func contains(arr []string, str string) bool { + for _, a := range arr { + if a == str { + return true + } + } + return false +}