diff --git a/common/attachments.go b/common/attachments.go index 32472b4f..ba78b554 100644 --- a/common/attachments.go +++ b/common/attachments.go @@ -6,6 +6,7 @@ import ( //"fmt" "os" + "path/filepath" "strings" qgen "github.com/Azareal/Gosora/query_gen" @@ -101,16 +102,14 @@ func (s *DefaultAttachmentStore) MiniGetList(originTable string, originID int) ( if err != nil { return nil, err } - extarr := strings.Split(a.Path, ".") - if len(extarr) < 2 { + a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".") + if len(a.Ext) == 0 { return nil, errors.New("corrupt attachment path") } - a.Ext = extarr[len(extarr)-1] a.Image = ImageFileExts.Contains(a.Ext) alist = append(alist, a) } - err = rows.Err() - if err != nil { + if err = rows.Err(); err != nil { return nil, err } if len(alist) == 0 { @@ -139,11 +138,10 @@ func (s *DefaultAttachmentStore) BulkMiniGetList(originTable string, ids []int) if err != nil { return nil, err } - extarr := strings.Split(a.Path, ".") - if len(extarr) < 2 { + a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".") + if len(a.Ext) == 0 { return nil, errors.New("corrupt attachment path") } - a.Ext = extarr[len(extarr)-1] a.Image = ImageFileExts.Contains(a.Ext) if currentID == 0 { currentID = a.OriginID @@ -169,11 +167,10 @@ func (s *DefaultAttachmentStore) FGet(id int) (*Attachment, error) { if err != nil { return nil, err } - extarr := strings.Split(a.Path, ".") - if len(extarr) < 2 { + a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".") + if len(a.Ext) == 0 { return nil, errors.New("corrupt attachment path") } - a.Ext = extarr[len(extarr)-1] a.Image = ImageFileExts.Contains(a.Ext) return a, nil } @@ -184,11 +181,10 @@ func (s *DefaultAttachmentStore) Get(id int) (*MiniAttachment, error) { if err != nil { return nil, err } - extarr := strings.Split(a.Path, ".") - if len(extarr) < 2 { + a.Ext = strings.TrimPrefix(filepath.Ext(a.Path), ".") + if len(a.Ext) == 0 { return nil, errors.New("corrupt attachment path") } - a.Ext = extarr[len(extarr)-1] a.Image = ImageFileExts.Contains(a.Ext) return a, nil } diff --git a/common/routes_common.go b/common/routes_common.go index 491ec20c..bd5b2303 100644 --- a/common/routes_common.go +++ b/common/routes_common.go @@ -126,12 +126,10 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, u *User) (h *Header, if len(theme.Resources) > 0 { rlist := theme.Resources for _, res := range rlist { - if res.Location == "global" || res.Location == "panel" { - extarr := strings.Split(res.Name, ".") - ext := extarr[len(extarr)-1] - if ext == "css" { + if res.LocID == LocGlobal || res.LocID == LocPanel { + if res.Type == ResTypeSheet { h.AddSheet(res.Name) - } else if ext == "js" { + } else if res.Type == ResTypeScript { if res.Async { h.AddScriptAsync(res.Name) } else { @@ -252,12 +250,10 @@ func PrepResources(u *User, h *Header, theme *Theme) { if res.Loggedin && !u.Loggedin { continue } - if res.Location == "global" || res.Location == "frontend" { - extarr := strings.Split(res.Name, ".") - ext := extarr[len(extarr)-1] - if ext == "css" { + if res.LocID == LocGlobal || res.LocID == LocFront { + if res.Type == ResTypeSheet { h.AddSheet(res.Name) - } else if ext == "js" { + } else if res.Type == ResTypeScript { if res.Async { h.AddScriptAsync(res.Name) } else { diff --git a/common/theme.go b/common/theme.go index 504b513e..8ea36276 100644 --- a/common/theme.go +++ b/common/theme.go @@ -75,9 +75,23 @@ type TemplateMapping struct { //When string } +const ( + ResTypeUnknown = iota + ResTypeSheet + ResTypeScript +) +const ( + LocUnknown = iota + LocGlobal + LocFront + LocPanel +) + type ThemeResource struct { Name string + Type int // 0 = unknown, 1 = sheet, 2 = script Location string + LocID int Loggedin bool // Only serve this resource to logged in users Async bool } diff --git a/common/theme_list.go b/common/theme_list.go index 5d21594a..2f34abd1 100644 --- a/common/theme_list.go +++ b/common/theme_list.go @@ -177,6 +177,23 @@ func NewThemeList() (themes ThemeList, err error) { log.Print("no overrides for " + theme.Name) } + for i, res := range theme.Resources { + ext := filepath.Ext(res.Name) + if ext == ".css" { + res.Type = ResTypeSheet + } else if ext == ".js" { + res.Type = ResTypeScript + } + if res.Location == "global" { + res.LocID = LocGlobal + } else if res.Location == "frontend" { + res.LocID = LocFront + } else if res.Location == "panel" { + res.LocID = LocPanel + } + theme.Resources[i] = res + } + // TODO: Bind the built template, or an interpreted one for any dock overrides this theme has themes[theme.Name] = theme diff --git a/routes/api.go b/routes/api.go index 176ca80f..631c9087 100644 --- a/routes/api.go +++ b/routes/api.go @@ -263,8 +263,8 @@ func OpenSearchXml(w http.ResponseWriter, r *http.Request) c.RouteError { w.Write([]byte(` ` + c.Site.Name + ` UTF-8 - - + + ` + furl + ` `)) return nil diff --git a/templates/header.html b/templates/header.html index a8f0c575..eb860880 100644 --- a/templates/header.html +++ b/templates/header.html @@ -13,16 +13,16 @@ {{range .Header.Scripts}} {{end}} - - {{if .Header.MetaDesc}}{{end}} + + {{if .Header.MetaDesc}}{{end}} {{/** TODO: Have page / forum / topic level tags and descriptions below as-well **/}} - + - - {{if .OGDesc}} - {{end}} - {{if .GoogSiteVerify}}{{end}} + + {{if .OGDesc}} + {{end}} + {{if .GoogSiteVerify}}{{end}}