Skip to content

Commit 763ddd7

Browse files
committed
Implemented experimental ajax crawling support to get better social integration with open graph tags.
1 parent 8d80614 commit 763ddd7

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

html/crawler.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%define "crawlerPage"%><!doctype html>
2+
<html>
3+
<head>
4+
<meta property="og:title" content="/<%.Room%>" />
5+
<meta property="og:site_name" content="<%.Cfg.Title%>"/>
6+
<meta property="og:image" content="<%.Scheme%>://<%.Host%><%.Cfg.B%>static/img/opengraph-image.png" />
7+
<meta property="og:type" content="article" />
8+
</head>
9+
<body></body>
10+
</html><%end%>

html/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%define "head"%><title><%.Cfg.Title%></title>
2+
<meta name="fragment" content="!">
23
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
34
<meta name="apple-mobile-web-app-capable" content="yes">
45
<meta name="mobile-web-app-capable" content="yes">

src/app/spreed-webrtc-server/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ type Context struct {
2727
Host string
2828
Ssl bool
2929
Languages []string
30+
Room string `json:"-"`
31+
Scheme string `json:"-"`
3032
}

src/app/spreed-webrtc-server/main.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,20 @@ func makeImageHandler(hub *Hub, expires time.Duration) http.HandlerFunc {
117117

118118
func handleRoomView(room string, w http.ResponseWriter, r *http.Request) {
119119

120+
var err error
121+
120122
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
121123
w.Header().Set("Expires", "-1")
122124
w.Header().Set("Cache-Control", "private, max-age=0")
123125

126+
scheme := "http"
127+
124128
// Detect if the request was made with SSL.
125129
ssl := r.TLS != nil
126130
proto, ok := r.Header["X-Forwarded-Proto"]
127131
if ok {
128132
ssl = proto[0] == "https"
133+
scheme = "https"
129134
}
130135

131136
// Get languages from request.
@@ -134,11 +139,22 @@ func handleRoomView(room string, w http.ResponseWriter, r *http.Request) {
134139
langs = append(langs, "en")
135140
}
136141

137-
// Prepare context to deliver to Javascript.
138-
context := &Context{Cfg: config, App: "main", Host: r.Host, Ssl: ssl, Languages: langs}
142+
// Prepare context to deliver to HTML..
143+
context := &Context{Cfg: config, App: "main", Host: r.Host, Scheme: scheme, Ssl: ssl, Languages: langs, Room: room}
144+
145+
// Get URL parameters.
146+
r.ParseForm()
147+
148+
// Check if incoming request is a crawler which supports AJAX crawling.
149+
// See https://developers.google.com/webmasters/ajax-crawling/docs/getting-started for details.
150+
if _, ok := r.Form["_escaped_fragment_"]; ok {
151+
// Render crawlerPage template..
152+
err = templates.ExecuteTemplate(w, "crawlerPage", &context)
153+
} else {
154+
// Render mainPage template.
155+
err = templates.ExecuteTemplate(w, "mainPage", &context)
156+
}
139157

140-
// Render the template.
141-
err := templates.ExecuteTemplate(w, "mainPage", &context)
142158
if err != nil {
143159
http.Error(w, err.Error(), http.StatusInternalServerError)
144160
}

static/img/opengraph-image.png

29.9 KB
Loading

0 commit comments

Comments
 (0)