aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/html/pages/pages.go
blob: 51bc902c706a5f756598d340d02a069aaecdb7a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2022 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package pages

import (
	_ "embed" // for go:embed directives
	"fmt"
	"html/template"
	"io/fs"
	"strings"

	"github.com/google/syzkaller/pkg/html"
)

func Create(page string) *template.Template {
	page = strings.Replace(page, "{{HEAD}}", getHeadTemplate(), 1)
	return template.Must(template.New("").Funcs(html.Funcs).Parse(page))
}

func CreateFromFS(fs fs.FS, patterns ...string) *template.Template {
	t := template.Must(template.New("syz-head").Funcs(html.Funcs).Parse(getHeadTemplate()))
	return template.Must(t.New("").Funcs(html.Funcs).ParseFS(fs, patterns...))
}

func getHeadTemplate() string {
	const headTempl = `<style type="text/css" media="screen">%v</style><script>%v</script>`
	return fmt.Sprintf(headTempl, style, js)
}

//go:embed style.css
var style string

//go:embed common.js
var js string