Details
-
Improvement
-
Resolution: Duplicate
-
Minor
-
None
-
11.0.3
-
Unknown
-
Description
It seems that more and more social media sites use the Open Graph Markup to fetch metadata from pasted URLs, e.g. Facebook, LinkedIn and Pinterest. This issue is about adding Open Graph Markup support directly in XWiki headers.
A way to achieve this would be to add the snippet below to the page header, with the following caveats:
- Attachment external URL should be computed with the URL factory / API so that there is no need of $baseUrl.
- The home page should be computed via the XWiki APIs so that there is no need of hardcoded "Main.WebHome".
- The macro should use page references, not full names.
- Adding home page images may be needed only if current page has no attachment.
<meta property="og:url" content="$doc.externalURL" /> <meta property="og:type" content="article" /> <meta property="og:title" content="$tdoc.getRenderedTitle("plain/1.0")" /> #set ($hasImages = false) #macro(addOpenGraphTagsForAttachedImages $pageFullName) #set ($page = $xwiki.getDocument($pageFullName)) #foreach ($attachment in $page.attachmentList) #if ($attachment.isImage()) #set ($hasImages = true) #set ($url = $page.getAttachmentURL($attachment.filename)) <meta property="og:image" content="$baseUrl$url" /> #end #end #end ## Add all page attachments that are images as og:image #addOpenGraphTagsForAttachedImages($doc.fullName) ## If current page has no attached image, add the ones of the home page #if ($hasImages && $doc.fullName != "Main.WebHome") #addOpenGraphTagsForAttachedImages("Main.WebHome") #end
What do you think?
Attachments
Issue Links
- is related to
-
XWIKI-16093 Add extension point to make the HTML head pluggable
- Closed