From 0d3d59434157b3e6cf1f5609e37231ce14e3ed05 Mon Sep 17 00:00:00 2001 From: Dirk Kelly Date: Sat, 22 Jun 2019 11:48:14 +0800 Subject: [PATCH 1/2] Add New Video Only --- util/channel.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 +} From 292b2964572fbaab63ea3012ebe97ef23263da67 Mon Sep 17 00:00:00 2001 From: Josh Michielsen Date: Sat, 22 Jun 2019 13:32:39 +0100 Subject: [PATCH 2/2] Remove goimports from .golangci.yml --- .golangci.yml | 2 -- 1 file changed, 2 deletions(-) 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: