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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
package config
import (
"fmt"
"strings"
"time"
"go.jetpack.io/tyson"
"xeiaso.net/v4/internal/jsonfeed"
)
type Config struct {
Authors map[string]Author `json:"authors"`
Characters []Character `json:"characters"`
ClackSet []string `json:"clackSet"`
ContactLinks []Link `json:"contactLinks"`
DefaultAuthor Author `json:"defaultAuthor"`
JobHistory []Job `json:"jobHistory"`
NotableProjects []Link `json:"notableProjects"`
Pronouns []Pronoun `json:"pronouns"`
SeriesDescriptions map[string]string `json:"seriesDescriptions"`
Resume Resume `json:"resume"`
VODs []VOD `json:"vods"`
WebMentionEndpoint string `json:"webMentionEndpoint"`
Redirects map[string]string `json:"redirects"`
}
type Author struct {
Name string `json:"name"`
Handle string `json:"handle"`
Image *string `json:"image,omitempty"`
URL *string `json:"url,omitempty"`
SameAs []string `json:"sameAs,omitempty"`
JobTitle *string `json:"jobTitle,omitempty"`
InSystem bool `json:"inSystem"`
Pronouns Pronoun `json:"pronouns"`
}
func (a Author) ToJSONFeedAuthor() jsonfeed.Author {
url := ""
if a.URL != nil {
url = *a.URL
}
avatar := ""
if a.Image != nil {
avatar = *a.Image
}
return jsonfeed.Author{
Name: a.Name,
URL: url,
Avatar: avatar,
}
}
type Character struct {
Name string `json:"name"`
StickerName string `json:"stickerName"`
DefaultPose string `json:"defaultPose"`
Description string `json:"description"`
Pronouns Pronoun `json:"pronouns"`
Stickers []string `json:"stickers"`
}
type Company struct {
Name string `json:"name"`
URL *string `json:"url,omitempty"`
Tagline string `json:"tagline"`
Location Location `json:"location"`
Defunct bool `json:"defunct"`
}
type Date struct {
time.Time
}
func (d *Date) UnmarshalYAML(unmarshal func(interface{}) error) error {
var dateStr string
if err := unmarshal(&dateStr); err != nil {
return err
}
if dateStr == "" {
return nil
}
t, err := time.Parse("2006-01-02", dateStr)
if err != nil {
return err
}
d.Time = t
return nil
}
func (d *Date) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
if s == "null" {
return nil
}
t, err := time.Parse("2006-01-02", s)
if err != nil {
return err
}
d.Time = t
return nil
}
func (d Date) MarshalJSON() ([]byte, error) {
if d.Time.IsZero() {
return []byte("null"), nil
}
return []byte(fmt.Sprintf("%q", d.Time.Format("2006-01-02"))), nil
}
type Job struct {
Company Company `json:"company"`
Title string `json:"title"`
Contract bool `json:"contract"`
StartDate *Date `json:"startDate"`
EndDate *Date `json:"endDate,omitempty"`
DaysWorked int `json:"daysWorked"`
DaysBetween int `json:"daysBetween"`
Salary Salary `json:"salary"`
LeaveReason *string `json:"leaveReason,omitempty"`
Locations []Location `json:"locations"`
Highlights []string `json:"highlights"`
HideFromResume bool `json:"hideFromResume"`
}
type Link struct {
URL string `json:"url"`
Title string `json:"title"`
Description *string `json:"description,omitempty"`
}
type Location struct {
City string `json:"city"`
StateOrProvince string `json:"stateOrProvince"`
Country string `json:"country"`
Remote bool `json:"remote"`
}
func (l Location) String() string {
return fmt.Sprintf("%s, %s, %s", l.City, l.StateOrProvince, l.Country)
}
type NagMessage struct {
Name string `json:"name"`
Mood string `json:"mood"`
Message string `json:"message"`
}
type Person struct {
Name string `json:"name"`
Tags []string `json:"tags"`
Links []Link `json:"links"`
}
type Pronoun struct {
Nominative string `json:"nominative"`
Accusative string `json:"accusative"`
PossessiveDeterminer string `json:"possessiveDeterminer"`
Possessive string `json:"possessive"`
Reflexive string `json:"reflexive"`
Singular bool `json:"singular"`
}
type Resume struct {
Name string `json:"name"`
Tagline string `json:"tagline"`
Location Location `json:"location"`
Buzzwords []string `json:"buzzwords"`
Jobs []Job `json:"jobs"`
NotablePublications []Link `json:"notablePublications"`
}
type Salary struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Per string `json:"per"`
Stock *Stock `json:"stock,omitempty"`
}
type Stock struct {
Kind string `json:"kind"`
Amount int `json:"amount"`
Liquid bool `json:"liquid"`
VestingYears int `json:"vestingYears"`
CliffYears int `json:"cliffYears"`
}
type VOD struct {
Title string `json:"title"`
Slug string `json:"slug"`
Date *Date `json:"date"`
Description string `json:"description"`
CDNPath string `json:"cdnPath"`
Tags []string `json:"tags"`
}
// Parse parses the config file and returns a Config struct.
func Parse(fname string) (*Config, error) {
var c Config
if err := tyson.Unmarshal(fname, &c); err != nil {
return nil, err
}
return &c, nil
}
|