github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/html/pages/pages.go (about)

     1  // Copyright 2022 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package pages
     5  
     6  import (
     7  	_ "embed" // for go:embed directives
     8  	"fmt"
     9  	"html/template"
    10  	"io/fs"
    11  	"strings"
    12  
    13  	"github.com/google/syzkaller/pkg/html"
    14  )
    15  
    16  func Create(page string) *template.Template {
    17  	page = strings.Replace(page, "{{HEAD}}", getHeadTemplate(), 1)
    18  	return template.Must(template.New("").Funcs(html.Funcs).Parse(page))
    19  }
    20  
    21  func CreateFromFS(fs fs.FS, patterns ...string) *template.Template {
    22  	t := template.Must(template.New("syz-head").Funcs(html.Funcs).Parse(getHeadTemplate()))
    23  	return template.Must(t.New("").Funcs(html.Funcs).ParseFS(fs, patterns...))
    24  }
    25  
    26  func getHeadTemplate() string {
    27  	const headTempl = `<style type="text/css" media="screen">%v</style><script>%v</script>`
    28  	return fmt.Sprintf(headTempl, style, js)
    29  }
    30  
    31  //go:embed style.css
    32  var style string
    33  
    34  //go:embed common.js
    35  var js string