How to update the lastmod date in your sitemap xml with Ant

Hmm, you want to add the “lastmod” node, but you’re too lazy to ever keep that up to date so you decide to update it with your Ant script whenever you deploy. Easy.

So you’ve just written a valid sitemap.xml file for your website because Google said it was a good idea. Great.

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.stolencamerafinder.com/</loc>
      <lastmod>2011-04-21</lastmod>
      <changefreq>weekly</changefreq>
   </url>
</urlset>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.stolencamerafinder.com/</loc>
      <lastmod>2011-04-21</lastmod>
      <changefreq>weekly</changefreq>
   </url>
</urlset>

First, you’ll need the jar for a third-party Ant task called XMLTask. Once you have that, the ant target you’ll need is simply:

1
2
3
4
5
6
7
8
9
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="test-lib/xmltask.jar"/>
<target name="update-sitemap" description="update the update date">
    <tstamp>
        <format property="today" pattern="yyyy-MM-dd" locale="en,UK"/>
    </tstamp>
    <xmltask source="war/sitemap.xml" dest="war/sitemap.xml" standalone="yes" report="true">
        <replace path="/:urlset/:url/:lastmod/text()" withText="${today}"/>
    </xmltask>
</target>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="test-lib/xmltask.jar"/>
<target name="update-sitemap" description="update the update date">
	<tstamp>
	    <format property="today" pattern="yyyy-MM-dd" locale="en,UK"/>
	</tstamp>
    <xmltask source="war/sitemap.xml" dest="war/sitemap.xml" standalone="yes" report="true">
        <replace path="/:urlset/:url/:lastmod/text()" withText="${today}"/>
    </xmltask>
</target>

Yeah yeah, this is kid’s stuff, why blog about it? Well, embarrassingly, it took me 3 hours of messing around to get it working. If I don’t write it down somewhere, I’ll only forget the next time I need to do this. Sigh.

How to detect browser support for File Api and drag and drop with javascript

Here’s a bit of info for you crazy HTML5 kids. You’ll need to include the handy Modernizr script for it to work.

var browserIsSupported = !!window.FileReader && Modernizr.draganddrop;
If you want see it in action, just visit stolencamerafinder ;)
I’ve tested this in Firefox 3.6, Chrome 10, IE8, Safari 5 and Opera 11. The only browsers from that list to support FileReader from the File API and the drag and drop events are FF and Chrome.
Let’s hope the other catch up soon…

How to stop Google Chrome using your location when searching

When you use Chrome’s omnibar to search, Chrome will redirect you to search results based on when you are geographically. This is great when I’m at home because I see (more relevant) results from google.co.uk and not google.com.

However, I’m travelling at the moment and getting my results from google.co.th is painful since most of the results are not in english.

  1. Close Chrome.
  2. Open the file “Local State” in notepad. Mine was in: C:\Users\matt\AppData\Local\Google\Chrome\User Data\Local State. Linux users may find it in ~/.config/google-chrome/ or ~/.config/chromium/, and OS X users can try ~/Library/Application Support/Google/Chrome.
  3. Look for “last_known_google_url” and “last_prompted_google_url” and change their values to the local Google page of your choice.
  4. Save and close.
  5. Done.
You may find other pages telling you to hardcode the url in the Chrome options page when you “manage search engines”. This works to an extent but breaks other things like suggest.

Thanks to Siavash for originally posting this.