Changes for page HTML Head

Last modified by slauriere on 2019/06/06

From version 15.3
edited by slauriere
on 2019/06/06
Change comment: There is no comment for this version
To version 17.1
edited by slauriere
on 2019/06/06
Change comment: There is no comment for this version

Summary

Details

html-head-extension-code-example.jpg
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.slauriere
Size
... ... @@ -1,1 +1,0 @@
1 -207.2 KB
Content
ExtensionPoint.UIXDescriptionClass[0]
How this Extension Point is used
... ... @@ -2,14 +2,39 @@
2 2  
3 3  It was introduced in version 11.1RC1 with the identifier ##org.xwiki.platform.head## and was later changed to ##org.xwiki.platform.html.head## in 11.5.
4 4  
5 -The first screenshot below illustrates an example of metadata tags injected into the HTML ##head## using this extension point. The second one shows the code used by a User Interface Extension (UIX) to produce such content.
5 +The screenshot below illustrates an example of metadata tags injected into the HTML ##head## using this extension point. The second one shows the code used by a User Interface Extension (UIX) to produce such content.
6 6  
7 7  (% style="border: 1px solid #ccc" %)(((
8 8  [[image:html-head-extension-example.jpg]]
9 9  )))
10 10  
11 +Such custom metadata tags can be produced by the following code sample, copied from the [[OpenGraph application>>extensions:Extension.OpenGraph Application.WebHome]].
11 11  
12 -(% style="border: 1px solid #ccc" %)(((
13 -[[image:html-head-extension-code-example.jpg]]
14 -)))
15 -
13 +{{code}}
14 +{{velocity}}
15 +{{html clean="false"}}
16 +#set ($serverUrl = $xcontext.URLFactory.getServerURL($xcontext.context))
17 +#set ($hasImages = false)
18 +#macro(addOpenGraphTagsForAttachedImages $pageReference)
19 + #set ($page = $xwiki.getDocument($pageReference))
20 + #foreach ($attachment in $page.attachmentList)
21 + #if ($attachment.isImage())
22 + #set ($hasImages = true)
23 + #set ($path= $page.getAttachmentURL($attachment.filename))
24 + <meta property="og:image" content="$serverUrl$path" />
25 + #end
26 + #end
27 +#end
28 +<meta property="og:url" content="$doc.externalURL"/>
29 +<meta property="og:type" content="article" />
30 +<meta property="og:title" content="$tdoc.getRenderedTitle("plain/1.0")" />
31 +## Add all current page's image attachments as "og:image".
32 +#addOpenGraphTagsForAttachedImages($doc.documentReference)
33 +## If current page has no attached image, add the ones of the home page, if any.
34 +#set ($wikiDescriptor = $services.wiki.getById($xcontext.wiki))
35 +#if (!$hasImages && $wikiDescriptor && $doc.documentReference != $wikiDescriptor.mainPageReference)
36 + #addOpenGraphTagsForAttachedImages($wikiDescriptor.mainPageReference)
37 +#end
38 +{{/html}}
39 +{{/velocity}}
40 +{{/code}}

Get Connected