Skip to content

Commit

Permalink
Include by default a HoloViz dropdown in the primary sidebar with lin…
Browse files Browse the repository at this point in the history
…ks to all the HoloViz sites (#319)
  • Loading branch information
maximlt authored Nov 16, 2024
1 parent 7c4c941 commit c8f6e24
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 22 deletions.
43 changes: 43 additions & 0 deletions nbsite/_shared_static/hv-sidebar-dropdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Sidebar styling for the HoloViz dropdown section */
.hv-sb-dd {
margin-bottom: 0.5em;
}

.hv-sb-dd .btn-group {
width: 100%;
}

.hv-sb-dd .hv-sb-dd-value {
text-align: start;
font-size: 0.9rem;
}

.hv-sb-dd .btn {
background-color: var(--pst-color-surface);
color: var(--pst-color-text-base);
}

.hv-sb-dd a.btn:hover {
color: var(--pst-color-link-hover);
text-decoration: underline;
text-decoration-thickness: max(3px, 0.1875rem, 0.12em);
}

.hv-sb-dd .dropdown-toggle-split {
border-left: solid 1px lightgray;
}

.hv-sb-dd .dropdown-menu {
width: 100%;
background-color: var(--pst-color-surface);
color: var(--pst-color-text-base);
}

.hv-sb-dd .dropdown-item {
font-size: 0.8rem;
}

.hv-sb-dd .hv-icon {
font-size: 0.75em;
margin-left: 0.3em;
}
29 changes: 29 additions & 0 deletions nbsite/_shared_templates/hv-sidebar-dropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% if hv_sidebar_dropdown %}
<div class="hv-sb-dd">
<div class="btn-group">
{% if 'href' in hv_sidebar_dropdown['dropdown_value'] %}
<a href="{{ hv_sidebar_dropdown['dropdown_value']['href'] }}" class="btn hv-sb-dd-value" target="_blank">{{ hv_sidebar_dropdown['dropdown_value']['text'] }}<i class="fa fa-external-link hv-icon" aria-hidden="true"></i></a>
{% else %}
<span class="btn hv-sb-dd-value">{{ hv_sidebar_dropdown['dropdown_value']['text'] }}</span>
{% endif %}
<button type="button" class="btn dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden"></span>
</button>
<ul class="dropdown-menu">
{% for project_name, project_opts in hv_sidebar_dropdown['libraries'].items() %}
{% if project_name | lower not in project | lower %}
<li><a class="dropdown-item" href="{{ project_opts['url'] }}" target="_blank" title="{{ project_opts['title'] }}">{{ project_opts['text'] }}<i class="fa fa-external-link hv-icon" aria-hidden="true"></i></a></li>
{% endif %}
{% endfor %}
{% if hv_sidebar_dropdown['others'] %}
<li><hr class="dropdown-divider"></li>
{% for project_name, project_opts in hv_sidebar_dropdown['others'].items() %}
{% if project_name | lower not in project | lower %}
<li><a class="dropdown-item" href="{{ project_opts['url'] }}" target="_blank" title="{{ project_opts['title'] }}">{{ project_opts['text'] }}<i class="fa fa-external-link hv-icon" aria-hidden="true"></i></a></li>
{% endif %}
{% endfor %}
{% endif %}
</ul>
</div>
</div>
{% endif %}
116 changes: 95 additions & 21 deletions nbsite/shared_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ def holoviz_icon_white(cur_file):
return str(icon_path)


def setup(app):
try:
from nbsite.paramdoc import param_formatter, param_skip
app.connect('autodoc-process-docstring', param_formatter)
app.connect('autodoc-skip-member', param_skip)
except ImportError:
print('no param_formatter (no param?)')

nbbuild.setup(app)
app.connect("builder-inited", remove_mystnb_static)

def remove_mystnb_static(app):
# Ensure our myst_nb.css is loaded by removing myst_nb static_path
# from config
app.config.html_static_path = [
p for p in app.config.html_static_path if 'myst_nb' not in p
]

extensions = [
'myst_nb',
'sphinx_design',
Expand Down Expand Up @@ -105,7 +87,8 @@ def remove_mystnb_static(app):
'gallery.css',
'alert.css',
'dataframe.css',
'scroller.css'
'scroller.css',
'hv-sidebar-dropdown.css',
]

