package html
import (
"fmt"
"io/ioutil"
"log"
"net/url"
"path/filepath"
"regexp"
"strings"
"unsafe"
"github.com/tdewolff/minify"
"github.com/tdewolff/minify/js"
)
type assetTypes struct {
JS string
CSS string
FAVICON string
HTML string
}
// AssetTypes is an enum for the asset type keys
var AssetTypes *assetTypes = &assetTypes{
JS: "javascript",
CSS: "css",
FAVICON: "favicon",
HTML: "html",
}
// Asset describes an asset type and its path
type Asset struct {
Type string
Path string
Data string
}
// Load the asset from disk
func (a *Asset) Load(basedirectory string) error {
assetpath := filepath.Join(basedirectory, a.Path)
data, err := ioutil.ReadFile(assetpath)
if err != nil {
return err
}
a.Data = string(data)
return nil
}
// AsString returns the data as a READ ONLY string
func (a *Asset) AsString() string {
return a.Data
}
// AsCHexData processes the asset data so it may be used by C
func (a *Asset) AsCHexData() string {
// This will be our final string to hexify
dataString := a.Data
switch a.Type {
case AssetTypes.HTML:
// Escape HTML
var re = regexp.MustCompile(`\s{2,}`)
result := re.ReplaceAllString(a.Data, ``)
result = strings.ReplaceAll(result, "\n", "")
result = strings.ReplaceAll(result, "\r\n", "")
result = strings.ReplaceAll(result, "\n", "")
// Inject wailsloader code
result = strings.Replace(result, `