Skip to content

Instantly share code, notes, and snippets.

@rcarmo
Created August 18, 2011 15:43
Show Gist options
  • Save rcarmo/1154357 to your computer and use it in GitHub Desktop.
Save rcarmo/1154357 to your computer and use it in GitHub Desktop.
Generate an HTML5 manifest automatically with bottle.py
@route('/app.manifest')
def manifest():
""" Generate an HTML 5 offline manifest automatically """
last = 0
lines = []
response.content_type = "ext/cache-manifest"
for (path, dirs, files) in os.walk('app'):
last = max(max(map(lambda x: os.path.getmtime(os.path.join(path, x)), files)),last)
map(lambda x: lines.append(os.path.join(os.path.relpath(path,'app'), x)), filter(lambda x: os.path.splitext(x)[1] in ['.css','.js','.png'], files))
response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last))
return '\n'.join(sum([["# Version %d" % last,'CACHE MANIFEST'],lines ,['NETWORK:','*']],[]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment