Skip to content

Commit

Permalink
Merge pull request #406 from plotly/default-favicon
Browse files Browse the repository at this point in the history
Default favicon
  • Loading branch information
T4rk1n authored Sep 26, 2018
2 parents 5dfbc44 + 30e8f14 commit 9c00695
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.28.0 - 2018-09-26
## Added
- Default favicon for dash apps. [#406](https://github.com/plotly/dash/pull/406#issuecomment-424821743)
- Bust the cache of the assets favicon.

## Fixed
- Remove the first and last blank lines from the HTML index string. [#403](https://github.com/plotly/dash/pull/403)

## 0.27.0 - 2018-09-20
## Added
- Added support for serving dev bundles from the components suite, enable with `app.run_server(dev_tools_serve_dev_bundles=True)` [#369](https://github.com/plotly/dash/pull/369)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include README.md
include LICENSE
include dash/favicon.ico
29 changes: 26 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def add_url(name, view_func, methods=('GET',)):
'{}<path:path>'.format(self.config['routes_pathname_prefix']),
self.index)

add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
self._serve_default_favicon)

self.server.before_first_request(self._setup_server)

self._layout = None
Expand Down Expand Up @@ -459,11 +462,22 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
config = self._generate_config_html()
metas = self._generate_meta_html()
title = getattr(self, 'title', 'Dash')

if self._favicon:
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
self.get_asset_url(self._favicon))
favicon_mod_time = os.path.getmtime(
os.path.join(self._assets_folder, self._favicon))
favicon_url = self.get_asset_url(self._favicon) + '?m={}'.format(
favicon_mod_time
)
else:
favicon = ''
favicon_url = '{}_favicon.ico'.format(
self.config.requests_pathname_prefix)

favicon = _format_tag('link', {
'rel': 'icon',
'type': 'image/x-icon',
'href': favicon_url
}, opened=True)

index = self.interpolate_index(
metas=metas, title=title, css=css, config=config,
Expand Down Expand Up @@ -973,6 +987,15 @@ def add_resource(p, filepath):
def _invalid_resources_handler(self, err):
return err.args[0], 404

def _serve_default_favicon(self):
headers = {
'Cache-Control': 'public, max-age={}'.format(
self.config.components_cache_max_age)
}
return flask.Response(pkgutil.get_data('dash', 'favicon.ico'),
headers=headers,
content_type='image/x-icon')

def get_asset_url(self, path):
asset = _get_asset_path(
self.config.requests_pathname_prefix,
Expand Down
Binary file added dash/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.27.0'
__version__ = '0.28.0'

0 comments on commit 9c00695

Please sign in to comment.