39 lines
837 B
Go
39 lines
837 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
)
|
|
|
|
func GenerateEpisodeDescription(imageURL, title, content string) string {
|
|
// Template con sezione CDATA
|
|
const descTemplate = `<![CDATA[
|
|
<h1 style="margin-top:0;">{{.Title}}</h1>
|
|
{{if .ImageURL}}<img src="{{.ImageURL}}" width="300" style="float:right; margin:0 0 10px 10px;">{{end}}
|
|
<div style="clear:both;"></div>
|
|
{{.Content}}
|
|
]]>`
|
|
|
|
// 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 "<![CDATA[<h3>" + title + "</h3>" + content + "]]>"
|
|
}
|
|
|
|
return buf.String()
|
|
}
|