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

Improvements for template favicon and metadata handling #1650

Merged
merged 1 commit into from
Oct 19, 2020
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
Binary file added panel/dist/icons/favicon.ico
Binary file not shown.
67 changes: 38 additions & 29 deletions panel/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from bokeh.document.document import Document as _Document
from bokeh.io import curdoc as _curdoc
from bokeh.settings import settings as _settings
from jinja2.environment import Template as _Template
from six import string_types
from pyviz_comms import JupyterCommManager as _JupyterCommManager
Expand All @@ -37,8 +38,7 @@
'https://localhost:{port}</a>'
)

# Should be served from somewhere else!
FAVICON_URL = "https://raw.githubusercontent.com/MarcSkovMadsen/awesome-panel/2781d86d4ed141889d633748879a120d7d8e777a/assets/images/favicon.ico"
FAVICON_URL = "/static/extensions/panel/icons/favicon.ico"


class BaseTemplate(param.Parameterized, ServableMixin):
Expand Down Expand Up @@ -329,8 +329,7 @@ class BasicTemplate(BaseTemplate):

main_max_width = param.String(default="", doc="""
The maximum width of the main area. For example '800px' or '80%'.
If the string is '' (default) no max width is set.
""")
If the string is '' (default) no max width is set.""")

sidebar = param.ClassSelector(class_=ListLike, constant=True, doc="""
A list-like container which populates the sidebar.""")
Expand All @@ -347,35 +346,42 @@ class BasicTemplate(BaseTemplate):
base64 encoded as URI).""")

title = param.String(default="Panel Application", doc="""
A title to show in the header. Also added to the document head meta settings and as the
browser tab title""")
# See https://www.w3schools.com/html/html_head.asp#:~:text=The%20element%20is%20a,scripts%2C%20and%20other%20meta%20information.
meta_description = param.String(default="""Analytics App made with HoloViz Panel, Python and \
the tools you know and love.""", doc="""
A meta description to add to the document head for search engine optimization. For example
'P.A. Nelson'. Default is 'Analytics App made with HoloViz Panel, Python and the tools you
know and love.'""")
meta_keywords = param.String(default="HoloViz, Panel, Python, Analytics", doc="""
Meta keywords to add to the document head for search engine optimization. Default is
'HoloViz, Panel, Python, Analytics'""")
meta_author = param.String(default="HoloViz Panel", doc="""
A meta author to add to the the document head for search engine optimization. For example
'P.A. Nelson'. Default is 'HoloViz Panel'""")
A title to show in the header. Also added to the document head
meta settings and as the browser tab title.""")

meta_description = param.String(doc="""
A meta description to add to the document head for search
engine optimization. For example 'P.A. Nelson'.""")

meta_keywords = param.String(doc="""
Meta keywords to add to the document head for search engine
optimization.""")

meta_author = param.String(doc="""
A meta author to add to the the document head for search
engine optimization. For example 'P.A. Nelson'.""")

meta_refresh = param.String(doc="""
A meta refresh rate to add to the document head. For example '30' will instruct the
browser to refresh every 30 seconds. Default is '', i.e. no automatic refresh.""")
meta_viewport = param.String(default="width=device-width, initial-scale=1.0", doc="""
A meta viewport to add to the header. Default is 'width=device-width, initial-scale=1.0'""")
A meta refresh rate to add to the document head. For example
'30' will instruct the browser to refresh every 30
seconds. Default is '', i.e. no automatic refresh.""")

meta_viewport = param.String(doc="""
A meta viewport to add to the header.""")

