Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Add New Video Only #29

Merged
merged 2 commits into from
Jun 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions util/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}