diff --git a/subleekr/labs/__init__.py b/subleekr/labs/__init__.py index a08ab96..0adbc5b 100644 --- a/subleekr/labs/__init__.py +++ b/subleekr/labs/__init__.py @@ -1,6 +1,6 @@ import os.path from flask import Module -from flaskext.autoindex import AutoIndexModule +from flaskext.autoindex import AutoIndexModule, RootFolder, Folder from subleekr import FlaskModule @@ -9,5 +9,24 @@ idx = AutoIndexModule(app, browse_root) +def get_favicon(ent): + favicon_paths = "favicon.ico", "resources/favicon.ico", \ + "artwork/favicon.ico", "static/favicon.ico", \ + "docs/_static/favicon.ico" + favicon_paths = sorted(favicon_paths, + lambda x, y: -cmp(x.count("/"), y.count("/"))) + if type(ent) is Folder and ent.name != "build": + for favicon_path in favicon_paths: + dirname = os.path.dirname(favicon_path) + if dirname and ent.path.endswith(dirname): + return False + favicon = os.path.join(ent.path, favicon_path) + if os.path.isfile(os.path.join(ent.root, favicon)): + return "/" + favicon + return False + + idx.add_icon_rule("folder_brick.png", foldername="forks") +idx.add_icon_rule("/favicon.ico", cls=RootFolder) +idx.add_icon_rule(get_favicon)