diff options
author | Alan Pearce | 2024-06-25 09:37:00 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-25 09:37:00 +0200 |
commit | 27cf354a0e5d5b25aba64cc58406c821f2cecfca (patch) | |
tree | e37d7222ddcca2db3b57a697c8909f5929bdcc0f | |
parent | becede4bfead952239b9cf7c8eb9fb96d01534ec (diff) | |
download | website-27cf354a0e5d5b25aba64cc58406c821f2cecfca.tar.lz website-27cf354a0e5d5b25aba64cc58406c821f2cecfca.tar.zst website-27cf354a0e5d5b25aba64cc58406c821f2cecfca.zip |
fix missing spacing in feed preview
-rw-r--r-- | config.toml | 4 | ||||
-rw-r--r-- | internal/builder/template.go | 30 | ||||
-rw-r--r-- | 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 @@ <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> |