-
Notifications
You must be signed in to change notification settings - Fork 21
/
page.go
43 lines (36 loc) · 1.29 KB
/
page.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
package core
import (
"io"
)
// Page is the entire page wrapped that provides the HTML head and body.
type Page struct {
title string
body Component
googleAnalyticsID string
}
func NewPage(title string, body Component, googleAnalyticsID string) *Page {
return &Page{
title: title,
body: body,
googleAnalyticsID: googleAnalyticsID,
}
}
func (c *Page) WriteHTMLTo(w io.Writer) (int64, error) {
googleAnalytics := NewGoogleAnalytics(c.googleAnalyticsID)
footer := NewFooterRow()
title := NewTag("title", nil, NewText(c.title))
n := appendString(w, `<html><head><meta charset="UTF-8">`)
n += appendComponent(w, googleAnalytics)
n += appendComponent(w, title)
n += appendString(w, `<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/4.4.0/font/octicons.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">`)
n += appendComponent(w, c.body)
n += appendComponent(w, footer)
n += appendString(w, `</div></body></html>`)
return n, nil
}