Skip to content

Commit e3a0571

Browse files
authored
Docs fixes and fix bug in library import (#1788)
1 parent f7d1694 commit e3a0571

File tree

11 files changed

+102
-22
lines changed

11 files changed

+102
-22
lines changed

config/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,5 @@
562562
"ROOT_TAG_EXTRA_ATTRS": "hx-preserve",
563563
}
564564
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
565+
566+
BOOST_BRANCHES = ["master", "develop"]

core/views.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
convert_name_to_id,
4040
modernize_preprocessor_docs,
4141
slightly_modernize_legacy_library_doc_page,
42+
remove_library_boostlook,
4243
)
4344
from .markdown import process_md
4445
from .models import RenderedContent
@@ -497,6 +498,13 @@ def normalize_boost_doc_path(content_path: str) -> str:
497498
"libs/variant2",
498499
]
499500

501+
FULLY_MODERNIZED_LIB_VERSIONS = [
502+
# FIXME: we should have a way to opt-in via a flag on the library/lib-version.
503+
# Hard-coding these here as a quick fix for now.
504+
"boost_1_87_0/libs/charconv",
505+
"boost_1_88_0/libs/charconv",
506+
]
507+
500508

501509
class DocLibsTemplateView(BaseStaticContentTemplateView):
502510
def get_from_s3(self, content_path):
@@ -506,6 +514,12 @@ def get_from_s3(self, content_path):
506514
def process_content(self, content):
507515
"""Replace page header with the local one."""
508516

517+
if any(
518+
lib_slug in self.request.path for lib_slug in FULLY_MODERNIZED_LIB_VERSIONS
519+
):
520+
# Return a fully modernized version in an iframe
521+
return self._fully_modernize_content(content)
522+
509523
if any(lib_slug in self.request.path for lib_slug in NO_PROCESS_LIBS):
510524
# Just render raw HTML for some pages
511525
return content
@@ -527,6 +541,69 @@ def process_content(self, content):
527541

528542
return render_to_string("original_docs.html", context, request=self.request)
529543

544+
def _fully_modernize_content(self, content):
545+
"""For libraries that have opted in to boostlook modernization"""
546+
content_type = self.content_dict.get("content_type")
547+
source_content_type = self.content_dict.get("source_content_type")
548+
if (
549+
source_content_type is None
550+
and SourceDocType.ANTORA.value in self.request.path
551+
):
552+
# hacky, but solves an edge case
553+
source_content_type = SourceDocType.ANTORA
554+
# Is the request coming from an iframe? If so, let's disable the modernization.
555+
sec_fetch_destination = self.request.headers.get("Sec-Fetch-Dest", "")
556+
is_iframe_destination = sec_fetch_destination in ["iframe", "frame"]
557+
558+
modernize = self.request.GET.get("modernize", "med").lower()
559+
560+
if (
561+
("text/html" or "text/html; charset=utf-8") not in content_type
562+
or modernize not in ("max", "med", "min")
563+
or is_iframe_destination
564+
):
565+
# eventually check for more things, for example ensure this HTML
566+
# was not generate from Antora builders.
567+
return content
568+
569+
context = {"disable_theme_switcher": False}
570+
insert_body = modernize == "max"
571+
head_selector = (
572+
"head"
573+
if modernize in ("max", "med")
574+
else {"data-modernizer": "boost-legacy-docs-extra-head"}
575+
)
576+
577+
context["hide_footer"] = True
578+
if source_content_type == SourceDocType.ASCIIDOC:
579+
extracted_content = content.decode(chardet.detect(content)["encoding"])
580+
soup = BeautifulSoup(extracted_content, "html.parser")
581+
soup = convert_name_to_id(soup)
582+
soup = remove_library_boostlook(soup)
583+
soup.find("head").append(
584+
soup.new_tag("script", src=f"{settings.STATIC_URL}js/theme_handling.js")
585+
)
586+
context["content"] = soup.prettify()
587+
else:
588+
# Potentially pass version if needed for HTML modification.
589+
# We disable plausible to prevent redundant 'about:srcdoc' tracking,
590+
# tracking is covered by docsiframe.html
591+
base_html = render_to_string(
592+
"docs_libs_placeholder.html",
593+
{**context, **{"disable_plausible": True}},
594+
request=self.request,
595+
)
596+
context["content"] = modernize_legacy_page(
597+
content,
598+
base_html,
599+
insert_body=insert_body,
600+
head_selector=head_selector,
601+
original_docs_type=source_content_type,
602+
show_footer=False,
603+
show_navbar=False,
604+
)
605+
return render_to_string("docsiframe.html", context, request=self.request)
606+
530607

531608
class UserGuideTemplateView(BaseStaticContentTemplateView):
532609
def get_from_s3(self, content_path):

libraries/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
generate_library_docs_url_utility_anchor,
2323
)
2424

25-
# Mapping for exeptions to loading URLs for older docs.
25+
# Mapping for exceptions to loading URLs for older docs.
2626
# key: Taken from Library.slug
2727
# value: List of dictionaries with instructions for how to format docs URLs for
2828
# those library-versions

libraries/management/commands/import_library_versions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def command(min_release: str, release: str, token: str):
4242
)
4343

