mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 07:23:40 +08:00
FIX: Safari iOS page title and url regression when sharing (#11699)
This commit is contained in:
parent
e52ccaa51f
commit
26337408a9
|
@ -0,0 +1,20 @@
|
||||||
|
import { getAbsoluteURL } from "discourse-common/lib/get-url";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "opengraph-tag-updater",
|
||||||
|
|
||||||
|
initialize(container) {
|
||||||
|
// workaround for Safari on iOS 14.3
|
||||||
|
// seems it has started using opengraph tags when sharing
|
||||||
|
let appEvents = container.lookup("service:app-events");
|
||||||
|
const ogTitle = document.querySelector("meta[property='og:title']"),
|
||||||
|
ogUrl = document.querySelector("meta[property='og:url']");
|
||||||
|
|
||||||
|
if (ogTitle && ogUrl) {
|
||||||
|
appEvents.on("page:changed", (data) => {
|
||||||
|
ogTitle.setAttribute("content", data.title);
|
||||||
|
ogUrl.setAttribute("content", getAbsoluteURL(data.url));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { click, visit } from "@ember/test-helpers";
|
||||||
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
|
||||||
|
acceptance("Opengraph Tag Updater", function (needs) {
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/about", () => {
|
||||||
|
return helper.response({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates OG title and URL", async function (assert) {
|
||||||
|
await visit("/");
|
||||||
|
await click("#toggle-hamburger-menu");
|
||||||
|
await click("a.about-link");
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
document
|
||||||
|
.querySelector("meta[property='og:title']")
|
||||||
|
.getAttribute("content"),
|
||||||
|
document.title,
|
||||||
|
"it should update OG title"
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
document
|
||||||
|
.querySelector("meta[property='og:url']")
|
||||||
|
.getAttribute("content")
|
||||||
|
.endsWith("/about"),
|
||||||
|
"it should update OG URL"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -6,6 +6,8 @@
|
||||||
<%= javascript_include_tag "test_helper" %>
|
<%= javascript_include_tag "test_helper" %>
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
<script src="<%= ExtraLocalesController.url('admin') %>"></script>
|
<script src="<%= ExtraLocalesController.url('admin') %>"></script>
|
||||||
|
<meta property="og:title" content="">
|
||||||
|
<meta property="og:url" content="">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user