support new thumbnail api
This commit is contained in:
@@ -86,12 +86,14 @@ func metadataFromList(l pixelapi.List) (meta template.HTML) {
|
||||
meta += ogRule{"og:description", "View '" + l.Title + "' on pixeldrain"}.HTML()
|
||||
meta += ogRule{"description", "View '" + l.Title + "' on pixeldrain"}.HTML()
|
||||
meta += ogRule{"og:url", "/l/" + l.ID}.HTML()
|
||||
meta += ogRule{"og:image", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += ogRule{"og:image:url", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += twitterRule{"twitter:image", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += twitterRule{"twitter:title", l.Title}.HTML()
|
||||
meta += twitterRule{"twitter:site", "@Fornax96"}.HTML()
|
||||
meta += twitterRule{"twitter:domain", "pixeldrain.com"}.HTML()
|
||||
meta += linkRule{"image_src", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
if l.FileCount > 0 {
|
||||
meta += ogRule{"og:image", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += ogRule{"og:image:url", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += twitterRule{"twitter:image", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
meta += linkRule{"image_src", "/api/file/" + l.Files[0].ID + "/thumbnail"}.HTML()
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fornaxian.com/pixeldrain-api/util"
|
||||
"github.com/Fornaxian/log"
|
||||
)
|
||||
|
||||
@@ -75,13 +76,14 @@ func (tm *TemplateManager) Get() *template.Template {
|
||||
|
||||
func (tm *TemplateManager) funcMap() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"bgPattern": tm.bgPattern,
|
||||
"isBrave": tm.isBrave,
|
||||
"debugMode": tm.debugMode,
|
||||
"apiUrl": tm.apiURL,
|
||||
"pageNr": tm.pageNr,
|
||||
"add": tm.add,
|
||||
"sub": tm.sub,
|
||||
"bgPattern": tm.bgPattern,
|
||||
"isBrave": tm.isBrave,
|
||||
"debugMode": tm.debugMode,
|
||||
"apiUrl": tm.apiURL,
|
||||
"pageNr": tm.pageNr,
|
||||
"add": tm.add,
|
||||
"sub": tm.sub,
|
||||
"formatData": tm.formatData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +110,38 @@ func (tm *TemplateManager) pageNr(s string) (nr int) {
|
||||
}
|
||||
return nr
|
||||
}
|
||||
func (tm *TemplateManager) add(a, b int) int {
|
||||
return a + b
|
||||
func (tm *TemplateManager) add(a, b interface{}) int {
|
||||
return detectInt(a) + detectInt(b)
|
||||
}
|
||||
func (tm *TemplateManager) sub(a, b int) int {
|
||||
return a - b
|
||||
func (tm *TemplateManager) sub(a, b interface{}) int {
|
||||
return detectInt(a) - detectInt(b)
|
||||
}
|
||||
func (tm *TemplateManager) formatData(i int) string {
|
||||
return util.FormatData(uint64(i))
|
||||
}
|
||||
|
||||
func detectInt(i interface{}) int {
|
||||
switch v := i.(type) {
|
||||
case int:
|
||||
return int(v)
|
||||
case int8:
|
||||
return int(v)
|
||||
case int16:
|
||||
return int(v)
|
||||
case int32:
|
||||
return int(v)
|
||||
case int64:
|
||||
return int(v)
|
||||
case uint:
|
||||
return int(v)
|
||||
case uint8:
|
||||
return int(v)
|
||||
case uint16:
|
||||
return int(v)
|
||||
case uint32:
|
||||
return int(v)
|
||||
case uint64:
|
||||
return int(v)
|
||||
}
|
||||
panic(fmt.Sprintf("%v is not an int", i))
|
||||
}
|
||||
|
Reference in New Issue
Block a user