From 27cf354a0e5d5b25aba64cc58406c821f2cecfca Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 25 Jun 2024 09:37:00 +0200 Subject: fix missing spacing in feed preview --- config.toml | 4 ++-- internal/builder/template.go | 30 +++++++++++------------------- templates/feed-styles.xsl | 4 +++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/config.toml b/config.toml index 6fc48a8..db9bab6 100644 --- a/config.toml +++ b/config.toml @@ -46,9 +46,9 @@ oidc_host = "https://id.alanpearce.eu/" ] 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", 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 diff --git a/templates/feed-styles.xsl b/templates/feed-styles.xsl index fcca39d..679d064 100644 --- a/templates/feed-styles.xsl +++ b/templates/feed-styles.xsl @@ -12,7 +12,9 @@ - +
-- cgit 1.4.1