/
render.go
71 lines (61 loc) · 1.88 KB
/
render.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
// Package resume contains functionality for rendering /resume page.
package resume
import (
"context"
"io"
"log"
"time"
homecomponent "github.com/shurcooL/home/component"
"github.com/shurcooL/home/internal/exp/service/notification"
"github.com/shurcooL/htmlg"
"github.com/shurcooL/reactions"
"github.com/shurcooL/resume"
"github.com/shurcooL/users"
)
var dmitshur = users.UserSpec{ID: 1924134, Domain: "github.com"}
// ReactableURL is the URL for reactionable items on this resume.
const ReactableURL = "dmitri.shuralyov.com/resume"
// RenderBodyInnerHTML renders the inner HTML of the <body> element of the page that displays the resume.
// It's safe for concurrent use.
func RenderBodyInnerHTML(ctx context.Context, w io.Writer, reactionsService reactions.Service, notification notification.Service, users users.Service, now time.Time, authenticatedUser users.User, returnURL string) error {
var nc uint64
if authenticatedUser.ID != 0 {
var err error
nc, err = notification.CountNotifications(ctx)
if err != nil {
// THINK: Should it be a fatal error or not? What about on frontend vs backend?
log.Println(err)
nc = 0
}
}
dmitshur, err := users.Get(ctx, dmitshur)
if err != nil {
return err
}
reactions, err := reactionsService.List(ctx, ReactableURL)
if err != nil {
return err
}
_, err = io.WriteString(w, `<div style="max-width: 800px; margin: 0 auto 100px auto;">`)
if err != nil {
return err
}
// Render the header.
header := homecomponent.Header{
CurrentUser: authenticatedUser,
NotificationCount: nc,
ReturnURL: returnURL,
}
err = htmlg.RenderComponents(w, header)
if err != nil {
return err
}
// Render the resume contents.
resume := resume.DmitriShuralyov(dmitshur, now, reactions, authenticatedUser)
err = htmlg.RenderComponents(w, resume)
if err != nil {
return err
}
_, err = io.WriteString(w, `</div>`)
return err
}