4444
for version in versions.order_by("-name"):
45+
version_type = "branch" if version.slug in settings.BOOST_BRANCHES else "tag"
4546
click.secho(f"Saving libraries for version {version.name}", fg="green")
46-
import_library_versions.delay(version.name, token=token)
47+
import_library_versions.delay(
48+
version.name, token=token, version_type=version_type
49+
)
4750

4851
click.secho("Finished saving library-version relationships.", fg="green")

templates/docsiframe.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{% extends "base.html" %}
2-
{% block main_content_wrapper %}<div class="md:px-3 mx-auto transition-all">{% endblock %}
32
{% block content %}
43
<iframe
54
{% if iframe_url %}

templates/libraries/_library_categorized_list_item.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
{% if library_version.cpp_standard_minimum and library_version.cpp_standard_minimum != 'None' %}{{ library_version.cpp_standard_minimum }}{% else %}03{% endif %}
1414
</span>
1515
</td>
16-
<td class="py-3 pr-2 align-top">
17-
<a class="text-sky-600 dark:text-sky-300 text-base" href="{{ library_version.documentation_url }}" title="Documentation">
18-
<i class="fa fa-book icon-link"></i>
19-
</a>
16+
<td class="align-top">
17+
{% include "libraries/includes/_documentation_link_icon.html" %}
2018
</td>
2119
<td class="hidden md:block py-2 pl-3 align-top">{{ library_version.description|default:"No description provide for this version." }}</td>
2220
</tr>

templates/libraries/_library_grid_list_item.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
<h3 class="pb-2 text-xl md:text-2xl capitalize border-b border-gray-700">
88
<div class="flex justify-between">
99
<a class="link-header" href="{% url 'library-detail' library_slug=library_version.library.slug version_slug=version_str %}">{{ library_version.library.name }}</a>
10-
<a class="text-sky-600 dark:text-sky-300 text-base" href="{{ library_version.documentation_url }}" title="Documentation">
11-
<i class="fa fa-book icon-link"></i>
12-
</a>
10+
{% include "libraries/includes/_documentation_link_icon.html" %}
1311
</div>
1412
{% for author in library.authors.all %}
1513
{% if author.image %}

templates/libraries/_library_vertical_list_item.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
{% if library_version.cpp_standard_minimum and library_version.cpp_standard_minimum != 'None' %}{{ library_version.cpp_standard_minimum }}{% else %}03{% endif %}
1313
</span>
1414
</td>
15-
<td class="py-3 pr-2 align-top">
16-
<a class="text-sky-600 dark:text-sky-300 text-base" href="{{ library_version.documentation_url }}" title="Documentation">
17-
<i class="fa fa-book icon-link"></i>
18-
</a>
15+
<td class="align-top">
16+
{% include "libraries/includes/_documentation_link_icon.html" %}
1917
</td>
2018
<td class="hidden md:block py-2 pl-3 align-top">{{ library_version.description|default:"No description provide for this version." }}</td>
2119
</tr>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<a class="text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange text-base block py-3 pr-2" href="{{ library_version.documentation_url }}" title="Documentation">
2+
<i class="fa fa-book icon-link"></i>
3+
</a>

templates/original_docs.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
<script src="{% static 'js/boost-gecko/main.eb9cabc5.js' %}" defer></script>
1010
</head>
1111
<style>
12-
/*
13-
Copyright 2005-2006 Redshift Software, Inc.
14-
Distributed under the Boost Software License, Version 1.0.
15-
(See accompanying file LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt)
16-
*/
17-
1812
body {
1913
margin-top: 0;
2014
}
@@ -41,6 +35,10 @@
4135
margin: 18px 0px 0px 24px;
4236
}
4337

38+
39+
#injected-header * {
40+
color: #000;
41+
}
4442
/* Links in the header. */
4543
#boost-common-heading-doc .heading-quote a,
4644
#heading .heading-quote a {
@@ -220,11 +218,15 @@
220218
</style>
221219

222220
{% if no_wrapper %}
221+
<div id="injected-header">
223222
{% include "includes/_legacy_docs_header.html" %}
223+
</div>
224224
{{ content|safe }}
225225
{% else %}
226226
<body style="margin: 0; padding: 0; max-width: unset;">
227+
<div id="injected-header">
227228
{% include "includes/_legacy_docs_header.html" %}
229+
</div>
228230
<div style="margin: 1em;">
229231
{{ content|safe }}
230232
</div>

versions/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.conf import settings
99
from django.core.management import call_command
1010
from fastcore.xtras import obj2dict
11+
1112
from core.githubhelper import GithubAPIClient, GithubDataParser
1213
from libraries.constants import SKIP_LIBRARY_VERSIONS
1314
from libraries.github import LibraryUpdater
@@ -160,10 +161,9 @@ def import_version(
160161
@app.task
161162
def import_development_versions():
162163
"""Imports the `master` and `develop` branches as Versions"""
163-
branches = ["master", "develop"]
164164
base_url = "https://github.com/boostorg/boost/tree/"
165165

166-
for branch in branches:
166+
for branch in settings.BOOST_BRANCHES:
167167
import_version.delay(
168168
branch,
169169
branch,

0 commit comments

Comments
 (0)