Skip to content

Commit

Permalink
mailchimp: Include style tags; use new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Jun 6, 2024
1 parent 0961062 commit a042a9a
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 3 deletions.
15 changes: 14 additions & 1 deletion internal/mailchimp/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ func ImportPage(ctx context.Context, cl *http.Client, page string) (body string,
}

func PageContent(doc *html.Node) (body string, err error) {
// Move <style> tags into <body>. Shove content into @scope rules.
styleEls := xhtml.SelectSlice(doc, xhtml.WithAtom(atom.Style))
for _, styleEl := range styleEls {
styleEl.Parent.RemoveChild(styleEl)
styleEl.InsertBefore(&html.Node{
Type: html.TextNode,
Data: "\n@scope {\n",
}, styleEl.FirstChild)
xhtml.AppendText(styleEl, "\n}\n")
}

bNode := xhtml.Select(doc, xhtml.WithBody)
if bNode == nil {
err = fmt.Errorf("could not find body element")
Expand All @@ -42,7 +53,9 @@ func PageContent(doc *html.Node) (body string, err error) {
xhtml.Attr(n, "id") == "awesomewrap"
})
xhtml.RemoveAll(remove)

for _, styleEl := range styleEls {
bNode.InsertBefore(styleEl, bNode.FirstChild)
}
body = xhtml.InnerHTML(bNode)
return
}

0 comments on commit a042a9a

Please sign in to comment.