mirror of
https://codeberg.org/hyperreal/go-transmission-stats
synced 2024-11-01 08:43:10 +01:00
Move template to main.go as raw string literal
This commit is contained in:
parent
3585533a81
commit
55b75e8ae4
79
html/main.go
79
html/main.go
@ -153,18 +153,89 @@ func main() {
|
||||
TorrentInfo: torrentInfo,
|
||||
}
|
||||
|
||||
htmlTemplate, err := template.ParseFiles("template.html")
|
||||
htmlTemplate := `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>hyperreal.coffee: Torrent Stats</title>
|
||||
<link rel="icon" type="image/x-icon" href="coffee.svg">
|
||||
<link href="torrentstats.css" rel="stylesheet">
|
||||
</head>
|
||||
<style>
|
||||
body {
|
||||
max-width: 96%;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Torrent Stats</h1>
|
||||
<p>As of {{.Date}}</p>
|
||||
|
||||
<h2>Session Stats</h2>
|
||||
<table>
|
||||
{{range .SessionStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Current Stats</h2>
|
||||
<table>
|
||||
{{range .CurrentStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Cumulative Stats</h2>
|
||||
<table>
|
||||
{{range .CumulativeStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Torrent Info</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Activity Date</th>
|
||||
<th>Total Size</th>
|
||||
<th>Leechers</th>
|
||||
<th>Seeders</th>
|
||||
</tr>
|
||||
{{range .TorrentInfo}}
|
||||
<tr>
|
||||
<td>{{.Name}}</td>
|
||||
<td>{{.ActivityDate}}</td>
|
||||
<td>{{.TotalSize}}</td>
|
||||
<td>{{.Leechers}}</td>
|
||||
<td>{{.Seeders}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
html, err := template.New("torrentstats").Parse(htmlTemplate)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
htmlFile, err := os.Create(os.Getenv("HTML_FILE"))
|
||||
htmlOutputFile, err := os.Create(os.Getenv("HTML_FILE"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer htmlFile.Close()
|
||||
defer htmlOutputFile.Close()
|
||||
|
||||
if err = htmlTemplate.Execute(htmlFile, data); err != nil {
|
||||
if err = html.Execute(htmlOutputFile, data); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>hyperreal.coffee: Torrent Stats</title>
|
||||
<link rel="icon" type="image/x-icon" href="coffee.svg">
|
||||
<link href="torrentstats.css" rel="stylesheet">
|
||||
</head>
|
||||
<style>
|
||||
body {
|
||||
max-width: 96%;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Torrent Stats</h1>
|
||||
<p>As of {{.Date}}</p>
|
||||
|
||||
<h2>Session Stats</h2>
|
||||
<table>
|
||||
{{range .SessionStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Current Stats</h2>
|
||||
<table>
|
||||
{{range .CurrentStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Cumulative Stats</h2>
|
||||
<table>
|
||||
{{range .CumulativeStats}}
|
||||
<tr>
|
||||
<td>{{.Label}}</td>
|
||||
<td>{{.Value}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
||||
<h2>Torrent Info</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Activity Date</th>
|
||||
<th>Total Size</th>
|
||||
<th>Leechers</th>
|
||||
<th>Seeders</th>
|
||||
</tr>
|
||||
{{range .TorrentInfo}}
|
||||
<tr>
|
||||
<td>{{.Name}}</td>
|
||||
<td>{{.ActivityDate}}</td>
|
||||
<td>{{.TotalSize}}</td>
|
||||
<td>{{.Leechers}}</td>
|
||||
<td>{{.Seeders}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user