Created
August 18, 2011 15:43
-
-
Save rcarmo/1154357 to your computer and use it in GitHub Desktop.
Generate an HTML5 manifest automatically with bottle.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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