59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html"
|
|
"text/template"
|
|
)
|
|
|
|
func GenerateEpisodeDescription(imageURL, title, content string) string {
|
|
// Template con sezione CDATA
|
|
const descTemplate = `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<style>
|
|
.episode-container { font-family: Arial, sans-serif; max-width: 800px; }
|
|
.episode-image { float: center; margin: 0 0 15px 15px; max-width: 300px; }
|
|
.episode-title { margin-top: 0; color: #333; }
|
|
.episode-content { line-height: 1.6; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="episode-container">
|
|
{{if .ImageURL}}
|
|
<img src="{{.ImageURL}}" alt="{{.Title}}" class="episode-image">
|
|
{{end}}
|
|
<h3 class="episode-title">{{.Title}}</h3>
|
|
<div class="episode-content">
|
|
{{.Content}}
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`
|
|
|
|
// Dati per il template
|
|
data := struct {
|
|
ImageURL string
|
|
Title string
|
|
Content string
|
|
}{
|
|
ImageURL: imageURL,
|
|
Title: title,
|
|
Content: content,
|
|
}
|
|
|
|
// Esecuzione del template
|
|
var buf bytes.Buffer
|
|
tmpl := template.Must(template.New("desc").Parse(descTemplate))
|
|
|
|
if err := tmpl.Execute(&buf, data); err != nil {
|
|
// Fallback con CDATA
|
|
return "<h3>" + title + "</h3>" + content + ">"
|
|
}
|
|
|
|
return html.EscapeString(buf.String())
|
|
}
|