forked from pgaskin/BookBrowser
/
html.go
136 lines (129 loc) · 4.67 KB
/
html.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
129
130
131
132
133
134
135
136
package main
import (
"bytes"
"fmt"
)
func pageHTML(title string, content string) string {
var html bytes.Buffer
html.WriteString(`<!DOCTYPE html>
<html>
<head>
<title>`)
html.WriteString(title)
html.WriteString(`</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/books/">BookBrowser</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/books/">Books</a></li>
<li><a href="/authors/">Authors</a></li>
<li><a href="/series/">Series</a></li>
<li><a href="/random/">Random Book</a></li>
</ul>
<ul class="nav navbar-nav navbar-right" style="padding-right:20px">
<form class="navbar-form" role="search" method="GET" action="/search/">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="q">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</ul>
</div>
</nav>
<div class="container">
<div class="page-header">
<h1>`)
html.WriteString(title)
html.WriteString(`</h1>
</div>`)
html.WriteString(content)
html.WriteString(`</div>
<footer class="footer">
<div class="container">
<p class="text-muted"><a href="https://github.com/geek1011/BookBrowser">BookBrowser</a> ` + curversion + `</p>
<p class="text-muted">Copyright 2017 <a href="https://geek1011.github.io">Patrick G</a></p>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>`)
return html.String()
}
func bookHTML(b *Book, isCard bool) string {
var html bytes.Buffer
if isCard {
html.WriteString(`<div class="book card">`)
} else {
html.WriteString(`<div class="book info">`)
}
html.WriteString(`<a class="cover" href="/books/` + b.ID + `">`)
if b.HasCover {
if isCard {
html.WriteString(`<img alt="cover" src="/covers/` + b.ID + `_thumb.jpg" />`)
} else {
html.WriteString(`<img alt="cover" src="/covers/` + b.ID + `.jpg" />`)
}
} else {
html.WriteString(`<img alt="cover" src="/static/nocover.jpg" />`)
}
html.WriteString(`</a>`)
html.WriteString(`<div class="meta">`)
html.WriteString(`<a class="title" href="/books/` + b.ID + `">`)
html.WriteString(b.Title)
html.WriteString(`</a>`)
if b.Author != "" {
html.WriteString(`<a class="author" href="/authors/` + b.AuthorID + `">`)
html.WriteString(b.Author)
html.WriteString(`</a>`)
}
if b.Series.Name != "" {
html.WriteString(`<div class="series">`)
html.WriteString(`<a class="name" href="/series/` + b.Series.ID + `">`)
html.WriteString(b.Series.Name)
html.WriteString(`</a> - <span class="index">`)
html.WriteString(fmt.Sprintf("%v", b.Series.Index))
html.WriteString(`</span>`)
html.WriteString(`</div>`)
}
if !isCard && b.Description != "" {
html.WriteString(`<div class="description">`)
html.WriteString(b.Description)
html.WriteString(`</div>`)
}
html.WriteString(`<a class="download btn btn-default" href="/download/` + b.ID + `.epub">Download EPUB</a>`)
html.WriteString(`<a class="reader btn btn-default" href="/static/reader/#/download/` + b.ID + `.epub">Read</a>`)
html.WriteString(`</div>`)
html.WriteString(`</div>`)
return html.String()
}
func itemCardHTML(title string, description string, link string) string {
var html bytes.Buffer
html.WriteString(`<a class="item card" href="` + link + `">`)
html.WriteString(`<div class="title">`)
html.WriteString(title)
html.WriteString(`</div>`)
html.WriteString(`<div class="description">`)
html.WriteString(description)
html.WriteString(`</div>`)
html.WriteString(`</a>`)
return html.String()
}