tRead HTML template from a file - scoreboard - Interactive scoreboard for CTF-like games
(HTM) git clone git://git.z3bra.org/scoreboard.git
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 9ae93c35af4c5f5f17da95e9405c72788d3f0707
(DIR) parent 05db44d4935f2aaf86977e40dca6b5855d592c7e
(HTM) Author: Willy Goiffon <contact@z3bra.org>
Date: Sat, 28 Sep 2024 10:00:49 +0200
Read HTML template from a file
Diffstat:
M html.go | 51 +------------------------------
M main.go | 4 ++++
A template.html | 64 +++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 50 deletions(-)
---
(DIR) diff --git a/html.go b/html.go
t@@ -21,55 +21,6 @@ type Template struct {
Placeholders []Boardline
}
-var html string = `
-<!DOCTYPE HTML>
-<html>
-<head>
- <meta charset="utf-8">
- <meta name="author" content="wgs">
- <meta name="viewport" content="width=device-width">
- <link rel="stylesheet" type="text/css" href="/5rooms.css">
- <link rel="icon" type="image/ico" href="/favicon.ico" />
- <title>High scores</title>
- <style>
- table {
- max-width: 100%;
- margin: auto;
- border-collapse: collapse;
- overflow: scroll;
- text-align:center;
- font-family: monospace;
- }
- th { padding: 1ch 1ch; }
- td { padding: 0ch 1ch; }
- tr.unset { color: #888; }
- tr > td:last-of-type { text-align:right; }
- p.copyright {
- width: 100%;
- text-align: center;
- position: absolute;
- bottom: 2ch;
- }
- </style>
-</head>
-<body class=flex>
-<h1>HIGH SCORES</h1>
-<main class="room vert">
-<table>
- <thead><tr><th>RANK</th><th>NAME</th><th>FLAGS</th><th>SCORE</th></tr></thead>
- <tbody>
-{{range .Players}} <tr><td>{{.Rank}}<td>{{.Name}}</td><td><abbr title="{{.Badge}}">{{.Flag}}</abbr></td><td>{{.Score}}</td></tr>
-{{end}}
-{{range .Placeholders}} <tr class='unset'><td>{{.Rank}}<td>{{.Name}}</td><td>{{.Flag}}</td><td>{{.Score}}</td></tr>
-{{end}}
- </tbody>
-</table>
-</main>
-<p class='copyright'>Copyright (C) <a href="https://z3bra.org">wgs</a>, 2024-2025</p>
-</body>
-</html>
-`
-
func (p *Player) BadgeHTML() string {
var badges strings.Builder
t@@ -132,7 +83,7 @@ func (a *Application) GenerateHTML() {
}
}
- tmpl, err := template.New("board").Parse(html)
+ tmpl, err := template.ParseFiles(a.tmpl)
if err != nil {
panic(err)
}
(DIR) diff --git a/main.go b/main.go
t@@ -31,6 +31,7 @@ const (
BOARD_WIDTH int = 28
BOARD_HEIGHT int = 15
HTML string = "score.html"
+ TMPL string = "template.html"
DB string = "score.db"
TOKEN_REMINDER string = `%s, use the token below to submit your flags.
Save it carefully, do not share it.
t@@ -52,6 +53,7 @@ type Application struct {
db *sql.DB
app *tview.Application
html string
+ tmpl string
pages *tview.Pages
frame *tview.Frame
board *tview.Flex
t@@ -88,6 +90,7 @@ func main() {
var reminder bool = false
html := flag.String("o", HTML, "Output HTML file")
+ tmpl := flag.String("t", HTML, "Template HTML file")
db := flag.String("d", DB, "Database file")
flag.Parse()
t@@ -117,6 +120,7 @@ func main() {
scoreboard.flag = Flag{}
scoreboard.html = *html
+ scoreboard.tmpl = *tmpl
scoreboard.app = tview.NewApplication()
scoreboard.pages = tview.NewPages()
scoreboard.board = tview.NewFlex()
(DIR) diff --git a/template.html b/template.html
t@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta name="author" content="wgs">
+ <meta name="viewport" content="width=device-width">
+ <link rel="icon" type="image/ico" href="/favicon.ico" />
+ <title>Scores</title>
+ <style>
+ body {
+ color: #eee;
+ background-color: #1d1d1d;
+ background-image: radial-gradient(rgba(255,255,255,0.2) 1px, transparent 0);
+ background-size: 8px 8px;
+ height: 100vh;
+ margin: 0;
+ }
+ main {
+ width: 80vw;
+ max-width: 540px;
+ height: 100%;
+ margin: 0 auto;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ }
+ h1 {
+ font-size: 4rem;
+ }
+ table {
+ border-radius: 12px;
+ background-color: #1d1d1d;
+ padding: 1ch;
+ max-width: 100%;
+ margin: auto;
+ text-align:center;
+ font-size: 1.2rem;
+ font-family: monospace;
+ }
+ th { padding: 1ch 1ch; }
+ td { padding: 0ch 1ch; }
+ tr.unset { color: #888; }
+ tr > td:last-of-type { text-align:right; }
+ p.copyright { text-align: center; }
+ p.copyright > a { color: #db4; }
+ </style>
+</head>
+<body>
+<main>
+<h1>Scores</h1>
+<table>
+ <thead><tr><th>RANK</th><th>NAME</th><th>FLAGS</th><th>SCORE</th></tr></thead>
+ <tbody>
+{{range .Players}} <tr><td>{{.Rank}}<td>{{.Name}}</td><td><abbr title="{{.Badge}}">{{.Flag}}</abbr></td><td>{{.Score}}</td></tr>
+{{end}}
+{{range .Placeholders}} <tr class='unset'><td>{{.Rank}}<td>{{.Name}}</td><td>{{.Flag}}</td><td>{{.Score}}</td></tr>
+{{end}}
+ </tbody>
+</table>
+<div style="flex-grow:2"></div>
+<p class='copyright'>Copyright (C) <a href="https://z3bra.org">wgs</a>, 2024-2025</p>
+</main>
+</body>
+</html>