Skip to content

Commit

Permalink
Proxito: support single language project (#10766)
Browse files Browse the repository at this point in the history
The important changes are in the resolver and unresolver.

- A new option was added to the versioning scheme field.
- There are some extra validations in place, so users can't create translations if their project doesn't support them.
- The versioning scheme field is disabled on translations, since it doesn't any effect there.
- All usages of single_version were replaced with versioning scheme, except where it's still required for backwards compatibility (API, sphinx html_context).
- Some function/variables were renamed to use the new naming.
- Docs were added, not sure if I'm following diataxis right...
- single-version.rst was moved into `versioning-schemes.rst` and `guides/setup/versioning-schemes.rst`. A redirect is needed.

Some changes on templates need to be ported to ext-theme.

Closes #10307
  • Loading branch information
stsewd authored Nov 27, 2023
1 parent 1b38024 commit 25d3d29
Show file tree
Hide file tree
Showing 27 changed files with 529 additions and 116 deletions.
1 change: 1 addition & 0 deletions docs/user/api/v3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ Project details
``versioning_scheme`` can be one of the following values:

- ``multiple_versions_with_translations``
- ``multiple_versions_without_translations``
- ``single_version_without_translations``

.. note::
Expand Down
5 changes: 5 additions & 0 deletions docs/user/guides/setup/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ The following how-to guides help you solve common tasks and challenges in the se
Is your version (flyout) menu overwhelmed and hard to navigate?
Here's how to make it shorter.

⏩️ :doc:`Changing the versioning scheme of your project </guides/setup/versioning-schemes>`
Change how the URLs of your documentation look like,
and if your project supports multiple versions or translations.

.. seealso::

:doc:`/tutorial/index`
Expand All @@ -50,3 +54,4 @@ The following how-to guides help you solve common tasks and challenges in the se
Hiding a version </guides/hiding-a-version>
Using a .readthedocs.yaml file in a sub-folder </guides/setup/monorepo>
Using custom URL redirects in documentation projects </guides/redirects>
Changing the versioning scheme of your project </guides/setup/versioning-schemes>
24 changes: 24 additions & 0 deletions docs/user/guides/setup/versioning-schemes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
How to change the versioning scheme of your project
===================================================

In this guide, we show you how to change the versioning scheme of your project on Read the Docs.

Changing the versioning scheme of your project will affect the URLs of your documentation,
any existing links to your documentation will break.
If you want to keep the old URLs working, you can create :doc:`redirects </user-defined-redirects>`.

.. seealso::

:doc:`/versioning-schemes`
Reference of all the versioning schemes supported by Read the Docs.

:doc:`/versions`
General explanation of how versioning works on Read the Docs.

Changing the versioning scheme
------------------------------

#. Go the :guilabel:`Admin` tab of your project.
#. Click on :guilabel:`Advanced Settings`.
#. Select the new versioning scheme in the :guilabel:`Versioning scheme` dropdown.
#. Click on :guilabel:`Save`.
6 changes: 3 additions & 3 deletions docs/user/reference/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Feature reference
We support multiple versions and translations,
integrated nicely into the URL of your documentation.
This is served at ``/en/latest/`` by default.
If you only have 1 version and translation,
we also support :doc:`single version projects </single-version>` served at ``/``.
If you have only one version, or don't need translations,
you can change the :doc:`versioning scheme </versioning-schemes>` of your project.

⏩️ :doc:`/pull-requests`
Your project can be configured to build and host documentation for every new pull request.
Expand Down Expand Up @@ -105,5 +105,5 @@ Feature reference
/reference/environment-variables
/security-log
/server-side-search/index
/single-version
/versioning-schemes
/science
39 changes: 0 additions & 39 deletions docs/user/single-version.rst

This file was deleted.

66 changes: 66 additions & 0 deletions docs/user/versioning-schemes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Versioning schemes
==================

The versioning scheme of your project defines the URL of your documentation,
and if your project supports multiple versions or translations.

Read the Docs supports three different versioning schemes:

- `Multiple versions with translations`_.
- `Multiple versions without translations`_.
- `Single version without translations`_.

.. seealso::

:doc:`/guides/setup/versioning-schemes`
How to configure your project to use a specific versioning scheme.

:doc:`/versions`
General explanation of how versioning works on Read the Docs.

Multiple versions with translations
-----------------------------------

This is the default versioning scheme, it's the recommend one if your project has multiple versions,
and has or plans to support translations.

The URLs of your documentation will look like:

- ``/en/latest/``
- ``/en/1.5/``
- ``/es/latest/install.html``
- ``/es/1.5/contributing.html``

Multiple versions without translations
--------------------------------------

Use this versioning scheme if you want to have multiple versions of your documentation,
but don't want to have translations.

The URLs of your documentation will look like:

- ``/latest/``
- ``/1.5/install.html``

.. warning::

This means you can't have translations for your documentation.

Single version without translations
-----------------------------------

Having a single version of a documentation project can be considered the better choice
in cases where there should only always exist one unambiguous copy of your project.
For example:

- A research project may wish to *only* expose readers to their latest list of publications and research data.
- A :abbr:`SaaS (Software as a Service)` application might only ever have one version live.

The URLs of your documentation will look like:

- ``/``
- ``/install.html``

.. warning::

This means you can't have translations or multiple versions for your documentation.
2 changes: 1 addition & 1 deletion readthedocs/api/v2/templates/restapi/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

</dl>
{% endif %}
{% if not project.single_version and versions|length >= 1 %}
{% if project.supports_multiple_versions and versions|length >= 1 %}
<dl>
<dt>{% trans "Versions" %}</dt>
{% for version in versions %}
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/api/v3/tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def test_update_project(self):
self.assertEqual(self.project.show_version_warning, False)
self.assertEqual(self.project.is_single_version, True)
self.assertEqual(self.project.external_builds_enabled, True)
self.assertEqual(
self.project.versioning_scheme, SINGLE_VERSION_WITHOUT_TRANSLATIONS
)

def test_partial_update_project(self):
data = {
Expand Down
21 changes: 13 additions & 8 deletions readthedocs/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

from readthedocs.builds.constants import EXTERNAL, INTERNAL
from readthedocs.core.utils.url import unsafe_join_url_path
from readthedocs.projects.constants import (
MULTIPLE_VERSIONS_WITHOUT_TRANSLATIONS,
SINGLE_VERSION_WITHOUT_TRANSLATIONS,
)
from readthedocs.subscriptions.constants import TYPE_CNAME
from readthedocs.subscriptions.products import get_feature

Expand Down Expand Up @@ -59,7 +63,7 @@ def base_resolve_path(
filename,
version_slug=None,
language=None,
single_version=None,
versioning_scheme=None,
project_relationship=None,
custom_prefix=None,
):
Expand All @@ -83,8 +87,10 @@ def base_resolve_path(
if custom_prefix:
path = unsafe_join_url_path(path, custom_prefix)

if single_version:
if versioning_scheme == SINGLE_VERSION_WITHOUT_TRANSLATIONS:
path = unsafe_join_url_path(path, "{filename}")
elif versioning_scheme == MULTIPLE_VERSIONS_WITHOUT_TRANSLATIONS:
path = unsafe_join_url_path(path, "{version}/{filename}")
else:
path = unsafe_join_url_path(path, "{language}/{version}/{filename}")

Expand All @@ -102,7 +108,6 @@ def resolve_path(
filename="",
version_slug=None,
language=None,
single_version=None,
):
"""Resolve a URL with a subset of fields defined."""
version_slug = version_slug or project.get_default_version()
Expand All @@ -111,22 +116,23 @@ def resolve_path(
filename = self._fix_filename(filename)

parent_project, project_relationship = self._get_canonical_project(project)
single_version = bool(project.is_single_version or single_version)

# If the project is a subproject, we use the custom prefix
# If the project is a subproject, we use the custom prefix and versioning scheme
# of the child of the relationship, this is since the project
# could be a translation. For a project that isn't a subproject,
# we use the custom prefix of the parent project.
# we use the custom prefix and versioning scheme of the parent project.
if project_relationship:
custom_prefix = project_relationship.child.custom_prefix
versioning_scheme = project_relationship.child.versioning_scheme
else:
custom_prefix = parent_project.custom_prefix
versioning_scheme = parent_project.versioning_scheme

return self.base_resolve_path(
filename=filename,
version_slug=version_slug,
language=language,
single_version=single_version,
versioning_scheme=versioning_scheme,
project_relationship=project_relationship,
custom_prefix=custom_prefix,
)
Expand All @@ -152,7 +158,6 @@ def resolve_version(self, project, version=None, filename="/"):
filename=filename,
version_slug=version.slug,
language=project.language,
single_version=project.single_version,
)
protocol = "https" if use_https else "http"
return urlunparse((protocol, domain, path, "", "", ""))
Expand Down
Loading

0 comments on commit 25d3d29

Please sign in to comment.