Skip to content

Commit 9c00695

Browse files
authored
Merge pull request #406 from plotly/default-favicon
Default favicon
2 parents 5dfbc44 + 30e8f14 commit 9c00695

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.28.0 - 2018-09-26
2+
## Added
3+
- Default favicon for dash apps. [#406](https://github.com/plotly/dash/pull/406#issuecomment-424821743)
4+
- Bust the cache of the assets favicon.
5+
6+
## Fixed
7+
- Remove the first and last blank lines from the HTML index string. [#403](https://github.com/plotly/dash/pull/403)
8+
19
## 0.27.0 - 2018-09-20
210
## Added
311
- 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)

Diff for: MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include README.md
22
include LICENSE
3+
include dash/favicon.ico

Diff for: dash/dash.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def add_url(name, view_func, methods=('GET',)):
214214
'{}<path:path>'.format(self.config['routes_pathname_prefix']),
215215
self.index)
216216

217+
add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
218+
self._serve_default_favicon)
219+
217220
self.server.before_first_request(self._setup_server)
218221

219222
self._layout = None
@@ -459,11 +462,22 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
459462
config = self._generate_config_html()
460463
metas = self._generate_meta_html()
461464
title = getattr(self, 'title', 'Dash')
465+
462466
if self._favicon:
463-
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
464-
self.get_asset_url(self._favicon))
467+
favicon_mod_time = os.path.getmtime(
468+
os.path.join(self._assets_folder, self._favicon))
469+
favicon_url = self.get_asset_url(self._favicon) + '?m={}'.format(
470+
favicon_mod_time
471+
)
465472
else:
466-
favicon = ''
473+
favicon_url = '{}_favicon.ico'.format(
474+
self.config.requests_pathname_prefix)
475+
476+
favicon = _format_tag('link', {
477+
'rel': 'icon',
478+
'type': 'image/x-icon',
479+
'href': favicon_url
480+
}, opened=True)
467481

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

990+
def _serve_default_favicon(self):
991+
headers = {
992+
'Cache-Control': 'public, max-age={}'.format(
993+
self.config.components_cache_max_age)
994+
}
995+
return flask.Response(pkgutil.get_data('dash', 'favicon.ico'),
996+
headers=headers,
997+
content_type='image/x-icon')
998+
976999
def get_asset_url(self, path):
9771000
asset = _get_asset_path(
9781001
self.config.requests_pathname_prefix,

Diff for: dash/favicon.ico

14.7 KB
Binary file not shown.

Diff for: dash/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.27.0'
1+
__version__ = '0.28.0'

0 commit comments

Comments
 (0)