minify menu templates

save bytes in init.js
This commit is contained in:
Azareal 2020-03-23 11:37:35 +10:00
parent a3d6f1c844
commit 0635627950
3 changed files with 19 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import (
"strings"
"github.com/Azareal/Gosora/common/phrases"
tmpl "github.com/Azareal/Gosora/common/templates"
qgen "github.com/Azareal/Gosora/query_gen"
)
@ -98,12 +99,12 @@ func (i MenuItem) Delete() error {
return err
}
func (h *MenuListHolder) LoadTmpl(name string) (menuTmpl MenuTmpl, err error) {
func (h *MenuListHolder) LoadTmpl(name string) (t MenuTmpl, err error) {
data, err := ioutil.ReadFile("./templates/" + name + ".html")
if err != nil {
return menuTmpl, err
return t, err
}
return h.Parse(name, data), nil
return h.Parse(name, []byte(tmpl.Minify(string(data)))), nil
}
// TODO: Make this atomic, maybe with a transaction or store the order on the menu itself?
@ -120,7 +121,7 @@ func (h *MenuListHolder) UpdateOrder(updateMap map[int]int) error {
func (h *MenuListHolder) LoadTmpls() (tmpls map[string]MenuTmpl, err error) {
tmpls = make(map[string]MenuTmpl)
loadTmpl := func(name string) error {
load := func(name string) error {
menuTmpl, err := h.LoadTmpl(name)
if err != nil {
return err
@ -128,11 +129,11 @@ func (h *MenuListHolder) LoadTmpls() (tmpls map[string]MenuTmpl, err error) {
tmpls[name] = menuTmpl
return nil
}
err = loadTmpl("menu_item")
err = load("menu_item")
if err != nil {
return tmpls, err
}
err = loadTmpl("menu_alerts")
err = load("menu_alerts")
return tmpls, err
}
@ -326,13 +327,13 @@ func (h *MenuListHolder) Parse(name string, tmplData []byte) (menuTmpl MenuTmpl)
return MenuTmpl{name, textBuffer, variableBuffer, renderList}
}
func (h *MenuListHolder) Scan(menuTmpls map[string]MenuTmpl, showItem func(i MenuItem) bool) (renderBuffer [][]byte, variableIndices []int, pathList []menuPath) {
func (h *MenuListHolder) Scan(tmpls map[string]MenuTmpl, showItem func(i MenuItem) bool) (renderBuffer [][]byte, variableIndices []int, pathList []menuPath) {
for _, mitem := range h.List {
// Do we want this item in this variation of the menu?
if !showItem(mitem) {
continue
}
renderBuffer, variableIndices = h.ScanItem(menuTmpls, mitem, renderBuffer, variableIndices)
renderBuffer, variableIndices = h.ScanItem(tmpls, mitem, renderBuffer, variableIndices)
pathList = append(pathList, menuPath{mitem.Path, len(renderBuffer) - 1})
}
@ -341,10 +342,10 @@ func (h *MenuListHolder) Scan(menuTmpls map[string]MenuTmpl, showItem func(i Men
}
// Note: This doesn't do a visibility check like hold.Scan() does
func (h *MenuListHolder) ScanItem(menuTmpls map[string]MenuTmpl, mitem MenuItem, renderBuffer [][]byte, variableIndices []int) ([][]byte, []int) {
menuTmpl, ok := menuTmpls[mitem.TmplName]
func (h *MenuListHolder) ScanItem(tmpls map[string]MenuTmpl, mitem MenuItem, renderBuffer [][]byte, variableIndices []int) ([][]byte, []int) {
menuTmpl, ok := tmpls[mitem.TmplName]
if !ok {
menuTmpl = menuTmpls["menu_item"]
menuTmpl = tmpls["menu_item"]
}
for _, renderItem := range menuTmpl.RenderList {

View File

@ -142,13 +142,13 @@ function loadScript(name,callback,fail) {
function RelativeTime(date) {return date}
function initPhrases(member, acp=false) {
function initPhrases(member,acp=false) {
console.log("initPhrases")
console.log("tmlInits",tmplInits)
let e = "";
if(member && !acp) e = ",status,topic_list,topic";
else if(acp) e = ",analytics,panel"; // TODO: Request phrases for just one section of the cp?
else e = ",status,topic_list";
if(member && !acp) e=",status,topic_list,topic";
else if(acp) e=",analytics,panel"; // TODO: Request phrases for just one section of the acp?
else e=",status,topic_list";
fetchPhrases("alerts,paginator"+e) // TODO: Break this up?
}

View File

@ -1,6 +1,6 @@
<li id="general_alerts" class="menu_right menu_alerts">
<li id="general_alerts"class="menu_right menu_alerts">
<div class="alert_bell"></div>
<div class="alert_counter" aria-label="{{lang "menu_alert_counter_aria"}}"></div>
<div class="alert_counter"aria-label="{{lang "menu_alert_counter_aria"}}"></div>
<div class="alert_aftercounter"></div>
<div class="alertList" aria-label="{{lang "menu_alert_list_aria"}}"></div>
<div class="alertList"aria-label="{{lang "menu_alert_list_aria"}}"></div>
</li>