]> cat aescling's git repositories - mastodon.git/commitdiff
Treat meta[property] as a space-separated list (#10604)
authorDaniel Aleksandersen <code@daniel.priv.no>
Sun, 21 Apr 2019 02:48:19 +0000 (04:48 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 21 Apr 2019 02:48:19 +0000 (04:48 +0200)
The @property attribute in HTML is a space-separated list of values.
This change normalizes whitespace and finds the desired value in
the list instead of requiring an exact single-value match.

More details:
https://www.ctrl.blog/entry/rdfa-socialmedia-metadata.html

app/services/fetch_link_card_service.rb

index 7979c312e5d771c84efbca492e495c4e54ccb019..494aaed759c3899961a15f1a06fb3e545df37675 100644 (file)
@@ -165,7 +165,7 @@ class FetchLinkCardService < BaseService
   end
 
   def meta_property(page, property)
-    page.at_xpath("//meta[@property=\"#{property}\"]")&.attribute('content')&.value || page.at_xpath("//meta[@name=\"#{property}\"]")&.attribute('content')&.value
+    page.at_xpath("//meta[contains(concat(' ', normalize-space(@property), ' '), ' #{property} ')]")&.attribute('content')&.value || page.at_xpath("//meta[@name=\"#{property}\"]")&.attribute('content')&.value
   end
 
   def lock_options