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

Add Open Graph Protocol support to page head

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Duplicate
    • Minor
    • None
    • 11.0.3
    • Administration
    • 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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: