-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Default favicon #406
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0103ee5
Add default dash favicon.
T4rk1n bb0d0c4
Add cache control header to default favicon.
T4rk1n 11905d8
Fix favicon format indent.
T4rk1n d2a2752
Add assets favicon cache busting, clearer favicon tag format.
T4rk1n 30e8f14
Update version and changelogs.
T4rk1n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include README.md | ||
include LICENSE | ||
include dash/favicon.ico |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'.format(self.config['routes_pathname_prefix']), | ||
self._serve_default_favicon) | ||
|
||
self.server.before_first_request(self._setup_server) | ||
|
||
self._layout = None | ||
|
@@ -461,11 +464,9 @@ 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)) | ||
else: | ||
favicon = '' | ||
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format( | ||
self.get_asset_url(self._favicon) if self._favicon | ||
else '{}_favicon'.format(self.config.requests_pathname_prefix)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this logic with the nested formats and conditional expression a little hard to parse initially. I'd have a preference for something more verbose but easier to read, like: if self._favicon:
favicon_url = self.get_asset_url(self._favicon)
else:
favicon_url = '{}_favicon'.format(self.config.requests_pathname_prefix)
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(favicon_url) |
||
|
||
index = self.interpolate_index( | ||
metas=metas, title=title, css=css, config=config, | ||
|
@@ -975,6 +976,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, | ||
|
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this route be
{}_favicon.ico
? I feel like this would make it clearer that the route is serving a .ico file directlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes probably clearer thanks.