base_url = param.String(doc="""
Specifies the base URL for all relative URLs in a page. Default is '', i.e. not the domain.
""")
Specifies the base URL for all relative URLs in a
page. Default is '', i.e. not the domain.""")

base_target = param.ObjectSelector(default="_self",
objects=["_blank", "_self", "_parent", "_top"], doc=
"""Specifies the base Target for all relative URLs in a page. Default is '_self'""")
objects=["_blank", "_self", "_parent", "_top"], doc="""
Specifies the base Target for all relative URLs in a page.""")

header_background = param.String(doc="Optional header background color override")
header_background = param.String(doc="""
Optional header background color override.""")

header_color = param.String(doc="Optional header text color override")
header_color = param.String(doc="""
Optional header text color override.""")

theme = param.ClassSelector(class_=Theme, default=DefaultTheme,
constant=True, is_instance=False, instantiate=False)
Expand Down Expand Up @@ -461,7 +467,10 @@ def _update_vars(self, *args):
raise ValueError("Could not determine file type of favicon: {self.favicon}.")
favicon = img._b64()
else:
favicon = self.favicon
if _settings.resources(default='server') == 'cdn' and self.favicon == FAVICON_URL:
favicon = "https://cdn.jsdelivr.net/npm/@holoviz/panel@latest/dist/icons/favicon.ico"
else:
favicon = self.favicon
self._render_variables['app_logo'] = logo
self._render_variables['app_favicon'] = favicon
self._render_variables['app_favicon_type'] = self._get_favicon_type(self.favicon)
Expand Down
9 changes: 9 additions & 0 deletions panel/template/bootstrap/bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<!-- goes in body -->
{% block preamble %}
{% if app_favicon %}<link rel="icon" href="{{ app_favicon }}" type="{{favicon_type}}">{% endif %}
{% if meta_name %}<meta name="name" content="{{ meta_name }}">{% endif %}
{% if meta_description %}<meta name="description" content="{{ meta_description }}">{% endif %}
{% if meta_keywords %}<meta name="keywords" content="{{ meta_keywords }}">{% endif %}
{% if meta_author %}<meta name="author" content="{{ meta_author }}">{% endif %}
{% if meta_refresh %}<meta http-equiv="refresh" content="{{ meta_refresh }}">{% endif %}
{% if meta_viewport %}<meta name="viewport" content="{{ meta_viewport }}">{% endif %}
{% if base_url and base_target %}<base href="{{ base_url }}" target="{{ base_target }}">{% endif %}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
Expand Down
9 changes: 9 additions & 0 deletions panel/template/golden/golden.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<!-- goes in body -->
{% block preamble %}
{% if app_favicon %}<link rel="icon" href="{{ app_favicon }}" type="{{favicon_type}}">{% endif %}
{% if meta_name %}<meta name="name" content="{{ meta_name }}">{% endif %}
{% if meta_description %}<meta name="description" content="{{ meta_description }}">{% endif %}
{% if meta_keywords %}<meta name="keywords" content="{{ meta_keywords }}">{% endif %}
{% if meta_author %}<meta name="author" content="{{ meta_author }}">{% endif %}
{% if meta_refresh %}<meta http-equiv="refresh" content="{{ meta_refresh }}">{% endif %}
{% if meta_viewport %}<meta name="viewport" content="{{ meta_viewport }}">{% endif %}
{% if base_url and base_target %}<base href="{{ base_url }}" target="{{ base_target }}">{% endif %}

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="https://golden-layout.com/files/latest/js/goldenlayout.js"></script>
<link type="text/css" rel="stylesheet" href="https://golden-layout.com/files/latest/css/goldenlayout-base.css" />
Expand Down
9 changes: 9 additions & 0 deletions panel/template/material/material.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<!-- goes in body -->
{% block preamble %}
{% if app_favicon %}<link rel="icon" href="{{ app_favicon }}" type="{{favicon_type}}">{% endif %}
{% if meta_name %}<meta name="name" content="{{ meta_name }}">{% endif %}
{% if meta_description %}<meta name="description" content="{{ meta_description }}">{% endif %}
{% if meta_keywords %}<meta name="keywords" content="{{ meta_keywords }}">{% endif %}
{% if meta_author %}<meta name="author" content="{{ meta_author }}">{% endif %}
{% if meta_refresh %}<meta http-equiv="refresh" content="{{ meta_refresh }}">{% endif %}
{% if meta_viewport %}<meta name="viewport" content="{{ meta_viewport }}">{% endif %}
{% if base_url and base_target %}<base href="{{ base_url }}" target="{{ base_target }}">{% endif %}

<link href="https://unpkg.com/[email protected]/dist/material-components-web.min.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/material-components-web.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
Expand Down