Skip to content

Commit 6686a6d

Browse files
committed
Add speaker image creation feature
1 parent a10efd5 commit 6686a6d

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

cmd/sponsor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/spf13/cobra"
1717
)
1818

19+
var All string
20+
1921
// sponsorCmd represents the sponsor command
2022
var sponsorCmd = &cobra.Command{
2123
Use: "sponsor [name]",
@@ -128,7 +130,7 @@ func init() {
128130

129131
// Cobra supports local flags which will only run when this command
130132
// is called directly, e.g.:
131-
// sponsorCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
133+
showSponsorCmd.Flags().BoolP("all", "a", false, "Show all sponsors")
132134

133135
}
134136

create/speaker.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func CreateSpeaker(speakerName, city, year string) (err error) {
183183

184184
if (imageQuery == "Y") || (imageQuery == "y") {
185185
imagePath = CreateSpeakerImage(helpers.NameClean(name), city, year)
186+
fmt.Println(imagePath)
186187
} else {
187188
imagePath = ""
188189
}
@@ -252,7 +253,7 @@ func CreateSpeakerImage(speaker, city, year string) (imageFile string) {
252253
return fmt.Errorf("please enter a proper path")
253254
}
254255

255-
if _, err := os.Stat(s); err == nil {
256+
if _, err := os.Stat(s); err != nil {
256257
return fmt.Errorf("File not found.")
257258
}
258259

@@ -262,26 +263,37 @@ func CreateSpeakerImage(speaker, city, year string) (imageFile string) {
262263
if err != nil {
263264
log.Fatal(err)
264265
}
265-
// create the destPath better here
266266

267-
re := regexp.MustCompile("\\.[^.]+$")
267+
var eventStaticPath string
268+
eventStaticPath, err = helpers.EventStaticPath(city, year)
269+
if err != nil {
270+
log.Fatal(err)
271+
}
272+
fmt.Println(eventStaticPath)
273+
274+
if err := os.MkdirAll(filepath.Join(eventStaticPath, "speakers"), 0777); err != nil {
275+
log.Fatal(err)
276+
}
277+
278+
re := regexp.MustCompile(`\.[^.]+$`)
268279
ext := strings.ToLower(re.FindString(srcPath))
280+
fmt.Println("extension is " + ext)
269281
switch ext {
270-
case "jpg":
282+
case ".jpg":
271283
s := []string{strings.TrimSpace(speaker), ".jpg"}
272-
destPath := filepath.Join(helpers.EventContentPath(city, year), "speakers", strings.Join(s, ""))
284+
destPath := filepath.Join(eventStaticPath, "speakers", strings.Join(s, ""))
273285
helpers.ResizeImage(srcPath, destPath, "jpg", 600, 600)
274286
return strings.Join(s, "")
275-
case "jpeg":
287+
case ".jpeg":
276288
s := []string{strings.TrimSpace(speaker), ".jpg"}
277-
destPath := filepath.Join(helpers.EventContentPath(city, year), "speakers", strings.Join(s, ""))
289+
destPath := filepath.Join(eventStaticPath, "speakers", strings.Join(s, ""))
278290
helpers.ResizeImage(srcPath, destPath, "jpg", 600, 600)
279291
return strings.Join(s, "")
280-
case "png":
292+
case ".png":
281293
s := []string{strings.TrimSpace(speaker), ".png"}
282-
destPath := filepath.Join(helpers.EventContentPath(city, year), "speakers", strings.Join(s, ""))
294+
destPath := filepath.Join(eventStaticPath, "speakers", strings.Join(s, ""))
283295
helpers.ResizeImage(srcPath, destPath, "png", 600, 600)
284296
return strings.Join(s, "")
285297
}
286-
return ""
298+
return "busted"
287299
}

helpers/event_content_path.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ import (
88
// EventContentPath returns the path for content for an event based upon city and year
99
func EventContentPath(city, year string) (eventContentPath string) {
1010
s := []string{strings.TrimSpace(year), "-", strings.Replace(strings.TrimSpace(strings.ToLower(city)), " ", "-", 10)}
11-
eventContentPath = filepath.Join(GetWebdir(), "content", "events", strings.Join(s, ""))
12-
// eventContentPath = webdir
13-
return eventContentPath
11+
return filepath.Join(GetWebdir(), "content", "events", strings.Join(s, ""))
1412
}

helpers/event_static_path.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package helpers
22

33
import (
4+
"os"
45
"path/filepath"
56
"strings"
67
)
78

8-
// EventStaticPath returns the full path of the static directory for an event
9-
func EventStaticPath(webdir, city, year string) (eventStaticPath string) {
10-
s := []string{strings.TrimSpace(year), "-", strings.Replace(strings.TrimSpace(strings.ToLower(city)), " ", "-", 10), ".yml"}
11-
return filepath.Join(webdir, "static", "events", strings.Join(s, ""))
9+
// EventStaticPath returns the full path of the static directory for an event, creating it if needed
10+
func EventStaticPath(city, year string) (eventStaticPath string, err error) {
11+
s := []string{strings.TrimSpace(year), "-", strings.Replace(strings.TrimSpace(strings.ToLower(city)), " ", "-", 10)}
12+
eventStaticPath = filepath.Join(GetWebdir(), "static", "events", strings.Join(s, ""))
13+
if err := os.MkdirAll(eventStaticPath, 0777); err == nil {
14+
return eventStaticPath, err
15+
}
16+
return "", err
1217
}

0 commit comments

Comments
 (0)