MCPcopy Create free account
hub / github.com/adhocteam/pushup / appendDevReloaderScript

Function appendDevReloaderScript

reloader.go:248–277  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

246`
247
248func appendDevReloaderScript(r io.Reader) (*html.Node, error) {
249 doc, err := html.Parse(r)
250 if err != nil {
251 return nil, fmt.Errorf("parsing HTML: %w", err)
252 }
253 var f func(*html.Node)
254 f = func(n *html.Node) {
255 if n.Type == html.ElementNode && n.Data == "body" {
256 text := &html.Node{
257 Type: html.TextNode,
258 Data: devReloaderScript,
259 }
260 script := &html.Node{
261 Type: html.ElementNode,
262 Data: "script",
263 DataAtom: atom.Script,
264 Attr: []html.Attribute{
265 {Key: "type", Val: "text/javascript"},
266 },
267 }
268 script.AppendChild(text)
269 n.AppendChild(script)
270 }
271 for c := n.FirstChild; c != nil; c = c.NextSibling {
272 f(c)
273 }
274 }
275 f(doc)
276 return doc, nil
277}
278
279func debounceEvents(ctx context.Context, interval time.Duration, watcher *fsnotify.Watcher, fn func(event fsnotify.Event)) {
280 var mu sync.Mutex

Callers 1

Calls 1

fFunction · 0.50

Tested by

no test coverage detected