fix missing spacing in feed preview
Alan Pearce alan@alanpearce.eu
Tue, 25 Jun 2024 09:37:00 +0200
3 files changed, 16 insertions(+), 22 deletions(-)
M config.toml → config.toml
@@ -46,9 +46,9 @@ "https://gc.zgo.at", ] style-src = [ ## index.html style - "'sha256-bGzdRsb1Yu6TLWwCqsdslYaNhLBikKOD6pFYeGsJ4lc='", - ## atom.xml style "'sha256-dCSzNS1o8vygl80V2G2nPTiSOUNvyDnW+06hHS4ZdHQ='", + ## atom.xml style + "'sha256-CFhPA4p8skr5MyhReF+Tk2GzmYzXdECg8zm+o7EOVPI=", ] frame-ancestors = [ "https://kagi.com",
M internal/builder/template.go → internal/builder/template.go
@@ -154,34 +154,26 @@ return strings.NewReader(doc.OutputXML(true)), nil } 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
M templates/feed-styles.xsl → templates/feed-styles.xsl
@@ -12,7 +12,9 @@ <title>RSS Feed | <xsl:value-of select="/atom:feed/atom:title"/></title> <meta charset="utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> - <style></style> + <style> + {{ .css }} + </style> </head> <body> <main>