refactor(modlist): replace html/template with text/template and clean up deps
Some checks failed
CI / build (push) Failing after 3s
Some checks failed
CI / build (push) Failing after 3s
This commit is contained in:
@@ -3,11 +3,12 @@ package services
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
stdhtml "html"
|
||||
"io"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"arma3-web-server/internal/models"
|
||||
"golang.org/x/net/html"
|
||||
@@ -15,19 +16,82 @@ import (
|
||||
|
||||
const modlistHTMLTmpl = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<html>
|
||||
<!--Created by Arma 3 Web Server-->
|
||||
<head>
|
||||
<meta name="arma:Type" content="list"/>
|
||||
<meta name="generator" content="Arma 3 Web Server"/>
|
||||
<meta name="arma:Type" content="list" />
|
||||
<meta name="generator" content="Arma 3 Web Server" />
|
||||
<title>Arma 3</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css" />
|
||||
<style>
|
||||
body{margin:0;padding:0;color:#fff;background:#000;font:95%/1.3 Roboto,Segoe UI,Tahoma,Arial,Helvetica,sans-serif}
|
||||
td{padding:3px 30px 3px 0}
|
||||
h1{padding:20px 20px 0;color:#fff;font-weight:200;font-family:segoe ui;font-size:3em;margin:0}
|
||||
.before-list{padding:5px 20px 10px}
|
||||
.mod-list{background:#222;padding:20px}
|
||||
.footer{padding:20px;color:gray}
|
||||
.from-steam{color:#449EBD}
|
||||
</style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #fff;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
body, th, td {
|
||||
font: 95%/1.3 Roboto, Segoe UI, Tahoma, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 3px 30px 3px 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding: 20px 20px 0 20px;
|
||||
color: white;
|
||||
font-weight: 200;
|
||||
font-family: segoe ui;
|
||||
font-size: 3em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
em {
|
||||
font-variant: italic;
|
||||
color:silver;
|
||||
}
|
||||
|
||||
.before-list {
|
||||
padding: 5px 20px 10px 20px;
|
||||
}
|
||||
|
||||
.mod-list {
|
||||
background: #222222;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.dlc-list {
|
||||
background: #222222;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 20px;
|
||||
color:gray;
|
||||
}
|
||||
|
||||
.whups {
|
||||
color:gray;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #D18F21;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color:#F1AF41;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.from-steam {
|
||||
color: #449EBD;
|
||||
}
|
||||
.from-local {
|
||||
color: gray;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Arma 3 Mods</h1>
|
||||
@@ -37,9 +101,13 @@ h1{padding:20px 20px 0;color:#fff;font-weight:200;font-family:segoe ui;font-size
|
||||
<div class="mod-list">
|
||||
<table>{{range .Mods}}
|
||||
<tr data-type="ModContainer">
|
||||
<td data-type="DisplayName">{{.Name}}</td>
|
||||
<td><span class="from-steam">Steam</span></td>
|
||||
<td><a href="https://steamcommunity.com/sharedfiles/filedetails/?id={{.ID}}" data-type="Link">https://steamcommunity.com/sharedfiles/filedetails/?id={{.ID}}</a></td>
|
||||
<td data-type="DisplayName">{{.Name | safeHTML}}</td>
|
||||
<td>
|
||||
<span class="from-steam">Steam</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://steamcommunity.com/sharedfiles/filedetails/?id={{.ID}}" data-type="Link">https://steamcommunity.com/sharedfiles/filedetails/?id={{.ID}}</a>
|
||||
</td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
</div>
|
||||
@@ -158,8 +226,14 @@ type renderMod struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
func safeHTML(s string) string {
|
||||
return stdhtml.EscapeString(s)
|
||||
}
|
||||
|
||||
func RenderModlistHTML(name string, mods []models.ModEntry) (string, error) {
|
||||
tmpl, err := template.New("modlist").Parse(modlistHTMLTmpl)
|
||||
tmpl, err := template.New("modlist").Funcs(template.FuncMap{
|
||||
"safeHTML": safeHTML,
|
||||
}).Parse(modlistHTMLTmpl)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("parse template: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user