Skip to content
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

Add support for structured data and more OpenGraph tags to link cards #16938

Merged
merged 1 commit into from
Nov 5, 2021

Conversation

Gargron
Copy link
Member

@Gargron Gargron commented Nov 4, 2021

Previously, link card generation was focused mainly on OEmbed, with OpenGraph details being merely the fallback. This adds more first-class treatment of OpenGraph data as well as JSON-LD structured data available on many news publications.

In particular, now author_name, author_url, provider_name, and provider_url will be available for OpenGraph links whereas previously those fields were only present on OEmbed links.

Respect canonical URL as long as the host is the same as of the page it is served from, but respect redirects leading up to it (e.g. through link shorteners) to avoid saving previews as belong to "t.co" and similar nonsense.

@Gargron Gargron force-pushed the feature-link-details-extractor branch 2 times, most recently from 9962be6 to 565973d Compare November 4, 2021 18:06
@Gargron Gargron marked this pull request as ready for review November 4, 2021 18:08
@Gargron Gargron force-pushed the feature-link-details-extractor branch from 565973d to 4f80e1f Compare November 4, 2021 19:56
@Gargron
Copy link
Member Author

Gargron commented Nov 5, 2021

There is a validation error caused by the canonical URL handling that I need to fix before merging 😔

@Gargron Gargron force-pushed the feature-link-details-extractor branch 2 times, most recently from da5b470 to a82198e Compare November 5, 2021 18:09
@Gargron Gargron force-pushed the feature-link-details-extractor branch from a82198e to a93799f Compare November 5, 2021 19:17
Save preview cards under their canonical URL

Increase max redirects to follow from 2 to 3
@Gargron Gargron force-pushed the feature-link-details-extractor branch from a93799f to 7795ab7 Compare November 5, 2021 19:19
if @status.local?
urls = @status.text.scan(URL_PATTERN).map { |array| Addressable::URI.parse(array[1]).normalize }
else
html = Nokogiri::HTML(@status.text)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I fixed shadowing of the html method

end

def opengraph_tag(name)
document.xpath("//meta[@property=\"#{name}\" or @name=\"#{name}\"]").map { |meta| meta['content'] }.first
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old method used to search all meta nodes for any attribute that had the searched-for value, but I don't think that is needed, OpenGraph tags can either be identified by name or property and nothing else.

@Gargron Gargron merged commit 39cdf61 into main Nov 5, 2021
@Gargron Gargron deleted the feature-link-details-extractor branch November 5, 2021 22:23
jesseplusplus pushed a commit to jesseplusplus/decodon that referenced this pull request Feb 10, 2022
…mastodon#16938)

Save preview cards under their canonical URL

Increase max redirects to follow from 2 to 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants