-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
95 lines (84 loc) · 1.45 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
package main
import (
"github.com/jchavannes/browser-history-parser/wikipedia"
"github.com/jchavannes/jgo/web"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
)
var (
indexRoute = web.Route{
Pattern: "/",
Handler: func(r *web.Response) {
r.Helper["Events"] = getEvents()
r.Render()
},
}
necessaryRoute = web.Route{
Pattern: "/necessary",
Handler: func(r *web.Response) {
r.Helper["OnlyNecessary"] = true
r.Helper["Events"] = getEvents()
r.RenderTemplate("index")
},
}
aboutRoute = web.Route{
Pattern: "/about",
Handler: func(r *web.Response) {
r.Render()
},
}
)
func main() {
server := web.Server{
Port: 2040,
TemplatesDir: "web",
StaticFilesDir: "web",
Routes: []web.Route{
indexRoute,
necessaryRoute,
aboutRoute,
},
}
server.Run()
}
func getEvents() events {
data, err := ioutil.ReadFile("events.yml")
check(err)
e := events{}
err = yaml.Unmarshal(data, &e)
check(err)
return e
}
type events struct {
Eras []era
}
type era struct {
Name string
Label string
Events []event
}
type event struct {
Name string
Necessary bool
Actual int64
Label string
Source string
Image struct {
Name string
Link string
Width string
Height string
}
}
func (e event) GetSourceText() string {
if ! wikipedia.IsWikipediaUrl(e.Source) {
return e.Source
}
return "wiki/" + wikipedia.ArticleNameFromUrl(e.Source)
}
func check(e error) {
if e != nil {
log.Fatal(e)
}
}