Skip to content

Commit 2145a53

Browse files
authored
Merge pull request #381 from numfocus/next
Add gsoc outputs to `main`
2 parents 550ad44 + 4092bfe commit 2145a53

8 files changed

Lines changed: 244 additions & 44 deletions

File tree

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,128 @@
11
name: deploy-book
22

3-
# Only run this when the main branch changes
43
on:
54
push:
65
branches:
7-
- main
6+
- main
7+
- '*-translations'
8+
- '!1.0-translations'
9+
10+
concurrency:
11+
group: "gh-pages"
12+
cancel-in-progress: true
813

9-
# This job installs dependencies, build the book, and pushes it to `gh-pages`
1014
jobs:
15+
get-info:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
languages: ${{ steps.get-languages.outputs.languages }}
19+
version: ${{ steps.version-info.outputs.version }}
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Get languages directly with jq
25+
id: get-languages
26+
run: |
27+
languages=$(jq -c '[.[] | .code]' DISCOVER/_static/languages.json)
28+
echo "languages=${languages}" >> "$GITHUB_OUTPUT"
29+
30+
- name: Determine version from GitHub context
31+
id: version-info
32+
env:
33+
REF_NAME: ${{ github.ref_name }}
34+
REF_TYPE: ${{ github.ref_type }}
35+
run: |
36+
version="dev"
37+
if [[ "$REF_TYPE" == "tag" ]]; then
38+
version="${REF_NAME#v}"
39+
elif [[ "$REF_NAME" == *-translations ]]; then
40+
version="${REF_NAME%-translations}"
41+
fi
42+
echo "version=$version" >> "$GITHUB_OUTPUT"
43+
1144
deploy-book:
45+
needs: get-info
1246
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
language: ${{ fromJSON(needs.get-info.outputs.languages) }}
1350
steps:
14-
- uses: actions/checkout@v2
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
56+
- name: Set up Python 3.13
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.13'
60+
61+
- name: Build documentation with script
62+
env:
63+
VERSION: ${{ needs.get-info.outputs.version }}
64+
LANGUAGE: ${{ matrix.language }}
65+
run: |
66+
bash ci/build_website.sh
1567
16-
- name: Set up Python 3.13
17-
uses: actions/setup-python@v1
18-
with:
19-
python-version: 3.13
68+
- name: Deploy language to GitHub Pages
69+
uses: peaceiris/actions-gh-pages@v4
70+
with:
71+
github_token: ${{ secrets.GITHUB_TOKEN }}
72+
publish_dir: ./DISCOVER/_build/html
73+
destination_dir: ${{ needs.get-info.outputs.version }}/${{ matrix.language }}
74+
keep_files: true
2075

21-
- name: Build the book
22-
run: |
23-
bash ci/build_website.sh
76+
create-redirect:
77+
needs: [get-info, deploy-book]
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Create version redirect
81+
run: |
82+
mkdir -p temp_redirect
83+
cat > temp_redirect/index.html << 'EOF'
84+
<!DOCTYPE html>
85+
<html>
86+
<head>
87+
<meta charset="UTF-8">
88+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
89+
<title>DISCOVER Cookbook - Redirecting...</title>
90+
<link rel="canonical" href="./en/">
91+
<meta http-equiv="refresh" content="0; url=./en/">
92+
</head>
93+
<body>
94+
<a href="./en/">Redirecting to English...</a>
95+
</body>
96+
</html>
97+
EOF
98+
99+
- name: Deploy version redirect
100+
uses: peaceiris/actions-gh-pages@v4
101+
with:
102+
github_token: ${{ secrets.GITHUB_TOKEN }}
103+
publish_dir: ./temp_redirect
104+
destination_dir: ${{ needs.get-info.outputs.version }}
105+
keep_files: true
106+
107+
deploy-root-files:
108+
needs: [get-info, deploy-book]
109+
runs-on: ubuntu-latest
110+
if: github.ref_name == 'main'
111+
steps:
112+
- name: Checkout repository
113+
uses: actions/checkout@v4
24114

115+
- name: Create root files directory
116+
run: |
117+
mkdir -p root_files
118+
cp DISCOVER/404.html root_files/
119+
cp index.html root_files/
120+
cp DISCOVER/_static/versions.json root_files/
25121
26-
- name: Push book HTML to gh-pages
27-
uses: peaceiris/actions-gh-pages@v3.9.0
28-
with:
29-
github_token: ${{ secrets.GITHUB_TOKEN }}
30-
publish_dir: ./DISCOVER/_build/html
31-
keep_files: true
32-
122+
- name: Deploy root files to GitHub Pages
123+
uses: peaceiris/actions-gh-pages@v4
124+
with:
125+
github_token: ${{ secrets.GITHUB_TOKEN }}
126+
publish_dir: ./root_files
127+
destination_dir: .
128+
keep_files: true

