Failed to execute template. Cause: [Access denied when checking [script] access to [xwiki:Collaboratory.UX.HbpSkin.WebHome] for user [xwiki:XWiki.Admin]]. Click on this message for details.

sitemap - HBP Wiki

IAM21 instance, do not create collab nor modify a team, your changes will be lost


Changes for page sitemap

Last modified by bougault on 2023/09/15 15:50

From version 33.1
edited by bougault
on 2023/09/15 12:07
Change comment: There is no comment for this version
To version 1.1
edited by bougault
on 2023/09/15 09:01
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,56 +1,38 @@
1 1  {{groovy}}
2 -/*
3 -if (xcontext.action == "get") {
4 - response.setContentType("text/xml")
5 -
6 - def docs = services.query.xwql('where doc.space like Collabs').execute()
7 -
8 - def sitePages = [
2 +if(request.gen && request.gen == "1") {
3 + content = ""
4 + def sitePages = [
9 9   // here you define the page you want in your sitemap
10 10   // the order is: document name, priority, change frequency
7 +
11 11   ["Main.WebHome","1","weekly"],
12 12   ["About.Contact","0.8","monthly"],
13 - ["About.Team","0.5", "monthly"]
10 + ["About.Team","0.5", "monthly"],
14 14   // add more here...
15 - ]
12 + ];
16 16  
17 - println('')
18 - 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">')
14 + content += ''
15 + content += '<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">'
19 19  
20 - for (doc in docs) {
21 - println("<url>")
22 - println(" <loc>" + xwiki.getDocument(page[0]).getExternalURL() + "</loc>")
23 - println(" <lastmod>" + xwiki.formatDate(xwiki.getDocument(page[0]).contentUpdateDate, 'yyyy-MM-dd') + "</lastmod>")
24 - //println(" <changefreq>" + page[2]+ "</changefreq>")
25 - //println(" <priority>" + page[1] + "</priority>")
26 - println("</url>")
27 - }
17 + for(page in sitePages) {
18 + content += "<url>"
19 + content += " <loc>" + xwiki.getDocument(page[0]).getExternalURL() + "</loc>"
20 + content += " <lastmod>" + xwiki.formatDate(xwiki.getDocument(page[0]).contentUpdateDate, 'yyyy-MM-dd') + "</lastmod>"
21 + content += " <changefreq>" + page[2]+ "</changefreq>"
22 + content += " <priority>" + page[1] + "</priority>"
23 + content += "</url>"
24 + }
28 28  
29 - println("</urlset>")
30 -} else {
31 - println("{{html}}<a href='"+ doc.getURL('get','outputSyntax=plain') +"'>Generate Sitemap</a>{{/html}}")
26 + content += "</urlset>"
27 + new File("../webapps/xwiki/sitemap.xml").withPrintWriter { w |
28 + w.println content
29 + }
30 + println("Done: <a href='/xwiki/sitemap.xml'>sitemap.xml</a>")
32 32  }
33 -*/
34 -{{/groovy}}
35 35  
33 +else {
36 36  
37 -{{velocity}}
38 -#if ($xcontext.action == "get")
39 - $response.setContentType("text/xml")
40 - #set ($spaceReferenceString = 'Collabs')
41 - #set ($query = $services.query.xwql("where doc.space like :space"))
42 - #set ($query = $query.bindValue('space').literal("${spaceReferenceString}.").anyChars().setLimit(10).query())
43 - #set ($resources = $query.execute())
44 - <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">
45 - #foreach ($resource in $resources)
46 - #set($page = $xwiki.getDocument($resource))
47 - <url>
48 - <loc>$page.getExternalURL()</loc>
49 - <lastmod>$xwiki.formatDate($page.contentUpdateDate, 'yyyy-MM-dd')</lastmod>
50 - </url>
51 - #end
52 - </urlset>
53 -#else
54 -{{html}}<a href="$doc.getURL('get','outputSyntax=plain')">Generate Sitemap</a>{{/html}}
55 -#end
56 -{{/velocity}}
35 + println("<a href='"+ doc.getURL('view', "gen=1") +"'>Generate Sitemap</a>")
36 +
37 +}
38 +{{/groovy}}