How can I create a simple Google Sitemap for Search Engine Optimisation?
SEO, "Search Engine Optimisation" is big nowadays. To help Google spider your public Foswiki website, you can create a file with page urls.
As Google says it: "Submit a Sitemap to tell Google about pages on your site we might not otherwise discover"
Since Google Sitemap accepts a simple list of urls instead of a generated XML file, our job is a lot easier and can simply be done within Foswiki.
What you need:
- Create a page with a
SEARCH
to generate the list of urls
- Install AttachContentPlugin to be able to write the search results to a static file
- This is because constructs like
Topic?section=list;skin=text
may run into problems with your robots.txt
settings
- For SEO, do not use WikiWords as topics names; use underscores to separate name parts, like:
Annual_report
. Google reads this as words in a sentence.
Example search:
%STARTATTACH{"sitemap.txt"}%
%SEARCH{
"BasicForm.TopicClassification='FrequentlyAskedQuestion'"
type="query"
excludetopic="*Template"
web="%WEB%"
format="%SCRIPTURL{"view"}%/$web/$topic"
separator="$n"
nonoise="on"
}%
%ENDATTACH%
Also put this in the topic:
<form action="%SCRIPTURL{"save"}%/%WEB%/%TOPIC%" method="post">
<input type="hidden" name="action_save" value="1" />
<input type="submit" class="foswikiButton" value="Update sitemap file" />
</form>
[[%ATTACHURL%/sitemap.txt][View sitemap file]]
Then post that sitemap file url to
Google Sitemap.
--
ArthurClemens - 30 Apr 2009
One addition to this
FAQ: if you want the site map file to be updated on a regular basis automatically (without you needing to return to the page to edit/save it), you can create a "cron job" (assuming some flavor of Linux OS) something like this:
0 0 * * * cd /var/www/foswiki/bin; ./save topic='MyWeb.SiteMapTopic' >/dev/null 2>&1
The above format assumes the cron job is part of one set up for the system user for your web server (e.g. www-data). You could also use the following variation in /etc/crontab (i.e. the "root" user crontab):
0 0 * * * www-data cd /var/www/foswiki/bin; ./save topic='MyWeb.SiteMapTopic' >/dev/null 2>&1
--
Main.LynnwoodBrown - 10 Mar 2021