From version 27.2
edited by Mark van den Broek
on 2016/04/14 12:18
To version 28.1
edited by Marius Dumitru Florea
on 2017/08/03 10:50
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.MarkvandenBroek
1 +xwiki:XWiki.mflorea
ExtensionCode.ExtensionClass[0]
Description
... ... @@ -5,51 +5,45 @@
5 5  
6 6  === 1st version: Create a link to download your sitemap ===
7 7  
8 -{{warning}}
9 -Wrap this code in a pre tag and groovy <% %> tag
10 -{{/warning}}
11 -
12 12  {{code}}
13 -if(request.xpage && request.xpage == "plain") {
9 +{{groovy}}
10 +if (xcontext.action == "get") {
11 + response.setContentType("text/xml")
14 14  
15 - response.setContentType("text/xml")
16 -
17 - def sitePages = [
13 + def sitePages = [
18 18   // here you define the page you want in your sitemap
19 19   // the order is: document name, priority, change frequency
20 -
21 21   ["Main.WebHome","1","weekly"],
22 22   ["About.Contact","0.8","monthly"],
23 23   ["About.Team","0.5", "monthly"]
24 24   // add more here...
25 -];
20 + ]
26 26  
27 - println('<?xml version="1.0" encoding="UTF-8"?>')
28 - println('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
22 + println('<?xml version="1.0" encoding="UTF-8"?>')
23 + println('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
29 29  
25 + for (page in sitePages) {
26 + println("<url>")
27 + println(" <loc>" + xwiki.getDocument(page[0]).getExternalURL() + "</loc>")
28 + println(" <lastmod>" + xwiki.formatDate(xwiki.getDocument(page[0]).contentUpdateDate, 'yyyy-MM-dd') + "</lastmod>")
29 + println(" <changefreq>" + page[2]+ "</changefreq>")
30 + println(" <priority>" + page[1] + "</priority>")
31 + println("</url>")
32 + }
30 30  
31 - for(page in sitePages) {
32 - println("<url>")
33 - println(" <loc>" + xwiki.getDocument(page[0]).getExternalURL() + "</loc>")
34 - println(" <lastmod>" + xwiki.formatDate(xwiki.getDocument(page[0]).contentUpdateDate, 'yyyy-MM-dd') + "</lastmod>")
35 - println(" <changefreq>" + page[2]+ "</changefreq>")
36 - println(" <priority>" + page[1] + "</priority>")
37 - println("</url>")
38 - }
39 -
40 - println("</urlset>")
41 -
34 + println("</urlset>")
35 +} else {
36 + println("{{html}}<a href='"+ doc.getURL('get','outputSyntax=plain') +"'>Generate Sitemap</a>{{/html}}")
42 42  }
43 -
44 -else {
45 -
46 - println("<a href='"+ doc.getURL('view','xpage=plain') +"'>Generate Sitemap</a>")
47 -
48 -}
38 +{{/groovy}}
49 49  {{/code}}
50 50  
51 51  === 2nd version: automatically write sitemap.xml in your web application folder ===
52 52  
43 +{{warning}}
44 +Wrap this code in a pre tag and groovy <% %> tag
45 +{{/warning}}
46 +
53 53  {{code}}
54 54  if(request.gen && request.gen == "1") {
55 55   content = ""

Get Connected