Skip to content

Conversation

@AR21SM
Copy link
Member

@AR21SM AR21SM commented Jun 16, 2025

Detailed Description:

Overview

This PR introduces a comprehensive multi-version and multi-language infrastructure for the DISCOVER Cookbook, enabling users to seamlessly navigate between different documentation versions and language translations through intuitive UI components.

Key Features Implemented

Dynamic Version Switcher

  • JSON-based Configuration: Added versions.json defining available versions with URL mapping and preferred version marking:
[
    {
        "version": "2.0",
        "url": "https://discover-cookbook.numfocus.org/2.0/",
        "preferred": true
    }
]
  • Sphinx Integration: Configured sphinx-book-theme switcher functionality with dynamic JSON URL loading:
html_theme_options = {
    "article_header_start": ["toggle-primary-sidebar","version-switcher","language-switcher"],
    "switcher": {
        "json_url": "https://discover-cookbook.numfocus.org/versions.json", 
        "version_match": version,
    },
}
  • Version Management: Automatic version detection and display in header navigation

Multi-Language Support Infrastructure

  • Language Configuration: Created languages.json supporting multiple languages with locale names, text direction, and visibility control:
[
    {
        "code": "es",
        "name_local": "Español",
        "direction": "ltr",
        "hidden": true
    }
]
  • Template System: Implemented language-switcher.html template with Bootstrap dropdown functionality

  • Context Variables: Added comprehensive HTML context variables for language data, current language detection, and URL generation:

# Load language data from languages.json
language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json')
language_data = []
current_language_name = None
if os.path.exists(language_json_path):
    with open(language_json_path, 'r', encoding='utf-8') as f:
        all_languages = json.load(f)

# Get the current language name 
current_language_name = next((lang['name_local'] for lang in all_languages if lang['code'] == language), language)

# Filter out hidden languages for the dropdown
language_data = [lang for lang in all_languages if not lang.get('hidden', False)]

html_context = {
    "languages": language_data,
    "current_language_name": current_language_name,
    "current_language": language,
    "current_version": version,
    "baseurl": baseurl
}
  • Hidden Language Support: Built-in capability to hide specific languages from public interface while maintaining backend support

Build System Enhancements

  • Build Script: Created ci/build_website.sh for streamlined build process.

  • Added destination_dir: dev/ for development version deployment:

- name: Push book HTML to gh-pages
  uses: peaceiris/[email protected]
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./DISCOVER/_build/html
    destination_dir: dev/
    keep_files: true

This implementation establishes a robust foundation for the DISCOVER Cookbook's evolution into a multi-version, multi-language documentation platform while maintaining seamless user experience.

@AR21SM
Copy link
Member Author

AR21SM commented Jun 16, 2025

Hi @OriolAbril,
I've now added the static language switcher using languages.json, and the dynamic version dropdown using versions.json.
Could you please verify ??

@OriolAbril
Copy link
Contributor

Thanks! I will try to review before the meeting tomorrow but there is high probability I won't be able. The video looks good and the modified lines summary of +167 −48 looks very promising too

Copy link
Member

@aterrel aterrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting this PR at the moment seems to make it so the live site will be pushing a switcher that goes to a 404. Can we fix that first?

@OriolAbril
Copy link
Contributor

Even if we fixed this I don't think it is ready to merge yet

@AR21SM AR21SM marked this pull request as draft June 26, 2025 01:04
@aterrel aterrel added the 🔄 changes required need update before reviewing again label Jun 27, 2025
@AR21SM
Copy link
Member Author

AR21SM commented Jul 1, 2025

Hi @OriolAbril, when you get a chance, could you please review this? I believe I’ve addressed all your feedback and implemented the changes as discussed in proposal #334

…l 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
@AR21SM
Copy link
Member Author

AR21SM commented Jul 17, 2025

Hi @OriolAbril Could you please verify ??
image

Copy link
Contributor

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great already, we have to coordinate in the next meeting to see how to "backport" part of these changes to 1.0 and 2.0 branches

@aterrel
Copy link
Member

aterrel commented Jul 22, 2025

I created a next branch so we can accept this without causing problems with the current workflow. https://github.com/numfocus/DISCOVER-Cookbook/tree/next

@OriolAbril OriolAbril changed the base branch from main to next July 22, 2025 17:05
@AR21SM AR21SM marked this pull request as ready for review July 29, 2025 16:50
Copy link
Contributor

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments are so we can merge this and start backporting elements of this PR into the other versions.

@AR21SM
Copy link
Member Author

AR21SM commented Aug 2, 2025

Hi, @OriolAbril can you verify ?

@AR21SM
Copy link
Member Author

AR21SM commented Aug 2, 2025

Hi @aterrel , Could you please add the next branch in Netlify so PR previews work for it too? 😊

@AR21SM
Copy link
Member Author

AR21SM commented Aug 5, 2025

Previously

Screen.Recording.2025-08-05.185854.mp4

Now

Screen.Recording.2025-08-05.185351.mp4

@OriolAbril
Copy link
Contributor

@AR21SM you have to undo this commit fix: correct English URL structure in language switcher. There will be nothing at url/<version>/, the english version will be at url/<version>/en. Using sphinx-build -b html DISCOVER/ DISCOVER/_build/html/en in the bash script and then publishing DISCOVER/_build/html as is takes care of keeping the en/ folder instead of having the english version at the version root.

@OriolAbril
Copy link
Contributor

The styling is a good start, we can continue polishing in follow up PRs. If you want to open an issue or a discussion to get an idea/proposal on what we want to happen do not hesitate to do so then tag us. In my opinion, we should try to match the look and behaviour of https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html as much as possible (we are using the compontent from the theme, but using a different theme, so it has many differences even if the core javascript to change the urls to matching ones is the same).

DISCOVER/conf.py Outdated
"navigation_with_keys": False,
"show_version_warning_banner": True,
"switcher": {
"json_url": "https://discover-cookbook.numfocus.org/_static/versions.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be nothing at this url given the current pipeline. I would propose using https://discover-cookbook.numfocus.org/versions.json and copying the json into that path but only when deploying from main/next. Otherwise use https://discover-cookbook.numfocus.org/dev/en/_static/versions.json which will already exist.

Having these jsons inside _static could be a bit confusing because the static folder is copied for every build. That is url/dev/es/ will also have the _static folder with the two jsons, same for url/2.0/en/

@AR21SM
Copy link
Member Author

AR21SM commented Aug 5, 2025

Screen.Recording.2025-08-05.204644.mp4

currently, it looks like this. I was thinking , should I reduce the font size (and box size) a bit and maybe add a little margin between the two buttons? Also, it’s placed at the left corner .Do you think that’s fine, or should I move it to the right or somewhere else? Open to any suggestions.

@OriolAbril OriolAbril merged commit 296a6af into numfocus:next Aug 5, 2025
OriolAbril pushed a commit that referenced this pull request Aug 24, 2025
* 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]>
OriolAbril pushed a commit that referenced this pull request Aug 26, 2025
* 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]>
@AR21SM AR21SM changed the title Added dynamic version dropdown and static language switcher feat: Implement dynamic version dropdown and static language switcher Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔄 changes required need update before reviewing again

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants