-
Notifications
You must be signed in to change notification settings - Fork 2
/
partners.go
89 lines (79 loc) · 1.59 KB
/
partners.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/gocarina/gocsv"
"gopkg.in/yaml.v2"
)
type Partner struct {
Key string `csv:"key"`
Title string `csv:"title"`
Category string `csv:"category"`
Order int `csv:"order"`
LogoExists string `csv:"logo_exists"`
Description string `csv:"description"`
}
type PartnerContent struct {
Key string
Title string
Category string
Order int
Logo string
Lang string
}
func createPartner(p *Partner) {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
dirPath := filepath.Join(wd, "partners", p.Category)
err = os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
panic(err)
}
f, err := os.OpenFile(filepath.Join(dirPath, fmt.Sprintf("%s.md", p.Key)), os.O_WRONLY|os.O_CREATE, os.ModePerm)
if err != nil {
panic(err)
}
defer f.Close()
sc := &PartnerContent{
Key: p.Key,
Title: p.Title,
Category: p.Category,
Order: p.Order,
Logo: fmt.Sprintf("/images/partners/logo-%s.png", p.Key),
Lang: "ja",
}
out, err := yaml.Marshal(sc)
if err != nil {
panic(err)
}
body := fmt.Sprintf(`---
%s---
%s`, string(out), p.Description)
rd := strings.NewReader(body)
_, err = io.Copy(f, rd)
if err != nil {
panic(err)
}
}
func processPartners() {
f, err := os.Open("partners.csv")
if err != nil {
panic(err)
}
defer f.Close()
var partners []*Partner
if err := gocsv.UnmarshalFile(f, &partners); err != nil { // Load clients from file
panic(err)
}
for _, p := range partners {
if p.LogoExists != "yes" {
continue
}
createPartner(p)
}
}