-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Twitter and OpenGraph cards not rendering for root URL and most pages #3590
Comments
The twitter summary card comes in two flavors: summary and summary_large_image. The generic summary card is a small photo in the left with title and desc on right, and the summary_large_image card is a larger image placed on top with title and description underneath. Summary card:
|
@peterbe I could have sworn that the social share Twitter card worked when I shared a page on twitter to someone referencing a documentation page about 2-3 weeks ago. Let me know your thoughts on this. |
Could it be that, unlike that Card Validator app, the real Twitter will fall back to the regular HTML meta tags that we have. |
If someone knows of a tweet of an MDN URL it would be nice to look at. |
I did a few test tweets on Twitter and the summary card isn't rendering. Since the Test tweet 1Test tweet 2Unless those When I paste the URL into a tweet, there isn't a summary card generated. Twitter is most likely using the validator behind the scenes to verify the URL when pasted (or manually entered) into tweet has a valid summary card rendered and then pop it into the tweet. Nothing is generated when I paste an MDN URL into the tweet box shown below. |
Looking at view-source:https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox (that is, Ctrl-U on https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox ) I can confirm, that the |
@peterbe I noticed all of the Mozilla hacks article pages do have the appropriate I don't think the document metadata tags inside the It seems the
Where it would be |
I don't think it would be hard to inject. But is it worth it? It probably is because people do use Twitter no matter what you might think about proprietary bloat that fills up your HTML. |
Yeah, it doesn't seem hard to inject. I think it is worth it. There are so many people using MDN (and potentially sharing links on social media) that having a summary card for both Twitter and Facebook appear rather than just a plain link would be better. If we instead go for only the OpenGraph meta tags, ie <head>
<meta name="og:title" content="{{ title }} - Learn web dev | MDN">
<meta name="og:type" content="website">
...
</head> Then browsers will only have a social share card for Facebook and Twitter won't be able to render one. Unless we use the information from each of the OpenGraph tags to populate the Twitter card meta tags eg: const $head = $('head');
$('meta').each((i, elem) => {
let $meta = $(elem);
let name = $meta.attr('name');
let content = $meta.attr('content');
switch (name) {
case "og:title":
$head.append(`<meta name='twitter:title' content='${content}'>`);
break;
case "og:url":
$head.append(`<meta name='twitter:site' content='@MozDevNet'>`);
break;
case "og:type":
$head.append(`<meta name='twitter:card' content='summary_large_image'>`);
break;
case "og:description":
$head.append(`<meta name='twitter:description' content='${content}'>`);
break;
case "og:image":
$head.append(`<meta name='twitter:image' content='${content}'>`);
break;
case "og:image:alt":
$head.append(`<meta name='twitter:image:alt' content='${content}'>`);
break;
default:
// maybe append some default Twitter meta tags if the OpenGraph tags don't exist
}
}); which would evaluate these OpenGraph cards <meta name="og:title" content="MDN Web Docs">
<meta name="og:type" content="website">
<meta name="og:url" content="https://developer.mozilla.org/en-US/">
<meta name="og:description" content="Some description text for the page">
<meta name="og:image" content="https://foobar.com/some-image.jpg">
<meta name="og:image:alt" content="Some alt text"> and create Twitter card meta tags like this <meta name="twitter:title" content="MDN Web Docs">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@MozDevNet">
<meta name="twitter:description" content="Some description text for the page">
<meta name="twitter:image" content="https://foobar.com/some-image.jpg">
<meta name="twitter:image:alt" content="Some alt text"> |
First of all, we don't have images, which is a shame. I sometimes wish we could take a screenshot of the page (without the header and sidebar) and make that the image.
So which websites can use and benefit from the OpenGraph tags? By the way, I don't mind adding these so much. But the proprietary bloat of bending to Twitters will is a bit annoying so I'm also not rushing to it :) |
Although Facebook is the most known consumer of Open Graph protocol, the circumstance that it is based on RDFa protocol allows for other crawlers to also understand it. Google is listed towards the end of that page. Twitter is entirely proprietary here … |
On https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started under the heading "Twitter Cards and Open Graph" it says
So, let's reinstate the Open Graph meta tags and see how Twitter handles that. |
@peterbe We could but it's a bit of setup. If we had a sort of social share image generator that happens at build time, maybe using puppeteer to load the page and take a screenshot of the document with certain dimensions (to not include header and sidebar)
and have the background be an image or some color that would handle generating the social share image and then the image output to some dir can be accessed via URL |
Completely agree, let's see how the Twitter card processor handles that. Thanks for posting that bit from card reference, I wasn't aware that the processor would fallback to the supported OpenGraph property. Seems like the last bit of the puzzle would just be generating images for the OpenGraph meta tag. |
In the past, I've used a service where you just point to a URL and it generates (and caches!) the screenshots based on something like puppeteer. Perhaps if you can combine it with a CSS selector or something to make it without the header and sidebar it could be neat. But it's bound to get very expensive at our scale. Let's park that discussion for another day. Let's focus on Open Graph :) |
@peterbe That sounds like a neat service! Yeah combining with some sort of selector or bit to make the dimensions not include the header or sidebar that'd be nice, but if it's very expensive with scale probably best to park for later. Open Graph it is :) |
Dropping https://docs.htmlcsstoimage.com/ which is used by forem (dev.to) => new issue? |
@Ryuno-Ki That's a really neat tool. Could definitely be useful down the line to generate the social share image for each SPA page. The current setup in #3623 renders a social card from the Open Graph meta tags for each social site besides Twitter, which should work as the twitter validator falls back to the Open Graph tags as Peter mentioned above from the docs. But it doesn't seem to be working as the docs say. |
Discussion first. Then if we decide to act on it, discussions can be turned into issues. |
Alright. #3638 |
I was certain that the Twitter card was rendering correctly for pages on MDN, but it looks like the required
<meta>
tags for the Twitter summary and OpenGraph cards don't exist.The following
<meta>
tags should be added for the Twitter social share card to render correctly.I couldn't track down where exactly the document metadata inside the
<head>
was being generated or manually typed, but if the<meta>
tags are being written in a template, we could define the metadata in YAML format or another data source to populate thecontent
of the required Twitter card meta tags. E.g. below is an example of defining the metadata as template variables and passing them into the required<meta>
tags.This seems like a solid way to add support for the social share Twitter summary card. We could also add
<meta>
tags for the OpenGraph protocol (Facebook card) which look like:These
<meta>
tags could also have theircontent
populated through template variables or from another data source like mentioned for the Twitter card tags.Thoughts
If the document metadata in the
<head>
is being rendered elsewhere and injected into the page, maybe writing a function to generate the<meta>
tags needed for the Twitter summary code would be a start in that direction. Going further down this route, (my eleventy knowledge thinks "shortcode") but creating a KS macro that accepts the 6 string arguments or a single object argument with all the nested key/value pairs to generate the<meta>
tags could be a good idea. That's if the metadata is being generated server side.The text was updated successfully, but these errors were encountered: