Skip to content

Commit 4d7b3fd

Browse files
authored
Merge pull request #732 from DougReeder/default-site-name
Assembles informative & polished metadata from whatever values are available
2 parents 2432320 + 8aafb17 commit 4d7b3fd

12 files changed

+131
-65
lines changed

lib/ret/http_utils.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,20 @@ defmodule Ret.HttpUtils do
175175
defp module_config(key) do
176176
Application.get_env(:ret, __MODULE__)[key]
177177
end
178+
179+
def join_smart(enum) do
180+
Enum.reduce(enum, "", fn(x, acc) ->
181+
x = cond do
182+
!x -> nil
183+
is_binary(x) -> String.trim(x)
184+
true -> "#{x}"
185+
end
186+
if x && x != "" do
187+
if acc && acc != "", do: acc <> " — " <> x, else: x
188+
else
189+
acc
190+
end
191+
end)
192+
end
193+
178194
end

lib/ret_web/controllers/file_controller.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ defmodule RetWeb.FileController do
2626

2727
app_name =
2828
AppConfig.get_cached_config_value("translations|en|app-full-name") ||
29-
AppConfig.get_cached_config_value("translations|en|app-name")
30-
title = "Photo taken in #{app_name} immersive space, powered by Hubs"
29+
AppConfig.get_cached_config_value("translations|en|app-name") || RetWeb.Endpoint.host()
30+
title = "Photo taken in #{app_name} immersive space"
3131
config = AppConfig.get_config()
3232

3333
conn
@@ -36,7 +36,11 @@ defmodule RetWeb.FileController do
3636
content_type: content_type |> RetWeb.ContentType.sanitize_content_type(),
3737
content_length: content_length,
3838
title: title,
39+
description_social_media: Ret.HttpUtils.join_smart([
40+
config["translations"]["en"]["app-tagline"],
41+
"powered by Hubs"]),
3942
translations: config["translations"]["en"],
43+
app_name: app_name,
4044
images: config["images"],
4145
root_url: RetWeb.Endpoint.url()
4246
)

lib/ret_web/controllers/page_controller.ex

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule RetWeb.PageController do
1717

1818
alias Plug.Conn
1919
import Ret.ConnUtils
20+
import Ret.HttpUtils
2021

2122
##
2223
# NOTE: In addition to adding a route, you must add static html pages to the page_origin_warmer.ex
@@ -63,12 +64,19 @@ defmodule RetWeb.PageController do
6364
defp render_scene_content(%t{} = scene, conn) when t in [Scene, SceneListing] do
6465
{app_config, app_config_script} = generate_app_config()
6566

67+
app_name = app_config["translations"]["en"]["app-full-name"] || app_config["translations"]["en"]["app-name"] || RetWeb.Endpoint.host()
6668
scene_meta_tags =
6769
Phoenix.View.render_to_string(RetWeb.PageView, "scene-meta.html",
6870
scene: scene,
6971
ret_meta: Ret.Meta.get_meta(include_repo: false),
7072
translations: app_config["translations"]["en"],
71-
description: "A scene you can use in the #{app_config["translations"]["en"]["app-name"] || ''} immersive spaces and others powered by Hubs. #{app_config["translations"]["en"]["app-description"] || ''}" |> String.replace("\\n", " "),
73+
title: join_smart([ scene.name, app_name ]),
74+
name: scene.name,
75+
description: join_smart([
76+
scene.description,
77+
"A scene you can use in the #{app_name} immersive spaces and others powered by Hubs",
78+
app_config["translations"]["en"]["app-description"]
79+
]) |> String.replace("\\n", " "),
7280
app_config_script: {:safe, app_config_script |> with_script_tags},
7381
extra_script: {:safe, get_extra_script(:scene) |> with_script_tags},
7482
extra_html: {:safe, get_extra_html(:scene) || ""}
@@ -97,10 +105,13 @@ defmodule RetWeb.PageController do
97105
defp render_avatar_content(%t{} = avatar, conn) when t in [Avatar, AvatarListing] do
98106
{app_config, app_config_script} = generate_app_config()
99107

108+
app_name = app_config["translations"]["en"]["app-full-name"] || app_config["translations"]["en"]["app-name"] || RetWeb.Endpoint.host()
100109
avatar_meta_tags =
101110
Phoenix.View.render_to_string(RetWeb.PageView, "avatar-meta.html",
102111
avatar: avatar,
103-
description: "An avatar you can use in the #{app_config["translations"]["en"]["app-name"] || ""} immersive spaces and others powered by Hubs." |> String.replace("\\n", " "),
112+
title: join_smart([avatar.name, app_name]),
113+
name: avatar.name,
114+
description: "An avatar you can use in the #{app_name} immersive spaces and others powered by Hubs.",
104115
ret_meta: Ret.Meta.get_meta(include_repo: false),
105116
translations: app_config["translations"]["en"],
106117
root_url: RetWeb.Endpoint.url(),
@@ -132,13 +143,20 @@ defmodule RetWeb.PageController do
132143
defp render_homepage_content(conn, nil = _public_room_id) do
133144
{app_config, app_config_script} = generate_app_config()
134145

146+
app_name = app_config["translations"]["en"]["app-full-name"] || app_config["translations"]["en"]["app-name"] || RetWeb.Endpoint.host()
147+
135148
index_meta_tags =
136149
Phoenix.View.render_to_string(
137150
RetWeb.PageView,
138151
"index-meta.html",
139152
root_url: RetWeb.Endpoint.url(),
140153
translations: app_config["translations"]["en"],
141-
description: "#{app_config["translations"]["en"]["app-description"] || ''} — Immersive spaces, right in your browser, powered by Hubs" |> String.replace("\\n", " "),
154+
app_name: app_name,
155+
title: join_smart([app_name, app_config["translations"]["en"]["app-tagline"]]),
156+
description: join_smart(
157+
[app_config["translations"]["en"]["app-description"],
158+
"Immersive spaces, right in your browser, powered by Hubs"
159+
]),
142160
images: app_config["images"],
143161
app_config_script: {:safe, app_config_script |> with_script_tags},
144162
extra_script: {:safe, get_extra_script(:index) |> with_script_tags},
@@ -272,10 +290,11 @@ defmodule RetWeb.PageController do
272290
manifest =
273291
Phoenix.View.render_to_string(RetWeb.PageView, "manifest.webmanifest",
274292
root_url: RetWeb.Endpoint.url(),
275-
app_name: get_app_config_value("translations|en|app-name") || "",
276-
app_description:
277-
(get_app_config_value("translations|en|app-description") || "")
278-
|> String.replace("\\n", " ")
293+
app_name: get_app_config_value("translations|en|app-name") || RetWeb.Endpoint.host(),
294+
app_description: join_smart([
295+
get_app_config_value("translations|en|app-description"),
296+
"Immersive spaces, right in your browser, powered by Hubs"
297+
]) |> String.replace("\\n", " ")
279298
)
280299

281300
unless module_config(:skip_cache) do
@@ -394,7 +413,7 @@ defmodule RetWeb.PageController do
394413
|> put_resp_header(
395414
"hub-name",
396415
get_app_config_value("translations|en|app-full-name") ||
397-
get_app_config_value("translations|en|app-name") || ""
416+
get_app_config_value("translations|en|app-name") || RetWeb.Endpoint.host()
398417
)
399418
|> put_resp_header(
400419
"hub-entity-type",
@@ -462,14 +481,35 @@ defmodule RetWeb.PageController do
462481
{_, available_integrations_script} =
463482
Ret.Meta.available_integrations_meta() |> generate_config("AVAILABLE_INTEGRATIONS")
464483

484+
app_name = app_config["translations"]["en"]["app-name"] || RetWeb.Endpoint.host()
485+
scene = hub.scene || hub.scene_listing
486+
name = cond do
487+
hub.name && scene && scene.name && scene.name != hub.name -> join_smart([hub.name, scene.name])
488+
hub.name -> hub.name
489+
scene && scene.name -> scene.name
490+
true -> "a room on " <> app_name
491+
end
465492
hub_meta_tags =
466493
Phoenix.View.render_to_string(RetWeb.PageView, "hub-meta.html",
467494
hub: hub,
468-
scene: hub.scene,
495+
scene: scene,
469496
ret_meta: Ret.Meta.get_meta(include_repo: false),
470497
available_integrations_script: {:safe, available_integrations_script |> with_script_tags},
471498
translations: app_config["translations"]["en"],
472-
description: "Join others in an immersive space in #{app_config["translations"]["en"]["app-name"] || ''}, right in your browser. #{app_config["translations"]["en"]["app-description"] || ''} — Powered by Hubs." |> String.replace("\\n", " "),
499+
title: join_smart([hub.name, app_name]),
500+
name: name,
501+
description: join_smart([
502+
hub.description,
503+
"an immersive space in #{app_name}, right in your browser",
504+
app_config["translations"]["en"]["app-description"],
505+
"powered by Hubs."
506+
]) |> String.replace("\\n", " "),
507+
description_social_media: join_smart([
508+
"Join others in an immersive space in #{app_name}, right in your browser",
509+
hub.description,
510+
app_config["translations"]["en"]["app-description"],
511+
"powered by Hubs."
512+
]) |> String.replace("\\n", " "),
473513
app_config_script: {:safe, app_config_script |> with_script_tags},
474514
extra_script: {:safe, get_extra_script(:room) |> with_script_tags},
475515
extra_html: {:safe, get_extra_html(:room) || ""}

lib/ret_web/email.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule RetWeb.Email do
33
alias Ret.{AppConfig}
44

55
def auth_email(to_address, signin_args) do
6-
app_name = AppConfig.get_cached_config_value("translations|en|app-name")
6+
app_name = AppConfig.get_cached_config_value("translations|en|app-name") || RetWeb.Endpoint.host()
77
app_full_name = AppConfig.get_cached_config_value("translations|en|app-full-name") || app_name
88
admin_email = Application.get_env(:ret, Ret.Account)[:admin_email]
99
custom_login_subject = AppConfig.get_cached_config_value("auth|login_subject")

lib/ret_web/templates/file/show.html.eex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,34 @@
1313
"contentUrl": "<%= @image_url %>",
1414
"encodingFormat": "<%= @content_type %>",
1515
"contentSize": "<%= @content_length %> b",
16-
"keywords": ["screenshot", "Hubs", "immersive 3D spaces", "social VR", "<%= @translations["share-hashtag"] %>"],
16+
"keywords": ["screenshot", "Hubs", "immersive 3D spaces", "social VR", "<%= @translations["share-hashtag"] %>", "<%= @translations["company-name"] %>"],
17+
<%= if @translations["company-name"] || @translations["contact-email"] do %>
1718
"maintainer": {
1819
"@type": "Organization",
19-
"name": "<%= @translations["company-name"] %>",
20+
"name": "<%= @translations["company-name"] || @app_name %>",
2021
"email": "<%= @translations["contact-email"] %>",
2122
"logo": "<%= @images["company_logo"] %>"
2223
},
24+
<% end %>
2325
"isBasedOn": "<%= @root_url %>/",
24-
"creditText": "check with <%= @translations["company-name"] %>"
26+
"creditText": "check with <%= @translations["company-name"] || @app_name %>"
2527
}
2628
</script>
2729

2830
<meta name="twitter:card" content="summary_large_image">
2931
<meta name="twitter:domain" value="<%= RetWeb.Endpoint.host %>" />
3032
<meta name="twitter:title" value="<%= @title %>" />
31-
<meta name="twitter:description" content="<%= @title %>">
33+
<meta name="twitter:description" content="<%= @description_social_media %>">
3234
<meta name="twitter:image" content="<%= @image_url %>"/>
3335
<meta name="twitter:url" value="<%= @image_url %>" />
3436

3537
<meta property="og:type" content="website" />
3638
<meta property="og:url" content="<%= @image_url %>" />
3739
<meta property="og:title" content="<%= @title %>" />
38-
<meta property="og:description" content="<%= @title %>">
40+
<meta name="description" property="og:description" content="<%= @description_social_media %>">
3941
<meta property="og:image" content="<%= @image_url %>"/>
42+
<meta property="og:image:type" content="<%= @content_type %>" />
43+
<meta name="application-name" property="og:site_name" content="<%= @app_name %>" />
4044
<title><%= @title %></title>
4145
<style>
4246
body {
@@ -58,7 +62,7 @@
5862
</head>
5963
<body>
6064
<a href="<%= RetWeb.Endpoint.url %>">
61-
<img src="<%= @image_url %>"/>
65+
<img src="<%= @image_url %>" alt="<%= @title %>"/>
6266
</a>
6367
</body>
6468
</html>

lib/ret_web/templates/page/avatar-meta.html.eex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
{
33
"@context": "https://schema.org/",
44
"@type": "3DModel",
5-
"name": "<%= @avatar.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>",
5+
"name": "<%= @name %>",
66
"url": "<%= @avatar |> Ret.Avatar.url %>",
77
"contentUrl": "<%= @avatar.gltf_owned_file |> Ret.OwnedFile.uri_for |> URI.to_string %>",
88
"thumbnailUrl": "<%= @avatar.thumbnail_owned_file |> Ret.OwnedFile.uri_for |> URI.to_string %>",
99
"description": "<%= @description %>",
10-
"isResizable": false,
10+
"isResizable": true,
1111
"keywords": ["3D avatar", "Hubs", "immersive 3D spaces", "social VR", "<%= @translations["share-hashtag"] %>"],
1212
"isPartOf": "<%= @root_url %>/"
1313
}
1414
</script>
1515

1616
<meta property="og:type" content="website" />
1717
<meta property="og:url" content="<%= @avatar |> Ret.Avatar.url %>" />
18-
<meta property="og:title" content="<%= @avatar.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>" />
19-
<meta property="og:description" content="<%= @description %>" />
18+
<meta property="og:title" content="<%= @name %>" />
19+
<meta name="description" property="og:description" content="<%= @description %>" />
2020
<meta property="og:image" content="<%= @avatar.thumbnail_owned_file |> Ret.OwnedFile.uri_for |> URI.to_string %>"/>
21-
<meta property="og:site_name" content="<%= @translations["app-full-name"] || @translations["app-name"] %>"/>
21+
<meta name="application-name" property="og:site_name" content="<%= @translations["app-full-name"] || @translations["app-name"] || RetWeb.Endpoint.host() %>"/>
2222

2323
<meta name="twitter:card" content="summary_large_image">
2424
<meta name="twitter:domain" content="<%= RetWeb.Endpoint.host %>" />
25-
<meta name="twitter:title" content="<%= @avatar.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>" />
25+
<meta name="twitter:title" content="<%= @name %>" />
2626
<meta name="twitter:description" content="<%= @description %>" />
2727
<meta name="twitter:image" content="<%= @avatar.thumbnail_owned_file |> Ret.OwnedFile.uri_for |> URI.to_string %>"/>
2828
<meta name="twitter:url" content="<%= @avatar |> Ret.Avatar.url %>" />
@@ -32,8 +32,7 @@
3232
<meta name="ret:phx_port" value="<%= @ret_meta[:phx_port] %>" />
3333
<meta name="ret:pool" value="<%= @ret_meta[:pool] %>" />
3434

35-
<title><%= @avatar.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %></title>
36-
<meta name="description" content="<%= @description %>" />
35+
<title><%= @title %></title>
3736

3837
<%= @app_config_script %>
3938
<%= @extra_html %>

lib/ret_web/templates/page/hub-meta.html.eex

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@
44
{
55
"@context": "https://schema.org/",
66
"@type": "VirtualLocation",
7-
"name": "<%= @hub.name %> | <%= @translations["app-full-name"] || @translations["app-name"] || "" %>",
7+
"name": "<%= @name %>",
88
"url": "<%= @hub |> Ret.Hub.url_for %>",
99
"image": "<%= @hub |> Ret.Hub.image_url_for %>",
10-
"description": "<%= @description %>",
11-
"disambiguatingDescription": "<%= @scene && @scene.name %>"
10+
"description": "<%= @description %>"
1211
}
1312
</script>
1413

1514
<meta property="og:type" content="website" />
1615
<meta property="og:url" content="<%= @hub |> Ret.Hub.url_for %>" />
17-
<meta property="og:title" content="<%= @hub.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>" />
18-
<meta property="og:description" content="<%= @description %>" />
16+
<meta property="og:title" content="<%= @name %>" />
17+
<meta name="description" property="og:description" content="<%= @description_social_media %>" />
1918
<meta property="og:image" content="<%= @hub |> Ret.Hub.image_url_for %>"/>
20-
<meta property="og:site_name" content="<%= @translations["app-full-name"] || @translations["app-name"] %>"/>
21-
22-
<meta name="description" content="<%= @description %>" />
23-
24-
<meta itemprop="name" content="<%= @hub.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>" />
25-
<meta itemprop="description" content="<%= @description %>" />
19+
<meta name="application-name" property="og:site_name" content="<%= @translations["app-full-name"] || @translations["app-name"] || RetWeb.Endpoint.host() %>"/>
2620

2721
<meta name="twitter:card" content="summary_large_image">
2822
<meta name="twitter:domain" content="<%= RetWeb.Endpoint.host %>" />
29-
<meta name="twitter:title" content="<%= @hub.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %>" />
30-
<meta name="twitter:description" content="<%= @description %>" />
23+
<meta name="twitter:title" content="<%= @name %>" />
24+
<meta name="twitter:description" content="<%= @description_social_media %>" />
3125
<meta name="twitter:image" content="<%= @hub |> Ret.Hub.image_url_for %>"/>
3226
<meta name="twitter:url" content="<%= @hub |> Ret.Hub.url_for %>" />
3327

@@ -38,7 +32,7 @@
3832

3933
<link rel="apple-touch-icon" href="/app-icon.png">
4034

41-
<title><%= @hub.name %> | <%= @translations["app-full-name"] || @translations["app-name"] %></title>
35+
<title><%= @title %></title>
4236

4337
<%= @available_integrations_script %>
4438
<%= @app_config_script %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
appFullName = "<%= @translations["app-full-name"] || @translations["app-name"] %>";
1+
appFullName = "<%= @translations["app-full-name"] || @translations["app-name"] || RetWeb.Endpoint.host() %>";

0 commit comments

Comments
 (0)