add OpenGraph meta tags, for image preview inside chat apps like Telegram
This commit is contained in:
parent
0fbf401fd3
commit
0a338c4568
@ -17,8 +17,9 @@ import (
|
||||
var SERVER_HEADER string = `contented/0.0.0-dev`
|
||||
|
||||
type ServerPublicProperties struct {
|
||||
AppTitle string
|
||||
MaxUploadBytes int64
|
||||
AppTitle string
|
||||
MaxUploadBytes int64
|
||||
CanonicalBaseURL string
|
||||
}
|
||||
|
||||
type ServerOptions struct {
|
||||
|
25
preview.go
25
preview.go
@ -15,10 +15,31 @@ func (this *Server) handlePreview(w http.ResponseWriter, fileIDList string) {
|
||||
fileIDs := strings.Split(fileIDList, `-`)
|
||||
|
||||
tmpl := `<!DOCTYPE html>
|
||||
<html>
|
||||
<html prefix="og: http://ogp.me/ns#">
|
||||
<head>
|
||||
<title>` + html.EscapeString(this.opts.ServerPublicProperties.AppTitle) + `</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta property="og:title" content="` + html.EscapeString(this.opts.ServerPublicProperties.AppTitle) + `" />
|
||||
<meta property="og:site_name" content="` + html.EscapeString(this.opts.ServerPublicProperties.AppTitle) + `" />
|
||||
<meta property="og:type" content="website" />
|
||||
`
|
||||
|
||||
if len(this.opts.ServerPublicPropertyies.CanonicalBaseURL) > 0 {
|
||||
tmpl += `
|
||||
<meta property="og:url" content="` + html.EscapeString(this.opts.ServerPublicProperties.CanonicalBaseURL+`p/`+fileIDList) + `" />
|
||||
`
|
||||
}
|
||||
|
||||
for _, fileID := range fileIDs {
|
||||
tmpl += `
|
||||
<meta property="og:image" content="` + html.EscapeString(`/thumb/m/`+fileID) + `" />
|
||||
<meta property="og:image:type" content="image/jpeg" />
|
||||
<meta property="og:image:width" content="300" />
|
||||
<meta property="og:image:height" content="300" />
|
||||
`
|
||||
}
|
||||
|
||||
tmpl += `
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
background: #333;
|
||||
|
Loading…
Reference in New Issue
Block a user