-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
128 lines (99 loc) · 2.77 KB
/
main.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"io/ioutil"
"log"
"os"
"sort"
"strings"
"time"
"text/template"
"gopkg.in/yaml.v2"
)
type TalkType string
const (
CommunityTalk TalkType = "COMMUNITY_TYPE"
CorporateTalk TalkType = "CORPORATE_TALK"
ConferenceTalk TalkType = "CONFERENCE_TALK"
Workshop TalkType = "WORKSHOP"
)
type Event struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
}
type Artifact struct {
Video string `yaml:"video"`
Slide string `yaml:"slide"`
}
type Talks []Talk
func (t *Talks) readConf() *Talks {
yamlFile, err := ioutil.ReadFile("talks.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, t)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return t
}
func (t Talks) Len() int {
return len(t)
}
func (t Talks) Less(i, j int) bool {
return t[i].GetTime().After(t[j].GetTime())
}
func (t Talks) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
type Talk struct {
Title string `yaml:"title"`
Type TalkType `yaml:"type"`
Event Event `yaml:"event"`
Date string `yaml:"dateTime"`
Artifact Artifact `yaml:"artifact"`
Tags []string `yaml:"tags"`
}
func (t Talk) DateStr() string {
return t.GetTime().Format("02-Jan-2006") // 31-Aug-2017
}
func (t Talk) GetTime() time.Time {
layout := "2006-01-02T15:04:05-0700"
tf, err := time.Parse(layout, t.Date)
if err != nil {
panic(err)
}
return tf
}
func (t Talk) TagsStr() string {
return strings.Join(t.Tags, ", ")
}
func main() {
var talks Talks
talks.readConf()
sort.Sort(talks)
f, err := createOrOpenFile("README.md", false)
if err != nil {
panic(err)
}
t := template.Must(template.New("readmeTemplate").Parse(string(readmeTemplate)))
t.Execute(f, talks)
}
var readmeTemplate = []byte(`
# Husni Alhamdani
### Biography
> Husni Alhamdani, Site reliability Engineer, Graduated LFX 2022 Spring, 3x Kubernetes Certified (KCNA-BETA, CKA, CKS) --> the first Kubernetes certified holder from Indonesia.
TECH TALK
====
List of tech talk I've ever gave about Community, Open Source and Cloud Computings
| Date | Event | Title | Slide | Video | Tags |
| ----------- | ----------- | ----------- | ----------- | ----------- | ----------- |
{{- range $index, $element := . }}
| {{ $element.DateStr }} | {{ if $element.Event.URL }} [{{ $element.Event.Name}}]({{$element.Event.URL}}) {{ else }}{{ $element.Event.Name}}{{ end }} | *{{ $element.Title }}* | {{ if $element.Artifact.Slide }} [Slide]({{ $element.Artifact.Slide }} ) {{ end }} | {{ if $element.Artifact.Video }} [Video]({{ $element.Artifact.Video }}) {{ end }} | {{ $element.TagsStr }} |
{{- end }}
`)
func createOrOpenFile(filename string, append bool) (*os.File, error) {
if append {
return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
}
return os.Create(filename)
}