Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Improve AJAX version switcher to sort and group languages and links, document workflow #583

Merged
merged 6 commits into from
May 28, 2024

Conversation

garvinhicking
Copy link
Contributor

@garvinhicking garvinhicking commented May 28, 2024

WHY

Currently the AJAX version selector to change the context of a rendered documentation to another language or version has multiple issues:

  • It cannot be used locally without errors
  • It cannot be tested locally to simulate the "deployed" behaviour
  • It uses pre-rendered HTML from the server
  • The language sorting is uninuitive
  • the language naming with ISO-codes is not userfriendly (see Issue Languages in version selector not sorted alphabetically #358 )

This PR hopefully 'catches them all'.

CAVEAT

One extra problem is important to note: I initially wanted to adjust this server-side. However, the code used for that (garvinhicking/site-intercept@aec6c1e) is in the domain of the TYPO3 GmbH, and the Documentation team cannot easily take over Maintenance for an active server-side component. Thus it was decided to fix the problem client-side, using the provided JSON data from the docs.typo3.org API (TYPO3GmbH/site-intercept#158).

WHAT

This PR contains:

  • Updated JavaScript, which now fetches JSON instead of HTML. And parses the JSON, and converts it using sorting methods and static translation name keys to a dynamic HTML list. The HTML structure can be adjusted in the future.
  • The "In one file" section is now a HTML5 'details' element that can be toggled
  • The sorting is now:
    • English first:
      • "main" for english
      • all numbered versions for english (recent version first)
      • all "fixed name" versions for english (alphabetically descending)
    • All other languages sorted alphabetically, using the same sub-ordering than for english
  • A PHP proxy is delivered, so that when using a local webserver to view the rendered HTML you can bypass CORS and use the docs.typo3.org API to simulate rendering a version selection menu.
  • The HTML DOM is adjusted for new data-attributes so that menu simulation can be performed
  • (Hopefully) exhaustive documentation for this is provided with this PR in Documentation/Developer/AjaxVersions.rst with more insight

The most glaring sad trombone sound stems from a necessary static language fixation. The versions.js file needs to be updated for new languages published to docs.typo3.org. On the upside, for years now the docs were only rendered in english, and only 2 or 3 documentations exist in another language. For a future improvement maybe we find a JSON language file that has a list of language keys like 'de-de' and their associated language name, that we can use or enhance. It's not so often that new languages get added.

HOW

Details are, as mentioned, in Documentation/Developer/AjaxVersions.rst. To quickly simulate this you must:

  • Check out this PR
  • Start ddev if you have not already
  • make docs
  • Copy the file packages/typo3-docs-theme/assets/js/versions-proxy.php to Documentation-GENERATED-temp/versions-proxy.php
  • ddev launch to view the rendered Documentation
  • Click on the version selector menu
  • Enjoy the sample

You probably want to simulate a different menu getting rendered. You can do this by:

  • Reload the HTML URL (you can only do this once per page load, once the AJAX has been called, it will not be called again)
  • Open browser JS console, enter: document.getElementById('toc-version').setAttribute('data-override-url-self', 'https://docs.typo3.org/other/t3docs/render-guides/main/en-us/Developer/InterlinkInventories.html');
  • Click on the version selector menu
  • See the selector rendering the output of render-guides.

OUTLOOK

We can possibly improve the design of the language selector, and adjust the nesting appearance for languages. Maybe we can also separate the language selection from the version selection.

@garvinhicking garvinhicking self-assigned this May 28, 2024
@garvinhicking garvinhicking marked this pull request as draft May 28, 2024 11:51
@garvinhicking garvinhicking added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed labels May 28, 2024
@garvinhicking garvinhicking marked this pull request as ready for review May 28, 2024 14:42
@linawolf
Copy link
Member

Great work, thank you! I made some Small adjustments (label, assets regeneration)

@garvinhicking garvinhicking merged commit ccebffd into main May 28, 2024
7 checks passed
@garvinhicking garvinhicking deleted the feature-sort-ajax-menu branch May 28, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants