You could go for a routing approach. I recommend to use actually different filenames instead of a querystring - some http caches won't cache urls with querystring.
route '/stylesheet/' do
csum = [File.open(item[:filename]).read.checksum]
# add other files you include from your stylesheet.less (if you use less)
csum += Dir['content/styles/*'].select { |i| File.file?(i) }.map { |f| File.read(f).checksum }
'/style-' + csum.checksum + '.css'
end
route '*' do
ext = item[:extension]
versionexts = ['css','js']
if versionexts.include?(ext)
# versioned filenames, depending on the checksum of the source file
# these files shouldn't depend on other sources, or you have to checksum them too (see above)
item.identifier.chop + '-' + File.read(item[:filename]).checksum + '.' + ext
elsif item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + ext
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
end
end
You can't use the checksum of generated content in routing, as the routing is done before compiling.