Fixing the meta tags

This commit is contained in:
2017-12-17 18:10:59 +01:00
parent 49c28476a9
commit 310d7c5bf8
3 changed files with 62 additions and 19 deletions

View File

@@ -41,6 +41,7 @@ func ServeFileViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params
return
}
var ogData OGData
var err error
if list {
listdata := map[string]interface{}{
@@ -54,12 +55,14 @@ func ServeFileViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params
"Title": fmt.Sprintf("%d files in Pixeldrain", len(finfo)),
"APIResponse": listdata,
"Type": "list",
"OGData": ogData.FromFile(*finfo[0]),
})
} else {
err = templates.Get().ExecuteTemplate(w, "file_viewer", map[string]interface{}{
"Title": fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].FileName),
"APIResponse": finfo[0],
"Type": "file",
"OGData": ogData.FromFile(*finfo[0]),
})
}
if err != nil {

40
webcontroller/ogData.go Normal file
View File

@@ -0,0 +1,40 @@
package webcontroller
import (
"fornaxian.com/pixeldrain-web/pixelapi"
)
// OGData holds all information needed to populate the various meta tags on the
// file and list viewer
type OGData struct {
Title string
Type string
SiteName string
Description string
URL string
Image string
}
// FromFile populates the OGData object from FileInfo. It returns itself for
// compactness.
func (d *OGData) FromFile(f pixelapi.FileInfo) *OGData {
d.Title = f.FileName
d.Type = "website"
d.SiteName = "Pixeldrain"
d.Description = "View " + f.FileName + " on Pixeldrain"
d.URL = "/u/" + f.ID
d.Image = "/api/file/" + f.ID + "/thumbnail"
return d
}
// FromList populated the OGData object from a List. It returns itself for
// compactness.
func (d *OGData) FromList(l pixelapi.List) *OGData {
d.Title = l.Title
d.Type = "website"
d.SiteName = "Pixeldrain"
d.Description = "View " + l.Title + " on Pixeldrain"
d.URL = "/l/" + l.ID
d.Image = "/api/list/" + l.ID + "/thumbnail"
return d
}