about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-06-25 09:37:00 +0200
committerAlan Pearce2024-06-25 09:37:00 +0200
commit27cf354a0e5d5b25aba64cc58406c821f2cecfca (patch)
treee37d7222ddcca2db3b57a697c8909f5929bdcc0f /internal
parentbecede4bfead952239b9cf7c8eb9fb96d01534ec (diff)
downloadwebsite-27cf354a0e5d5b25aba64cc58406c821f2cecfca.tar.lz
website-27cf354a0e5d5b25aba64cc58406c821f2cecfca.tar.zst
website-27cf354a0e5d5b25aba64cc58406c821f2cecfca.zip
fix missing spacing in feed preview
Diffstat (limited to 'internal')
-rw-r--r--internal/builder/template.go30
1 files changed, 11 insertions, 19 deletions
diff --git a/internal/builder/template.go b/internal/builder/template.go
index 9d81582..da45fb7 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -154,34 +154,26 @@ func renderFeed(
 }
 
 func renderFeedStyles() (*strings.Reader, error) {
-	reader, err := loadTemplate("templates/feed-styles.xsl")
+	tpl, err := template.ParseFiles("templates/feed-styles.xsl")
 	if err != nil {
 		return nil, err
 	}
-	defer func() {
-		_, err := reader.Seek(0, io.SeekStart)
-		if err != nil {
-			panic("could not reset reader: " + err.Error())
-		}
-	}()
-	doc, err := xmlquery.Parse(reader)
-	if err != nil {
-		return nil, errors.Wrap(err, "could not parse XML")
-	}
-	expr, err := xpath.CompileWithNS("//xhtml:style", nsMap)
+
+	esc := &strings.Builder{}
+	err = xml.EscapeText(esc, []byte(css))
 	if err != nil {
-		return nil, errors.Wrap(err, "could not parse XML")
+		return nil, err
 	}
-	style := xmlquery.QuerySelector(doc, expr)
-	xmlquery.AddChild(style, &xmlquery.Node{
-		Type: xmlquery.TextNode,
-		Data: css,
+
+	w := &strings.Builder{}
+	err = tpl.Execute(w, map[string]interface{}{
+		"css": esc.String(),
 	})
 
-	return strings.NewReader(doc.OutputXML(true)), nil
+	return strings.NewReader(w.String()), nil
 }
 
-func getFeedStylesHash(r *strings.Reader) (string, error) {
+func getFeedStylesHash(r io.Reader) (string, error) {
 	doc, err := xmlquery.Parse(r)
 	if err != nil {
 		return "", err