|
| 1 | +package speaker |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "io/ioutil" |
| 6 | + "log" |
| 7 | + "path/filepath" |
| 8 | + "strings" |
| 9 | + |
| 10 | + "github.com/BurntSushi/toml" |
| 11 | + paths "github.com/devopsdays/devopsdays-cli/helpers/paths" |
| 12 | + "github.com/devopsdays/devopsdays-cli/model" |
| 13 | + "github.com/gernest/front" |
| 14 | + "github.com/pkg/errors" |
| 15 | +) |
| 16 | + |
| 17 | +// GetSpeakers takes in the city and year and returns a list of the talks |
| 18 | +func GetSpeakers(city, year string) ([]string, error) { |
| 19 | + |
| 20 | + speakerdir := filepath.Join(paths.EventContentPath(city, year), "speakers") |
| 21 | + |
| 22 | + fmt.Println(speakerdir) |
| 23 | + files, err := ioutil.ReadDir(speakerdir) |
| 24 | + |
| 25 | + if err != nil { |
| 26 | + return nil, errors.Wrap(err, "read speaker directory failed") |
| 27 | + } |
| 28 | + var s []string |
| 29 | + // s := make([]string, len(files)) |
| 30 | + for _, f := range files { |
| 31 | + s = append(s, f.Name()) |
| 32 | + } |
| 33 | + return s, nil |
| 34 | +} |
| 35 | + |
| 36 | +func GetSpeakerInfo(file, city, year string) (speaker model.Speaker, err error) { |
| 37 | + |
| 38 | + // speakerPerson := `+++ |
| 39 | + // Website = "" |
| 40 | + // Title = "Rainbow Dash" |
| 41 | + // Twitter = "" |
| 42 | + // date = "2016-12-08T20:55:58-06:00" |
| 43 | + // Type = "speaker" |
| 44 | + // Image = "rainbow-dash.png" |
| 45 | + // Facebook = "" |
| 46 | + // Linkedin = "" |
| 47 | + // Pronouns = "" |
| 48 | + // +++ |
| 49 | + // Food-truck SpaceTeam pivot |
| 50 | + // ` |
| 51 | + filePath := filepath.Join(paths.EventContentPath(city, year), "speakers", file) |
| 52 | + dat, err := ioutil.ReadFile(filePath) |
| 53 | + // lines.WriteTo(os.Stdout) |
| 54 | + m := front.NewMatter() |
| 55 | + m.Handle("+++", TOMLHandler) |
| 56 | + |
| 57 | + f, body, err := m.Parse(strings.NewReader(string(dat))) |
| 58 | + if err != nil { |
| 59 | + panic(err) |
| 60 | + } |
| 61 | + |
| 62 | + speaker = model.Speaker{ |
| 63 | + Name: file, |
| 64 | + Title: f["Title"].(string), |
| 65 | + Website: f["Website"].(string), |
| 66 | + Twitter: f["Twitter"].(string), |
| 67 | + Facebook: f["Facebook"].(string), |
| 68 | + Linkedin: f["Linkedin"].(string), |
| 69 | + Github: f["Github"].(string), |
| 70 | + Gitlab: f["Gitlab"].(string), |
| 71 | + ImagePath: f["ImagePath"].(string), |
| 72 | + Bio: body, |
| 73 | + } |
| 74 | + |
| 75 | + return |
| 76 | +} |
| 77 | + |
| 78 | +// TOMLHandler decodes ymal string into a go map[string]interface{} |
| 79 | +func TOMLHandler(front string) (map[string]interface{}, error) { |
| 80 | + |
| 81 | + // type thing struct { |
| 82 | + // Name string |
| 83 | + // Title string |
| 84 | + // Website string `toml:"website,omitempty"` |
| 85 | + // Twitter string `toml:"twitter,omitempty"` |
| 86 | + // Facebook string `toml:"facebook,omitempty"` |
| 87 | + // Linkedin string `toml:"linkedin,omitempty"` |
| 88 | + // Github string `toml:"github,omitempty"` |
| 89 | + // Gitlab string `toml:"gitlab,omitempty"` |
| 90 | + // ImagePath string `toml:"image,omitempty"` |
| 91 | + // Bio string |
| 92 | + // } |
| 93 | + |
| 94 | + // var stuff thing |
| 95 | + var stuff model.Speaker |
| 96 | + if _, err := toml.Decode(front, &stuff); err != nil { |
| 97 | + log.Fatal(err) |
| 98 | + } |
| 99 | + x := map[string]interface{}{ |
| 100 | + "Name": stuff.Name, |
| 101 | + "Title": stuff.Title, |
| 102 | + "Website": stuff.Website, |
| 103 | + "Twitter": stuff.Twitter, |
| 104 | + "Facebook": stuff.Facebook, |
| 105 | + "Linkedin": stuff.Linkedin, |
| 106 | + "Github": stuff.Github, |
| 107 | + "Gitlab": stuff.Gitlab, |
| 108 | + "ImagePath": stuff.ImagePath, |
| 109 | + "Bio": stuff.Bio, |
| 110 | + } |
| 111 | + |
| 112 | + return x, nil |
| 113 | +} |
0 commit comments