From e3a057120a07965be302c6db5b79ac92e50b0b65 Mon Sep 17 00:00:00 2001 From: Greg Kaleka Date: Mon, 19 May 2025 15:13:22 -0400 Subject: [PATCH] Docs fixes and fix bug in library import (#1788) --- config/settings.py | 2 + core/views.py | 77 +++++++++++++++++++ libraries/constants.py | 2 +- .../commands/import_library_versions.py | 5 +- templates/docsiframe.html | 1 - .../_library_categorized_list_item.html | 6 +- .../libraries/_library_grid_list_item.html | 4 +- .../_library_vertical_list_item.html | 6 +- .../includes/_documentation_link_icon.html | 3 + templates/original_docs.html | 14 ++-- versions/tasks.py | 4 +- 11 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 templates/libraries/includes/_documentation_link_icon.html diff --git a/config/settings.py b/config/settings.py index 10240de1..0dde0697 100755 --- a/config/settings.py +++ b/config/settings.py @@ -562,3 +562,5 @@ if DEBUG_TOOLBAR: "ROOT_TAG_EXTRA_ATTRS": "hx-preserve", } MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware") + +BOOST_BRANCHES = ["master", "develop"] diff --git a/core/views.py b/core/views.py index 5cd3f3ab..2cff9f6d 100644 --- a/core/views.py +++ b/core/views.py @@ -39,6 +39,7 @@ from .htmlhelper import ( convert_name_to_id, modernize_preprocessor_docs, slightly_modernize_legacy_library_doc_page, + remove_library_boostlook, ) from .markdown import process_md from .models import RenderedContent @@ -497,6 +498,13 @@ NO_WRAPPER_LIBS = [ "libs/variant2", ] +FULLY_MODERNIZED_LIB_VERSIONS = [ + # FIXME: we should have a way to opt-in via a flag on the library/lib-version. + # Hard-coding these here as a quick fix for now. + "boost_1_87_0/libs/charconv", + "boost_1_88_0/libs/charconv", +] + class DocLibsTemplateView(BaseStaticContentTemplateView): def get_from_s3(self, content_path): @@ -506,6 +514,12 @@ class DocLibsTemplateView(BaseStaticContentTemplateView): def process_content(self, content): """Replace page header with the local one.""" + if any( + lib_slug in self.request.path for lib_slug in FULLY_MODERNIZED_LIB_VERSIONS + ): + # Return a fully modernized version in an iframe + return self._fully_modernize_content(content) + if any(lib_slug in self.request.path for lib_slug in NO_PROCESS_LIBS): # Just render raw HTML for some pages return content @@ -527,6 +541,69 @@ class DocLibsTemplateView(BaseStaticContentTemplateView): return render_to_string("original_docs.html", context, request=self.request) + def _fully_modernize_content(self, content): + """For libraries that have opted in to boostlook modernization""" + content_type = self.content_dict.get("content_type") + source_content_type = self.content_dict.get("source_content_type") + if ( + source_content_type is None + and SourceDocType.ANTORA.value in self.request.path + ): + # hacky, but solves an edge case + source_content_type = SourceDocType.ANTORA + # Is the request coming from an iframe? If so, let's disable the modernization. + sec_fetch_destination = self.request.headers.get("Sec-Fetch-Dest", "") + is_iframe_destination = sec_fetch_destination in ["iframe", "frame"] + + modernize = self.request.GET.get("modernize", "med").lower() + + if ( + ("text/html" or "text/html; charset=utf-8") not in content_type + or modernize not in ("max", "med", "min") + or is_iframe_destination + ): + # eventually check for more things, for example ensure this HTML + # was not generate from Antora builders. + return content + + context = {"disable_theme_switcher": False} + insert_body = modernize == "max" + head_selector = ( + "head" + if modernize in ("max", "med") + else {"data-modernizer": "boost-legacy-docs-extra-head"} + ) + + context["hide_footer"] = True + if source_content_type == SourceDocType.ASCIIDOC: + extracted_content = content.decode(chardet.detect(content)["encoding"]) + soup = BeautifulSoup(extracted_content, "html.parser") + soup = convert_name_to_id(soup) + soup = remove_library_boostlook(soup) + soup.find("head").append( + soup.new_tag("script", src=f"{settings.STATIC_URL}js/theme_handling.js") + ) + context["content"] = soup.prettify() + else: + # Potentially pass version if needed for HTML modification. + # We disable plausible to prevent redundant 'about:srcdoc' tracking, + # tracking is covered by docsiframe.html + base_html = render_to_string( + "docs_libs_placeholder.html", + {**context, **{"disable_plausible": True}}, + request=self.request, + ) + context["content"] = modernize_legacy_page( + content, + base_html, + insert_body=insert_body, + head_selector=head_selector, + original_docs_type=source_content_type, + show_footer=False, + show_navbar=False, + ) + return render_to_string("docsiframe.html", context, request=self.request) + class UserGuideTemplateView(BaseStaticContentTemplateView): def get_from_s3(self, content_path): diff --git a/libraries/constants.py b/libraries/constants.py index 3fc31902..21a8406b 100644 --- a/libraries/constants.py +++ b/libraries/constants.py @@ -22,7 +22,7 @@ from .constants_utils import ( generate_library_docs_url_utility_anchor, ) -# Mapping for exeptions to loading URLs for older docs. +# Mapping for exceptions to loading URLs for older docs. # key: Taken from Library.slug # value: List of dictionaries with instructions for how to format docs URLs for # those library-versions diff --git a/libraries/management/commands/import_library_versions.py b/libraries/management/commands/import_library_versions.py index 4cfe750d..c679326e 100644 --- a/libraries/management/commands/import_library_versions.py +++ b/libraries/management/commands/import_library_versions.py @@ -42,7 +42,10 @@ def command(min_release: str, release: str, token: str): ) for version in versions.order_by("-name"): + version_type = "branch" if version.slug in settings.BOOST_BRANCHES else "tag" click.secho(f"Saving libraries for version {version.name}", fg="green") - import_library_versions.delay(version.name, token=token) + import_library_versions.delay( + version.name, token=token, version_type=version_type + ) click.secho("Finished saving library-version relationships.", fg="green") diff --git a/templates/docsiframe.html b/templates/docsiframe.html index 83518e39..35179f84 100644 --- a/templates/docsiframe.html +++ b/templates/docsiframe.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% block main_content_wrapper %}
{% endblock %} {% block content %}