Using a sitemap.xml file
A sitemap is a XML file that lists the URLs for a site. It allows webmasters to include additional information about each URL: when it was last updated, how often it changes, and how important it is in relation to other URLs in the site, for example. This allows search engines to crawl the site more intelligently.
Viewport does not support sitemaps out of the box but there are several workarounds that you can use to generate one.
Please note the suggested workarounds will generate a file with the name /sitemap-xml
in your domain's top level directory. Since search engines will look for a name like sitemap.xml
, we recommend you submit the resulting sitemap URL manually to the search engines of your choice.
Workaround 1: Dynamically generate a sitemap using a custom velocity template
You can automatically generate a sitemap with the HTML/Velocity template below. Save it as sitemap.xml.vm
in your viewport theme
#set($PAGE_FILTER = [
"sitemap.xml"
])#*
*##macro(processChildren $page)#*
*##if (!$PAGE_FILTER.contains($page.title))#*
*#<url>
<loc>$page.absoluteLink</loc>
</url>
#end
#foreach($child in $page.children)#*
*##processChildren($child)
#end
#end#*
*#<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#processChildren($home)
</urlset>
To make the sitemap available, you need to create a placeholder page in the space so Scroll Viewport can handle requests to .../sitemap.xml
and then tell Scroll Viewport to use the sitemap.xml.vm
template from your theme to produce the sitemap on the fly.
- Create a page called sitemap.xml as a direct child of the home page.
- Add a page properties macro as follows on that page:
The value of the property must mach the name of the template in your viewport theme.
Workaround 2: Embed Static Sitemap Content in your Viewport Theme
- In the space for the viewport for "/" create a new page called
sitemap.xml
as child of the home page - Add the sitemap.xml contents to a template, e.g. sitemap.vm
Make sure that the
sitemap.xml
page is rendered only with the content of the file (without any HTML tags). To do this, add the following code to yourpage.vm
template:XML#if($stringUtils.equals($page.title, "sitemap.xml")) //output static sitemap content $include.template("/sitemap.vm") #else <!DOCTYPE html> <html> <head> ... rest of page.vm ... </body> </html> #end
And then in the
sitemap.vm
add your sitemap contentXML#literal() <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://www.example.com/</loc> </url> ... </urlset> #end
With the #literal() ... #end directives you are telling the Velocity template engine that is used to render your theme to not touch that content and thus you don't have to worry about special characters in your sitemap.
Also you do not have to use the XML sitemap protocol and can just list URLs using the textfile format.
- If your template has a page tree you'll want to adapt it so it filters out pages called
sitemap.xml
Workaround 3: Static sitemap.xml File served by a Reverse Proxy
- Set up a reverse proxy in front of Confluence (Apache, Nginx, ...)
- Configure it to serve requests to sitemap.xml itself instead of forwarding it to Confluence. The actual configuration depends on your reverse proxy software and configuration.