DISCOVER/_static/css/mainLogo.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,4 @@ html[data-theme=dark] .dropdown-item.active:hover {
225225
.bd-header-article .version-switcher__button,
226226
.bd-header-article #language-switcher-button {
227227
margin: 0 !important;
228-
}
228+
}

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: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
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+
import json
2+
import os
3+
4+
version = os.environ.get("WEBSITE_VERSION", "dev")
5+
language = os.environ.get("WEBSITE_LANGUAGE", "en")
6+
7+
baseurl = 'https://discover-cookbook.numfocus.org'
8+
9+
# Load language data from languages.json
10+
language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json')
11+
language_data = []
12+
current_language_name = None
13+
if os.path.exists(language_json_path):
14+
with open(language_json_path, 'r', encoding='utf-8') as f:
15+
all_languages = json.load(f)
16+
17+
# Get the current language name
18+
current_language_name = next((lang['name_local'] for lang in all_languages if lang['code'] == language), language)
19+
20+
# Filter out hidden languages for the dropdown
21+
language_data = [lang for lang in all_languages if not lang.get('hidden', False)]
22+
23+
html_context = {
24+
"languages": language_data,
25+
"current_language_name": current_language_name,
26+
"current_language": language,
27+
"current_version": version,
28+
"baseurl": baseurl
29+
}
30+
31+
html_baseurl = baseurl
32+
633
author = 'Community'
734
comments_config = {'hypothesis': False, 'utterances': False}
835
copyright = '2023'
9-
1036
exclude_patterns = ['**.ipynb_checkpoints', '.DS_Store', 'Thumbs.db', '_build']
11-
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']
37+
extensions = [
38+
'sphinx_togglebutton',
39+
'sphinx_copybutton',
40+
'myst_parser',
41+
'jupyter_book',
42+
'sphinx_external_toc',
43+
'sphinx.ext.intersphinx',
44+
'sphinx_design',
45+
'sphinx_book_theme',
46+
'sphinx_tags',
47+
'sphinx_jupyterbook_latex',
48+
'sphinx_multitoc_numbering'
49+
]
1250
external_toc_exclude_missing = False
1351
external_toc_path = '_toc.yml'
1452
html_baseurl = ''
@@ -19,7 +57,31 @@
1957
html_sourcelink_suffix = ''
2058
html_static_path = ['_static']
2159
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}
60+
templates_path = ["_templates"]
61+
html_theme_options = {
62+
'search_bar_text': 'Search this book...',
63+
'launch_buttons': {'notebook_interface': 'classic', 'binderhub_url': '', 'jupyterhub_url': '', 'thebe': False, 'colab_url': '', 'deepnote_url': ''},
64+
'path_to_docs': 'DISCOVER',
65+
'repository_url': 'https://github.com/numfocus/DISCOVER-Cookbook/',
66+
'repository_branch': 'main',
67+
'extra_footer': '',
68+
'home_page_in_toc': True,
69+
'announcement': '',
70+
'analytics': {'google_analytics_id': '', 'plausible_analytics_domain': '', 'plausible_analytics_url': 'https://plausible.io/js/script.js'},
71+
'use_repository_button': True,
72+
'use_edit_page_button': False,
73+
'use_issues_button': True,
74+
75+
76+
"article_header_start": ["toggle-primary-sidebar","version-switcher","language-switcher"],
77+
"navigation_with_keys": False,
78+
"show_version_warning_banner": True,
79+
"switcher": {
80+
"json_url": "https://discover-cookbook.numfocus.org/versions.json",
81+
"version_match": version,
82+
},
83+
}
84+
2385
html_title = 'DISCOVER'
2486
latex_engine = 'pdflatex'
2587
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: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
1+
#!/usr/bin/env bash
22
echo "Starting build process..."
33

4+
# Get parameters with defaults
5+
VERSION=${VERSION:-${1:-"dev"}}
6+
LANGUAGE=${LANGUAGE:-${2:-"en"}}
7+
8+
echo "Building version: $VERSION, language: $LANGUAGE"
9+
410
# Install dependencies
511
pip install -r requirements.txt
612

713
# Clean tags directory
814
rm -rf DISCOVER/_tags/*
915

10-
echo "Building English version..."
11-
sphinx-build -b html DISCOVER/ DISCOVER/_build/html
12-
13-
14-
# Copy root level files if they exist
15-
if [ -f "DISCOVER/_static/404.html" ]; then
16-
cp DISCOVER/_static/404.html DISCOVER/_build/html/
17-
fi
18-
19-
if [ -f "DISCOVER/_static/index.html" ]; then
20-
cp DISCOVER/_static/index.html DISCOVER/_build/html/
21-
fi
2216

23-
echo "Build completed successfully"
17+
echo "Building $LANGUAGE version..."
18+
WEBSITE_VERSION="$VERSION" WEBSITE_LANGUAGE="$LANGUAGE" sphinx-build -b html DISCOVER/ DISCOVER/_build/html

0 commit comments

Comments
 (0)