Use bundled images instead of old webroot files

This commit is contained in:
Gabe Kangas
2022-06-20 21:43:53 -07:00
parent d3a5ebd4be
commit 18a184eeb7
168 changed files with 164 additions and 260 deletions

32
static/static.go vendored
View File

@@ -3,6 +3,8 @@ package static
import (
"embed"
"html/template"
"io/fs"
"log"
"os"
"path/filepath"
@@ -16,14 +18,30 @@ import (
var webFiles embed.FS
// GetWeb will return an embedded filesystem reference to the admin web app.
func GetWeb() embed.FS {
return webFiles
func GetWeb() fs.FS {
wf, err := fs.Sub(webFiles, "web")
if err != nil {
log.Fatal(err)
}
return wf
}
//go:embed img/emoji/*
var emojiFiles embed.FS
// GetEmoji will return the emoji files.
func GetEmoji() fs.FS {
ef, err := fs.Sub(emojiFiles, "img/emoji")
if err != nil {
log.Fatal(err)
}
return ef
}
// GetWebIndexTemplate will return the bot/scraper metadata template.
func GetWebIndexTemplate() (*template.Template, error) {
webFiles := GetWeb()
name := "web/index.html"
name := "index.html"
t, err := template.ParseFS(webFiles, name)
if err != nil {
return nil, errors.Wrap(err, "unable to open index.html template")
@@ -41,6 +59,14 @@ func GetOfflineSegment() []byte {
return getFileSystemStaticFileOrDefault("offline.ts", offlineVideoSegment)
}
//go:embed img/logo.png
var logo []byte
// GetLogo will return the logo data.
func GetLogo() []byte {
return getFileSystemStaticFileOrDefault("img/logo.png", logo)
}
func getFileSystemStaticFileOrDefault(path string, defaultData []byte) []byte {
fullPath := filepath.Join("static", path)
data, err := os.ReadFile(fullPath) //nolint: gosec