# A single line footer that includes the copyright and the last updated date.
Expand All @@ -123,8 +106,8 @@ def remove_mystnb_static(app):
# The layout.html template in pydata-sphinx-theme removes the default
# sidebar-nav-bs.html template.
html_sidebars = {
"index": ["sidebar-nav-bs-alt"],
"**": ["sidebar-nav-bs-alt"],
"index": ["sidebar-nav-bs-alt", "hv-sidebar-dropdown"],
"**": ["sidebar-nav-bs-alt", "hv-sidebar-dropdown"],
}

# To be reused in a conf.py file to define the `copyright` string reused
Expand Down Expand Up @@ -207,3 +190,94 @@ def linkcode_resolve(domain, info):
return f"{GITHUB_BASE_URL}{package}/blob/main/{package}/{fn}{linespec}"
else:
return f"{GITHUB_BASE_URL}{package}/blob/v{pver}/{package}/{fn}{linespec}"


nbsite_hv_sidebar_dropdown = {
'dropdown_value': {
'href': 'https://holoviz.org',
'text': 'HoloViz.org',
},
'libraries': {
'panel': {
'text': 'Panel',
'url': 'https://param.holoviz.org',
'title': 'Assembling objects from many different libraries into a layout or app, whether in a Jupyter notebook or in a standalone servable dashboard',
},
'hvplot': {
'text': 'hvPlot',
'url': 'https://hvplot.holoviz.org',
'title': 'Quickly return interactive HoloViews, GeoViews, or Panel objects from Pandas, Xarray, or other data structures',
},
'holoviews': {
'text': 'HoloViews',
'url': 'https://holoviews.org',
'title': 'Declarative objects for instantly visualizable data, building Bokeh plots from convenient high-level specifications',
},
'geoviews': {
'text': 'GeoViews',
'url': 'https://geoviews.org',
'title': 'Visualizable geographic data that that can be mixed and matched with HoloViews objects',
},
'datashader': {
'text': 'Datashader',
'url': 'https://datashader.org',
'title': 'Rasterizing huge datasets quickly as fixed-size images',
},
'param': {
'text': 'Param',
'url': 'https://param.holoviz.org',
'title': 'Make your Python code clearer and more reliable by declaring Parameters',
},
'lumen': {
'text': 'Lumen',
'url': 'https://lumen.holoviz.org',
'title': 'Framework for visual analytics that allows users to build data-driven dashboards from a simple YAML specification',
},
'colorcet': {
'text': 'Colorcet',
'url': 'https://colorcet.holoviz.org',
'title': 'A wide range of perceptually uniform continuous colormaps and perceptually based categorical color sets for use with the other libraries',
},
},
'others': {
'examples': {
'text': 'Examples Gallery',
'url': 'https://examples.holoviz.org',
'title': ' Visualization-focused examples using HoloViz for specific topics ',
},
'blog': {
'text': 'Blog',
'url': 'https://blog.holoviz.org',
'title': 'HoloViz blog',
},
},
}


def remove_mystnb_static(app):
# Ensure our myst_nb.css is loaded by removing myst_nb static_path
# from config
app.config.html_static_path = [
p for p in app.config.html_static_path if 'myst_nb' not in p
]


def add_hv_sidebar_dropdown_context(app, pagename, templatename, context, doctree, *args) -> None:
# Inject it in the context to make it available to the template namespace.s
context['hv_sidebar_dropdown'] = app.config.nbsite_hv_sidebar_dropdown


def setup(app):
try:
from nbsite.paramdoc import param_formatter, param_skip
app.connect('autodoc-process-docstring', param_formatter)
app.connect('autodoc-skip-member', param_skip)
except ImportError:
print('no param_formatter (no param?)')

nbbuild.setup(app)
app.connect("builder-inited", remove_mystnb_static)

# hv_sidebar_dropdown
app.add_config_value('nbsite_hv_sidebar_dropdown', {}, 'html')
app.connect("html-page-context", add_hv_sidebar_dropdown_context)
1 change: 0 additions & 1 deletion site/doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"icon": "fab fa-discourse",
},
],
"navbar_end": ["navbar-icon-links"],
"pygments_light_style": "material",
"pygments_dark_style": "material",
'secondary_sidebar_items': [
Expand Down

0 comments on commit c8f6e24

Please sign in to comment.