From b6491ba5dd54a25e18326ea0c91a680a0187a9e2 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Wed, 2 Jul 2025 18:33:42 +0530 Subject: [PATCH 01/11] 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 --- .github/workflows/build-gh-pages.yml | 3 +-- .github/workflows/preview.yml | 15 +++++++-------- netlify.toml | 6 ++++++ 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 netlify.toml diff --git a/.github/workflows/build-gh-pages.yml b/.github/workflows/build-gh-pages.yml index d3fe1127e..d9635aa8c 100644 --- a/.github/workflows/build-gh-pages.yml +++ b/.github/workflows/build-gh-pages.yml @@ -20,8 +20,7 @@ jobs: - name: Install dependencies run: | - pip install jupyter-book - pip install sphinx-tags + pip install -r requirements.txt - name: Build the book run: | diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 49f369153..9ecea08d9 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,12 +1,12 @@ name: Deploy PR previews on: - pull_request: - types: - - opened - - reopened - - synchronize - - closed + # pull_request: + # types: + # - opened + # - reopened + # - synchronize + # - closed permissions: contents: write @@ -28,8 +28,7 @@ jobs: - name: Install dependencies run: | - pip install jupyter-book - pip install sphinx-tags + pip install -r requirements.txt - name: Build the book if: github.event.action != 'closed' diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..2ab3e0a6e --- /dev/null +++ b/netlify.toml @@ -0,0 +1,6 @@ +[build] + publish = "DISCOVER/_build/html" + command = "pip install -r requirements.txt && rm -rf DISCOVER/_tags/* && sphinx-build -b html DISCOVER/ DISCOVER/_build/html" + +[build.environment] + PYTHON_VERSION = "3.12" \ No newline at end of file From 820d5c7c38ecb0582c91effd6afce88892ba874d Mon Sep 17 00:00:00 2001 From: AR21SM Date: Fri, 18 Jul 2025 12:34:59 +0530 Subject: [PATCH 02/11] deleted preview.yml --- .github/workflows/preview.yml | 45 ----------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index 9ecea08d9..000000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Deploy PR previews - -on: - # pull_request: - # types: - # - opened - # - reopened - # - synchronize - # - closed - -permissions: - contents: write - -concurrency: preview-${{ github.ref }} - -jobs: - deploy-preview: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Python 3.12.8 - uses: actions/setup-python@v4 - with: - python-version: 3.12.8 - - - name: Install dependencies - run: | - pip install -r requirements.txt - - - name: Build the book - if: github.event.action != 'closed' - run: | - rm -rf DISCOVER/_tags/* - jupyter-book build DISCOVER - - - name: Deploy PR Preview - uses: rossjrw/pr-preview-action@v1 - with: - source-dir: ./DISCOVER/_build/html/ - preview-branch: gh-pages - umbrella-dir: pr-preview - action: auto From 2c45f6d4b8f4dac1a8e82efef4b2b50c47686a6c Mon Sep 17 00:00:00 2001 From: AR21SM Date: Fri, 18 Jul 2025 13:22:30 +0530 Subject: [PATCH 03/11] added build.sh --- ci/build.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ci/build.sh diff --git a/ci/build.sh b/ci/build.sh new file mode 100644 index 000000000..08cad6a43 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,13 @@ + +echo "Starting build process..." + +# Install dependencies +pip install -r requirements.txt + +# Clean tags directory +rm -rf DISCOVER/_tags/* + +echo "Building English version..." +sphinx-build -b html DISCOVER/ DISCOVER/_build/html + +echo "Build completed successfully" \ No newline at end of file From 29a584b529593ccd0515c9ed9716936fee361420 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Fri, 18 Jul 2025 13:42:51 +0530 Subject: [PATCH 04/11] updated workflows and netlify.toml file --- .github/workflows/build-gh-pages.yml | 7 +------ ci/{build.sh => build_website.sh} | 10 ++++++++++ netlify.toml | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) rename ci/{build.sh => build_website.sh} (51%) diff --git a/.github/workflows/build-gh-pages.yml b/.github/workflows/build-gh-pages.yml index d9635aa8c..234e874fc 100644 --- a/.github/workflows/build-gh-pages.yml +++ b/.github/workflows/build-gh-pages.yml @@ -18,14 +18,9 @@ jobs: with: python-version: 3.13 - - name: Install dependencies - run: | - pip install -r requirements.txt - - name: Build the book run: | - rm -rf DISCOVER/_tags/* - sphinx-build -b html DISCOVER/ DISCOVER/_build/html + bash ci/build_website.sh - name: Push book HTML to gh-pages uses: peaceiris/actions-gh-pages@v3.9.0 diff --git a/ci/build.sh b/ci/build_website.sh similarity index 51% rename from ci/build.sh rename to ci/build_website.sh index 08cad6a43..53f30cb69 100644 --- a/ci/build.sh +++ b/ci/build_website.sh @@ -10,4 +10,14 @@ rm -rf DISCOVER/_tags/* echo "Building English version..." sphinx-build -b html DISCOVER/ DISCOVER/_build/html + +# Copy root level files if they exist +if [ -f "DISCOVER/_static/404.html" ]; then + cp DISCOVER/_static/404.html DISCOVER/_build/html/ +fi + +if [ -f "DISCOVER/_static/index.html" ]; then + cp DISCOVER/_static/index.html DISCOVER/_build/html/ +fi + echo "Build completed successfully" \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 2ab3e0a6e..a24b3ff6b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,6 @@ [build] publish = "DISCOVER/_build/html" - command = "pip install -r requirements.txt && rm -rf DISCOVER/_tags/* && sphinx-build -b html DISCOVER/ DISCOVER/_build/html" + command = "bash ci/build_website.sh" [build.environment] PYTHON_VERSION = "3.12" \ No newline at end of file From 031010a25d7adc67196ff969284519ba24e48c68 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Mon, 16 Jun 2025 16:56:46 +0530 Subject: [PATCH 05/11] Added dynamic version dropdown and static language switcher --- DISCOVER/_static/languages.json | 28 ++++++++++ DISCOVER/_static/versions.json | 12 +++++ DISCOVER/_templates/language-switcher.html | 19 +++++++ DISCOVER/conf.py | 61 +++++++++++++++++++--- README.md | 10 ++-- 5 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 DISCOVER/_static/languages.json create mode 100644 DISCOVER/_static/versions.json create mode 100644 DISCOVER/_templates/language-switcher.html diff --git a/DISCOVER/_static/languages.json b/DISCOVER/_static/languages.json new file mode 100644 index 000000000..8bed96ebb --- /dev/null +++ b/DISCOVER/_static/languages.json @@ -0,0 +1,28 @@ +[ + { + "language": "en", + "name": "English", + "preferred": true, + "url": "https://discover-cookbook.numfocus.org/2.0/en" + }, + { + "language": "hi", + "name": "हिन्दी", + "url": "https://discover-cookbook.numfocus.org/2.0/hi" + }, + { + "language": "es", + "name": "Español", + "url": "https://discover-cookbook.numfocus.org/2.0/es" + }, + { + "language": "fr", + "name": "Français", + "url": "https://discover-cookbook.numfocus.org/2.0/fr" + }, + { + "language": "pt", + "name": "Português", + "url": "https://discover-cookbook.numfocus.org/2.0/pt" + } +] \ No newline at end of file diff --git a/DISCOVER/_static/versions.json b/DISCOVER/_static/versions.json new file mode 100644 index 000000000..1378b0c6d --- /dev/null +++ b/DISCOVER/_static/versions.json @@ -0,0 +1,12 @@ +[ + { + "version": "2.0", + "preferred": true, + "url": "https://discover-cookbook.numfocus.org/2.0/" + }, + { + "version": "1.0", + "url": "https://discover-cookbook.numfocus.org/1.0/" + } + +] diff --git a/DISCOVER/_templates/language-switcher.html b/DISCOVER/_templates/language-switcher.html new file mode 100644 index 000000000..6d935fa55 --- /dev/null +++ b/DISCOVER/_templates/language-switcher.html @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/DISCOVER/conf.py b/DISCOVER/conf.py index aed03e5ca..94c15079c 100644 --- a/DISCOVER/conf.py +++ b/DISCOVER/conf.py @@ -1,12 +1,32 @@ -############################################################################### -# Auto-generated by `jupyter-book config` -# If you wish to continue using _config.yml, make edits to that file and -# re-generate this one. -############################################################################### +version = '2.0' +language = 'en' + +import json +import os + +# Load language data from languages.json +language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json') +language_data = [] +if os.path.exists(language_json_path): + with open(language_json_path, 'r',encoding='utf-8') as f: + language_data = json.load(f) + +language_names = {} +for lang in language_data: + if "language" in lang and "name" in lang: + language_names[lang["language"]] = lang["name"] + + +html_context = { + "languages": language_data, + "language_names": language_names, + "current_language": language, + "current_version": version +} + author = 'Community' comments_config = {'hypothesis': False, 'utterances': False} copyright = '2023' - exclude_patterns = ['**.ipynb_checkpoints', '.DS_Store', 'Thumbs.db', '_build'] 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'] external_toc_exclude_missing = False @@ -19,7 +39,34 @@ html_sourcelink_suffix = '' html_static_path = ['_static'] html_theme = 'sphinx_book_theme' -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} +templates_path = ["_templates"] +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, + + + "article_header_start": ["toggle-primary-sidebar","version-switcher","language-switcher"], + "navigation_with_keys": False, + "show_version_warning_banner": True, + "switcher": { + "json_url": ( + "_static/versions.json" + # "https://discover-cookbook.numfocus.org/DISCOVER/_static/versions.json" + ), + "version_match": version, + }, +} + html_title = 'DISCOVER' latex_engine = 'pdflatex' myst_enable_extensions = ['colon_fence', 'dollarmath', 'linkify', 'substitution', 'tasklist'] diff --git a/README.md b/README.md index 3376ac861..207e9338b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ While content is the heart of the project, the quality of the content needs to r ### Bug fixes -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). +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). > **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. @@ -47,7 +47,7 @@ To contribute changes: 4. **Make Changes**: - Edit files in your preferred editor - - Build and verify your changes locally using the [build instructions](#how-to-run-the-book-locally) below + - See [how to build and run the site locally](#how-to-build-and-run-the-site-locally) below to test your changes. 5. **Test Locally**: Build the book and view your changes: ```sh @@ -72,7 +72,7 @@ To contribute changes: See the [contributing.md](CONTRIBUTING.md) for a detailed guide on how to contribute. -## How to run the book locally +## How to Build and Run the Site Locally Create a local python environment and install all the required dependencies using the following commands (either with conda or pip) @@ -85,7 +85,7 @@ conda env create -f environment.yml ```sh conda activate DISCOVER-Cookbook ``` -3. Finally, to build the Jupyter Book +3. Finally, to build the sphinx-build ``` sh sphinx-build -b html DISCOVER/ DISCOVER/_build/html ``` @@ -108,7 +108,7 @@ source .venv/bin/activate ```sh pip install -r requirements.txt ``` -4. Finally, to build the Jupyter Book +4. Finally, to build the sphinx-build ``` sh sphinx-build -b html DISCOVER/ DISCOVER/_build/html ``` From bd11923501b98cedc78dd602b871b7c6088ff235 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Tue, 1 Jul 2025 22:53:53 +0530 Subject: [PATCH 06/11] fixed all proposed changes --- DISCOVER/_static/languages.json | 39 ++++++++++++---------- DISCOVER/_templates/language-switcher.html | 10 +++--- DISCOVER/conf.py | 17 +++++++--- README.md | 4 +-- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/DISCOVER/_static/languages.json b/DISCOVER/_static/languages.json index 8bed96ebb..835a1f293 100644 --- a/DISCOVER/_static/languages.json +++ b/DISCOVER/_static/languages.json @@ -1,28 +1,33 @@ [ { - "language": "en", - "name": "English", - "preferred": true, - "url": "https://discover-cookbook.numfocus.org/2.0/en" + "code": "en", + "name_local": "English", + "direction": "ltr" }, - { - "language": "hi", - "name": "हिन्दी", - "url": "https://discover-cookbook.numfocus.org/2.0/hi" + { + "code": "hi", + "name_local": "हिन्दी", + "direction": "ltr" + }, + { + "code": "es", + "name_local": "Español", + "direction": "ltr" }, { - "language": "es", - "name": "Español", - "url": "https://discover-cookbook.numfocus.org/2.0/es" + "code": "fr", + "name_local": "Français", + "direction": "ltr" }, { - "language": "fr", - "name": "Français", - "url": "https://discover-cookbook.numfocus.org/2.0/fr" + "code": "pt", + "name_local": "Português", + "direction": "ltr" }, { - "language": "pt", - "name": "Português", - "url": "https://discover-cookbook.numfocus.org/2.0/pt" + "code": "ar", + "name_local": "العربية", + "direction": "rtl", + "hidden": true } ] \ No newline at end of file diff --git a/DISCOVER/_templates/language-switcher.html b/DISCOVER/_templates/language-switcher.html index 6d935fa55..bd205e2ae 100644 --- a/DISCOVER/_templates/language-switcher.html +++ b/DISCOVER/_templates/language-switcher.html @@ -5,15 +5,13 @@ \ No newline at end of file diff --git a/DISCOVER/conf.py b/DISCOVER/conf.py index 94c15079c..b277a1e46 100644 --- a/DISCOVER/conf.py +++ b/DISCOVER/conf.py @@ -1,5 +1,6 @@ version = '2.0' language = 'en' +baseurl = 'https://discover-cookbook.numfocus.org' import json import os @@ -8,22 +9,28 @@ language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json') language_data = [] if os.path.exists(language_json_path): - with open(language_json_path, 'r',encoding='utf-8') as f: - language_data = json.load(f) + with open(language_json_path, 'r', encoding='utf-8') as f: + all_languages = json.load(f) + # Filter out hidden languages + language_data = [lang for lang in all_languages if not lang.get('hidden', False)] +# Create a mapping of language codes to their localized names language_names = {} for lang in language_data: - if "language" in lang and "name" in lang: - language_names[lang["language"]] = lang["name"] + if "code" in lang and "name_local" in lang: + language_names[lang["code"]] = lang["name_local"] html_context = { "languages": language_data, "language_names": language_names, "current_language": language, - "current_version": version + "current_version": version, + "baseurl": baseurl } +html_baseurl = baseurl + author = 'Community' comments_config = {'hypothesis': False, 'utterances': False} copyright = '2023' diff --git a/README.md b/README.md index 207e9338b..eac4e8d19 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ conda env create -f environment.yml ```sh conda activate DISCOVER-Cookbook ``` -3. Finally, to build the sphinx-build +3. Finally, to build the Jupyter Book ``` sh sphinx-build -b html DISCOVER/ DISCOVER/_build/html ``` @@ -108,7 +108,7 @@ source .venv/bin/activate ```sh pip install -r requirements.txt ``` -4. Finally, to build the sphinx-build +4. Finally, to build the Jupyter Book ``` sh sphinx-build -b html DISCOVER/ DISCOVER/_build/html ``` From 3b7bd815bc979f43c43c3db65f2dea455ab99ae9 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Tue, 29 Jul 2025 18:03:04 +0530 Subject: [PATCH 07/11] updated build-gh-pages.yml --- .github/workflows/build-gh-pages.yml | 1 + ci/build_website.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-gh-pages.yml b/.github/workflows/build-gh-pages.yml index 234e874fc..1e96fec60 100644 --- a/.github/workflows/build-gh-pages.yml +++ b/.github/workflows/build-gh-pages.yml @@ -27,4 +27,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./DISCOVER/_build/html + destination_dir: dev/ keep_files: true diff --git a/ci/build_website.sh b/ci/build_website.sh index 53f30cb69..e5cbb6af3 100644 --- a/ci/build_website.sh +++ b/ci/build_website.sh @@ -8,7 +8,7 @@ pip install -r requirements.txt rm -rf DISCOVER/_tags/* echo "Building English version..." -sphinx-build -b html DISCOVER/ DISCOVER/_build/html +sphinx-build -b html DISCOVER/ DISCOVER/_build/html/en # Copy root level files if they exist From 05ddee210229bdfcfdf12093224eab0116570764 Mon Sep 17 00:00:00 2001 From: AR21SM Date: Sat, 2 Aug 2025 15:15:41 +0530 Subject: [PATCH 08/11] Fixed all Proposed changes --- .github/workflows/build-gh-pages.yml | 1 + DISCOVER/_static/languages.json | 23 ++-------------------- DISCOVER/_static/versions.json | 8 ++++++-- DISCOVER/_templates/language-switcher.html | 2 +- DISCOVER/conf.py | 21 ++++++++------------ ci/build_website.sh | 6 +++--- 6 files changed, 21 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-gh-pages.yml b/.github/workflows/build-gh-pages.yml index 1e96fec60..4106b097f 100644 --- a/.github/workflows/build-gh-pages.yml +++ b/.github/workflows/build-gh-pages.yml @@ -5,6 +5,7 @@ on: push: branches: - main + - next # This job installs dependencies, build the book, and pushes it to `gh-pages` jobs: diff --git a/DISCOVER/_static/languages.json b/DISCOVER/_static/languages.json index 835a1f293..08fe61f41 100644 --- a/DISCOVER/_static/languages.json +++ b/DISCOVER/_static/languages.json @@ -4,30 +4,11 @@ "name_local": "English", "direction": "ltr" }, - { - "code": "hi", - "name_local": "हिन्दी", - "direction": "ltr" - }, { "code": "es", "name_local": "Español", - "direction": "ltr" - }, - { - "code": "fr", - "name_local": "Français", - "direction": "ltr" - }, - { - "code": "pt", - "name_local": "Português", - "direction": "ltr" - }, - { - "code": "ar", - "name_local": "العربية", - "direction": "rtl", + "direction": "ltr", "hidden": true } + ] \ No newline at end of file diff --git a/DISCOVER/_static/versions.json b/DISCOVER/_static/versions.json index 1378b0c6d..54baa593d 100644 --- a/DISCOVER/_static/versions.json +++ b/DISCOVER/_static/versions.json @@ -1,8 +1,12 @@ [ + { + "version": "dev", + "url": "https://discover-cookbook.numfocus.org/dev/" + }, { "version": "2.0", - "preferred": true, - "url": "https://discover-cookbook.numfocus.org/2.0/" + "url": "https://discover-cookbook.numfocus.org/2.0/", + "preferred": true }, { "version": "1.0", diff --git a/DISCOVER/_templates/language-switcher.html b/DISCOVER/_templates/language-switcher.html index bd205e2ae..44b5726fb 100644 --- a/DISCOVER/_templates/language-switcher.html +++ b/DISCOVER/_templates/language-switcher.html @@ -1,7 +1,7 @@