Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Support server-rendered index.html for all clients. Closes #1871

Gabe Kangas0554d85d8c90
diff --git a/controllers/index.go b/controllers/index.go
index 0920fb98a5..20753d2c14 100644
--- a/controllers/index.go
+++ b/controllers/index.go
@@ -36,12 +36,6 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
isIndexRequest := r.URL.Path == "/" || filepath.Base(r.URL.Path) == "index.html" || filepath.Base(r.URL.Path) == ""
if isIndexRequest {
- serveWeb(w, r)
- return
- }
- // For search engine bots and social scrapers return a special
- // server-rendered page.
- if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {
handleScraperMetadataPage(w, r)
return
}
@@ -78,7 +72,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
// Return a basic HTML page with server-rendered metadata from the config
// to give to Opengraph clients and web scrapers (bots, web crawlers, etc).
func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
- tmpl, err := static.GetBotMetadataTemplate()
+ tmpl, err := static.GetWebIndexTemplate()
if err != nil {
log.Errorln(err)
w.WriteHeader(http.StatusInternalServerError)
diff --git a/static/static.go b/static/static.go
index d8a546853a..5aa5945bd3 100644
--- a/static/static.go
+++ b/static/static.go
@@ -5,6 +5,8 @@ import (
"html/template"
"os"
"path/filepath"
+
+ "github.com/pkg/errors"
)
//go:embed web/*
@@ -18,13 +20,15 @@ func GetWeb() embed.FS {
return webFiles
}
-//go:embed metadata.html.tmpl
-var botMetadataTemplate embed.FS
+// GetWebIndexTemplate will return the bot/scraper metadata template.
+func GetWebIndexTemplate() (*template.Template, error) {
+ webFiles := GetWeb()
+ name := "web/index.html"
+ t, err := template.ParseFS(webFiles, name)
+ if err != nil {
+ return nil, errors.Wrap(err, "unable to open index.html template")
+ }
-// GetBotMetadataTemplate will return the bot/scraper metadata template.
-func GetBotMetadataTemplate() (*template.Template, error) {
- name := "metadata.html.tmpl"
- t, err := template.ParseFS(botMetadataTemplate, name)
tmpl := template.Must(t, err)
return tmpl, err
}
diff --git a/utils/utils.go b/utils/utils.go
index f6a32762aa..6cd6049401 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -15,7 +15,6 @@ import (
"strings"
"time"
- "github.com/mssola/user_agent"
log "github.com/sirupsen/logrus"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
@@ -98,34 +97,6 @@ func moveFallback(source, destination string) error {
return nil
}
-// IsUserAgentABot returns if a web client user-agent is seen as a bot.
-func IsUserAgentABot(userAgent string) bool {
- if userAgent == "" {
- return false
- }
-
- botStrings := []string{
- "mastodon",
- "pleroma",
- "applebot",
- "whatsapp",
- "matrix",
- "synapse",
- "element",
- "rocket.chat",
- "duckduckbot",
- }
-
- for _, botString := range botStrings {
- if strings.Contains(strings.ToLower(userAgent), botString) {
- return true
- }
- }
-
- ua := user_agent.New(userAgent)
- return ua.Bot()
-}
-
// IsUserAgentAPlayer returns if a web client user-agent is seen as a media player.
func IsUserAgentAPlayer(userAgent string) bool {
if userAgent == "" {
diff --git a/utils/utils_test.go b/utils/utils_test.go
index 9b8bfcdbc2..cdabe55ea4 100644
--- a/utils/utils_test.go
+++ b/utils/utils_test.go
@@ -4,21 +4,6 @@ import (
"testing"
)
-func TestUserAgent(t *testing.T) {
- testAgents := []string{
- "Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site [email protected]",
- "Mastodon 1.2.3 Bot",
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15 (Applebot/0.1; +http://www.apple.com/go/applebot)",
- "WhatsApp",
- }
-
- for _, agent := range testAgents {
- if !IsUserAgentABot(agent) {
- t.Error("Incorrect parsing of useragent", agent)
- }
- }
-}
-
func TestGetHashtagsFromText(t *testing.T) {
text := `Some text with a #hashtag goes here.\n\n
Another #secondhashtag, goes here.\n\n
diff --git a/web/components/layouts/Main.tsx b/web/components/layouts/Main.tsx
index 900e2a41f7..7bc4e7e39d 100644
--- a/web/components/layouts/Main.tsx
+++ b/web/components/layouts/Main.tsx
@@ -1,5 +1,6 @@
import { Layout } from 'antd';
import { useRecoilValue } from 'recoil';
+import Head from 'next/head';
import {
ClientConfigStore,
isChatAvailableSelector,
@@ -19,6 +20,63 @@ function Main() {
return (
<>
+ <Head>
+ <meta name="description" content="{{.Summary}}" />
+
+ <meta property="og:title" content="{{.Name}}" />
+ <meta property="og:site_name" content="{{.Name}}" />
+ <meta property="og:url" content="{{.RequestedURL}}" />
+ <meta property="og:description" content="{{.Summary}}" />
+ <meta property="og:type" content="video.other" />
+ <meta property="video:tag" content="{{.TagsString}}" />
+
+ <meta property="og:image" content="{{.Thumbnail}}" />
+ <meta property="og:image:url" content="{{.Thumbnail}}" />
+ <meta property="og:image:alt" content="{{.Image}}" />
+
+ <meta property="og:video" content="{{.RequestedURL}}embed/video" />
+ <meta property="og:video:secure_url" content="{{.RequestedURL}}embed/video" />
+ <meta property="og:video:height" content="315" />
+ <meta property="og:video:width" content="560" />
+ <meta property="og:video:type" content="text/html" />
+ <meta property="og:video:actor" content="{{.Name}}" />
+
+ <meta property="twitter:title" content="{{.Name}}" />
+ <meta property="twitter:url" content="{{.RequestedURL}}" />
+ <meta property="twitter:description" content="{{.Summary}}" />
+ <meta property="twitter:image" content="{{.Image}}" />
+ <meta property="twitter:card" content="player" />
+ <meta property="twitter:player" content="{{.RequestedURL}}embed/video" />
+ <meta property="twitter:player:width" content="560" />
+ <meta property="twitter:player:height" content="315" />
+
+ <link rel="apple-touch-icon" sizes="57x57" href="/img/favicon/apple-icon-57x57.png" />
+ <link rel="apple-touch-icon" sizes="60x60" href="/img/favicon/apple-icon-60x60.png" />
+ <link rel="apple-touch-icon" sizes="72x72" href="/img/favicon/apple-icon-72x72.png" />
+ <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon/apple-icon-76x76.png" />
+ <link rel="apple-touch-icon" sizes="114x114" href="/img/favicon/apple-icon-114x114.png" />
+ <link rel="apple-touch-icon" sizes="120x120" href="/img/favicon/apple-icon-120x120.png" />
+ <link rel="apple-touch-icon" sizes="144x144" href="/img/favicon/apple-icon-144x144.png" />
+ <link rel="apple-touch-icon" sizes="152x152" href="/img/favicon/apple-icon-152x152.png" />
+ <link rel="apple-touch-icon" sizes="180x180" href="/img/favicon/apple-icon-180x180.png" />
+ <link
+ rel="icon"
+ type="image/png"
+ sizes="192x192"
+ href="/img/favicon/android-icon-192x192.png"
+ />
+ <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="96x96" href="/img/favicon/favicon-96x96.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon/favicon-16x16.png" />
+ <link rel="manifest" href="/manifest.json" />
+
+ <link href="/api/auth/provider/indieauth" />
+
+ <meta name="msapplication-TileColor" content="#ffffff" />
+ <meta name="msapplication-TileImage" content="/img/favicon/ms-icon-144x144.png" />
+ <meta name="theme-color" content="#ffffff" />
+ </Head>
+
<ClientConfigStore />
<Layout>
<Header name={title || name} chatAvailable={isChatAvailable} />