fix: if empty que title not render answers

This commit is contained in:
skeris 2025-06-17 17:21:37 +03:00
parent d0d7b1af55
commit 19cba7f57e
3 changed files with 11 additions and 5 deletions

@ -483,7 +483,7 @@
</tr>
{{ range .AllAnswers }}
{{ if index $.QuestionsMap .AnswerID }}
{{ if keyExists $.QuestionsMap .AnswerID }}
<tr>
<td colspan="2" style="padding: 0">
<table

@ -6,9 +6,10 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"gitea.pena/SQuiz/common/model"
"golang.org/x/net/html"
"html/template"
"gitea.pena/SQuiz/common/model"
"io"
"strings"
)
@ -54,6 +55,10 @@ func generateTextFromTemplate(data TemplateData, tpl string) (string, error) {
}
var tmplFuncs = template.FuncMap{
"keyExists": func(m map[uint64]string, key uint64) bool {
_, ok := m[key]
return ok
},
"renderImage": RenderImage,
}
@ -74,7 +79,7 @@ func RenderImage(content string) template.HTML {
if err != nil {
return SplitContent(content)
} else {
builder.WriteString(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, strings.Replace(res.Image,"http","https",1)))
builder.WriteString(fmt.Sprintf("<td>%s<br><img class=\"image\" style=\"width:100%%; max-width:250px; max-height:250px\" src=\"%s\"/></td>", res.Description, strings.Replace(res.Image, "http", "https", 1)))
}
}

@ -80,6 +80,7 @@
<tr>
<td colspan="2" style="height: 100%">
<a
href="https://quiz.pena.digital/results/{{ .QuizID }}"
style="
display: flex;
justify-content: center;
@ -482,7 +483,7 @@
</tr>
{{ range .AllAnswers }}
{{ if index $.QuestionsMap .AnswerID }}
{{ if keyExists $.QuestionsMap .AnswerID }}
<tr>
<td colspan="2" style="padding: 0">
<table