Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default favicon #406

Merged
merged 5 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -216,6 +216,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 @@ -461,11 +464,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 @@ -975,6 +989,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'