Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-16087

Add Open Graph Protocol support to page head

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 11.0.3
    • Fix Version/s: None
    • Component/s: Administration
    • Labels:
    • Difficulty:
      Unknown
    • Similar issues:

      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

            Activity

              People

              • Assignee:
                slauriere slauriere
                Reporter:
                slauriere slauriere
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Date of First Response: