feat(templates): Get static mounted images
This commit is contained in:
parent
d910a722df
commit
4deda8adf1
@ -81,7 +81,11 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||||
return templates.GetImage("error"), nil
|
sponsors := []string{
|
||||||
|
"sponsoringheader",
|
||||||
|
"odit",
|
||||||
|
}
|
||||||
|
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||||
|
1
static/images/odit.base64
Normal file
1
static/images/odit.base64
Normal file
File diff suppressed because one or more lines are too long
1
static/images/sponsoringheader.base64
Normal file
1
static/images/sponsoringheader.base64
Normal file
File diff suppressed because one or more lines are too long
@ -3,6 +3,8 @@ package templates
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed card/en.html
|
//go:embed card/en.html
|
||||||
@ -44,10 +46,10 @@ func GetTemplate(locale, templateName string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetImage(imageName string) string {
|
func GetImage(imageName string) string {
|
||||||
switch imageName {
|
content, err := os.ReadFile("static/images/" + imageName + ".base64")
|
||||||
case "sponsoringheader":
|
if content == nil || err != nil {
|
||||||
return ImageSponsoringHeaderBase64
|
log.Printf("error reading image %s: %v", imageName, err)
|
||||||
default:
|
|
||||||
return ImageErrorBase64
|
return ImageErrorBase64
|
||||||
}
|
}
|
||||||
|
return string(content)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user