about summary refs log tree commit diff stats
path: root/internal/builder/template.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/builder/template.go')
-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