mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-14 01:22:11 -04:00
Improve URL previews for sites with only Twitter card information. (#13056)
Pull out `twitter:` meta tags when generating a preview and use it to augment any `og:` meta tags. Prefers Open Graph information over Twitter card information.
This commit is contained in:
parent
7552615247
commit
0fcc0ae37c
3 changed files with 137 additions and 17 deletions
|
@ -370,6 +370,47 @@ class OpenGraphFromHtmlTestCase(unittest.TestCase):
|
|||
og = parse_html_to_open_graph(tree)
|
||||
self.assertEqual(og, {"og:title": "ó", "og:description": "Some text."})
|
||||
|
||||
def test_twitter_tag(self) -> None:
|
||||
"""Twitter card tags should be used if nothing else is available."""
|
||||
html = b"""
|
||||
<html>
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:description" content="Description">
|
||||
<meta name="twitter:site" content="@matrixdotorg">
|
||||
</html>
|
||||
"""
|
||||
tree = decode_body(html, "http://example.com/test.html")
|
||||
og = parse_html_to_open_graph(tree)
|
||||
self.assertEqual(
|
||||
og,
|
||||
{
|
||||
"og:title": None,
|
||||
"og:description": "Description",
|
||||
"og:site_name": "@matrixdotorg",
|
||||
},
|
||||
)
|
||||
|
||||
# But they shouldn't override Open Graph values.
|
||||
html = b"""
|
||||
<html>
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:description" content="Description">
|
||||
<meta property="og:description" content="Real Description">
|
||||
<meta name="twitter:site" content="@matrixdotorg">
|
||||
<meta property="og:site_name" content="matrix.org">
|
||||
</html>
|
||||
"""
|
||||
tree = decode_body(html, "http://example.com/test.html")
|
||||
og = parse_html_to_open_graph(tree)
|
||||
self.assertEqual(
|
||||
og,
|
||||
{
|
||||
"og:title": None,
|
||||
"og:description": "Real Description",
|
||||
"og:site_name": "matrix.org",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class MediaEncodingTestCase(unittest.TestCase):
|
||||
def test_meta_charset(self) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue