Skip to content

Commit 0cf0ddf

Browse files
AR21SMaterrel
authored andcommitted
Added dynamic version dropdown and static language switcher (#330)
* Add Netlify configuration for PR previewsThis commit adds netlify.toml configuration to enable automatic PR previews:- Configures build settings to match our GitHub Actions workflow- Sets publish directory to DISCOVER/_build/html- Configures Python 3.12 as the runtime environment- Ensures build command removes tags and rebuilds documentation- Disabled preview.yml workflow by commenting out trigger conditions * deleted preview.yml * added build.sh * updated workflows and netlify.toml file * Added dynamic version dropdown and static language switcher * fixed all proposed changes * updated build-gh-pages.yml * Fixed all Proposed changes * fix: correct English URL structure in language switcher * styled language switcher to match version switcher design * undoing the chnages --------- Co-authored-by: Andy R. Terrel <[email protected]>
1 parent 01dfdc6 commit 0cf0ddf

File tree

8 files changed

+140
-15
lines changed

8 files changed

+140
-15
lines changed

.github/workflows/build-gh-pages.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- main
8+
- next
89

910
# This job installs dependencies, build the book, and pushes it to `gh-pages`
1011
jobs:
@@ -28,5 +29,5 @@ jobs:
2829
with:
2930
github_token: ${{ secrets.GITHUB_TOKEN }}
3031
publish_dir: ./DISCOVER/_build/html
32+
destination_dir: dev/
3133
keep_files: true
32-

DISCOVER/_static/css/mainLogo.css

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,35 @@ html[data-theme=dark] .social-links a:hover {
118118
.social-links {
119119
margin: 1rem 0 0 0;
120120
}
121-
}
121+
}
122+
123+
.version-switcher__button {
124+
color: #9ca4af !important;
125+
}
126+
.version-switcher__button:hover{
127+
color: #ced6dd !important;
128+
}
129+
#language-switcher-button {
130+
background-color: #121212 !important;
131+
border: 1px solid transparent !important;
132+
}
133+
134+
#language-switcher-button:hover {
135+
background-color: #121212 !important;
136+
border: 1px solid transparent !important;
137+
box-shadow: 0 0 0 0.1875rem #e89217 !important;
138+
}
139+
140+
#language-switcher-button:focus {
141+
background-color: #121212 !important;
142+
border: 1px solid transparent !important;
143+
box-shadow: 0 0 0 0.1875rem #e89217 !important;
144+
}
145+
.dropdown-item.active {
146+
background-color:#121212 !important;
147+
color: #528fe4 !important;
148+
}
149+
.dropdown-item.active:hover {
150+
color: #ced6dd !important;
151+
}
152+

DISCOVER/_static/languages.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "en",
4+
"name_local": "English",
5+
"direction": "ltr"
6+
},
7+
{
8+
"code": "es",
9+
"name_local": "Español",
10+
"direction": "ltr",
11+
"hidden": true
12+
}
13+
14+
]

DISCOVER/_static/versions.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"version": "dev",
4+
"url": "https://discover-cookbook.numfocus.org/dev/"
5+
},
6+
{
7+
"version": "2.0",
8+
"url": "https://discover-cookbook.numfocus.org/2.0/",
9+
"preferred": true
10+
},
11+
{
12+
"version": "1.0",
13+
"url": "https://discover-cookbook.numfocus.org/1.0/"
14+
}
15+
16+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="dropdown">
2+
<button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="language-switcher-button"
3+
data-bs-toggle="dropdown" aria-expanded="false">
4+
{{current_language_name}}
5+
</button>
6+
<ul class="dropdown-menu" aria-labelledby="language-switcher-button">
7+
{% for item in languages %}
8+
<li>
9+
<a class="dropdown-item{% if current_language == item.code %}active{% endif %}"
10+
href="{{ baseurl }}/{{ current_version }}/{{ item.code }}/{{ pagename }}.html"
11+
{% if item.direction %}dir="{{ item.direction }}"{% endif %}>
12+
{{ item.name_local }}
13+
</a>
14+
</li>
15+
{% endfor %}
16+
</ul>
17+
</div>

DISCOVER/conf.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
###############################################################################
2-
# Auto-generated by `jupyter-book config`
3-
# If you wish to continue using _config.yml, make edits to that file and
4-
# re-generate this one.
5-
###############################################################################
1+
version = 'dev'
2+
language = 'en'
3+
baseurl = 'https://discover-cookbook.numfocus.org'
4+
5+
import json
6+
import os
7+
8+
# Load language data from languages.json
9+
language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json')
10+
language_data = []
11+
current_language_name = None
12+
if os.path.exists(language_json_path):
13+
with open(language_json_path, 'r', encoding='utf-8') as f:
14+
all_languages = json.load(f)
15+
16+
# Get the current language name
17+
current_language_name = next((lang['name_local'] for lang in all_languages if lang['code'] == language), language)
18+
19+
# Filter out hidden languages for the dropdown
20+
language_data = [lang for lang in all_languages if not lang.get('hidden', False)]
21+
22+
html_context = {
23+
"languages": language_data,
24+
"current_language_name": current_language_name,
25+
"current_language": language,
26+
"current_version": version,
27+
"baseurl": baseurl
28+
}
29+
30+
html_baseurl = baseurl
31+
632
author = 'Community'
733
comments_config = {'hypothesis': False, 'utterances': False}
834
copyright = '2023'
9-
1035
exclude_patterns = ['**.ipynb_checkpoints', '.DS_Store', 'Thumbs.db', '_build']
1136
extensions = ['sphinx_togglebutton', 'sphinx_copybutton', 'myst_nb', 'jupyter_book', 'sphinx_external_toc', 'sphinx.ext.intersphinx', 'sphinx_design', 'sphinx_book_theme', 'sphinx_tags', 'sphinx_jupyterbook_latex', 'sphinx_multitoc_numbering']
1237
external_toc_exclude_missing = False
@@ -19,7 +44,31 @@
1944
html_sourcelink_suffix = ''
2045
html_static_path = ['_static']
2146
html_theme = 'sphinx_book_theme'
22-
html_theme_options = {'search_bar_text': 'Search this book...', 'launch_buttons': {'notebook_interface': 'classic', 'binderhub_url': '', 'jupyterhub_url': '', 'thebe': False, 'colab_url': '', 'deepnote_url': ''}, 'path_to_docs': 'DISCOVER', 'repository_url': 'https://github.com/numfocus/DISCOVER-Cookbook/', 'repository_branch': 'main', 'extra_footer': '', 'home_page_in_toc': True, 'announcement': '', 'analytics': {'google_analytics_id': '', 'plausible_analytics_domain': '', 'plausible_analytics_url': 'https://plausible.io/js/script.js'}, 'use_repository_button': True, 'use_edit_page_button': False, 'use_issues_button': True}
47+
templates_path = ["_templates"]
48+
html_theme_options = {
49+
'search_bar_text': 'Search this book...',
50+
'launch_buttons': {'notebook_interface': 'classic', 'binderhub_url': '', 'jupyterhub_url': '', 'thebe': False, 'colab_url': '', 'deepnote_url': ''},
51+
'path_to_docs': 'DISCOVER',
52+
'repository_url': 'https://github.com/numfocus/DISCOVER-Cookbook/',
53+
'repository_branch': 'main',
54+
'extra_footer': '',
55+
'home_page_in_toc': True,
56+
'announcement': '',
57+
'analytics': {'google_analytics_id': '', 'plausible_analytics_domain': '', 'plausible_analytics_url': 'https://plausible.io/js/script.js'},
58+
'use_repository_button': True,
59+
'use_edit_page_button': False,
60+
'use_issues_button': True,
61+
62+
63+
"article_header_start": ["toggle-primary-sidebar","version-switcher","language-switcher"],
64+
"navigation_with_keys": False,
65+
"show_version_warning_banner": True,
66+
"switcher": {
67+
"json_url": "https://discover-cookbook.numfocus.org/versions.json",
68+
"version_match": version,
69+
},
70+
}
71+
2372
html_title = 'DISCOVER'
2473
latex_engine = 'pdflatex'
2574
myst_enable_extensions = ['colon_fence', 'dollarmath', 'linkify', 'substitution', 'tasklist']

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ While content is the heart of the project, the quality of the content needs to r
2424

2525
### Bug fixes
2626

27-
For issues with other elements of the book, first make sure an issue is open and tracking can occur on the issue. Then open a a [pull request](https://github.com/numfocus/DISCOVER-Cookbook/pulls).
27+
For issues with other elements of the book, first make sure an issue is open and tracking can occur on the issue. Then open a [pull request](https://github.com/numfocus/DISCOVER-Cookbook/pulls).
2828

2929
> **Note:** To contribute effectively, check for active pull requests to avoid duplication, discuss your ideas in active issues or pull requests, and seek approval from maintainers or issue creators before proceeding. Respect others' contributions and collaborate constructively to improve the project.
3030
@@ -47,7 +47,7 @@ To contribute changes:
4747

4848
4. **Make Changes**:
4949
- Edit files in your preferred editor
50-
- Build and verify your changes locally using the [build instructions](#how-to-run-the-book-locally) below
50+
- See [how to build and run the site locally](#how-to-build-and-run-the-site-locally) below to test your changes.
5151

5252
5. **Test Locally**: Build the book and view your changes:
5353
```sh
@@ -72,7 +72,7 @@ To contribute changes:
7272
See the [contributing.md](CONTRIBUTING.md) for a detailed guide on how to contribute.
7373

7474

75-
## How to run the book locally
75+
## How to Build and Run the Site Locally
7676

7777
Create a local python environment and install all the required dependencies using the following commands (either with conda or pip)
7878

ci/build_website.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ if [ -f "DISCOVER/_static/404.html" ]; then
1616
cp DISCOVER/_static/404.html DISCOVER/_build/html/
1717
fi
1818

19-
if [ -f "DISCOVER/_static/index.html" ]; then
20-
cp DISCOVER/_static/index.html DISCOVER/_build/html/
21-
fi
2219

2320
echo "Build completed successfully"

0 commit comments

Comments
 (0)