Skip to content

Commit 65fdf7c

Browse files
authored
Correct documentation URL issues (boostorg#1975)
1 parent f65a5c7 commit 65fdf7c

File tree

10 files changed

+71
-11
lines changed

10 files changed

+71
-11
lines changed

docs/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Import `VersionFile` objects from Artifactory.
137137
**Example**
138138

139139
```bash
140-
./manage.py get_library_version_documentation_urls --version=1.81.0
140+
./manage.py import_library_version_docs_urls --version=1.81.0
141141
```
142142

143143
**Options**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 4.2.24 on 2025-10-16 23:31
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("libraries", "0033_libraryversion_cpp20_module_support"),
10+
]
11+
12+
operations = [
13+
migrations.RunSQL(
14+
sql="UPDATE libraries_libraryversion SET documentation_url = REPLACE(documentation_url, '/boost_', '/') WHERE documentation_url LIKE '%/boost_%';",
15+
reverse_sql="UPDATE libraries_libraryversion SET documentation_url = REPLACE(documentation_url, '/doc/libs/', '/doc/libs/boost_') WHERE documentation_url LIKE '/doc/libs/[0-9]%';",
16+
),
17+
]

libraries/tasks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def get_and_store_library_version_documentation_urls_for_version(version_pk):
6060
return
6161

6262
base_path = f"doc/libs/{version.boost_url_slug}/libs/"
63+
boost_stripped_base_path = base_path.replace("doc/libs/boost_", "doc/libs/")
6364
key = f"{base_path}libraries.htm"
6465
result = get_content_from_s3(key)
6566

@@ -74,7 +75,7 @@ def get_and_store_library_version_documentation_urls_for_version(version_pk):
7475
try:
7576
# In most cases, the name matches close enough to get the correct object
7677
library_version = library_versions.get(library__name__iexact=library_name)
77-
library_version.documentation_url = f"/{base_path}{url_path}"
78+
library_version.documentation_url = f"/{boost_stripped_base_path}{url_path}"
7879
library_version.save()
7980
except LibraryVersion.DoesNotExist:
8081
logger.info(
@@ -131,7 +132,9 @@ def get_and_store_library_version_documentation_urls_for_version(version_pk):
131132
content = get_content_from_s3(key[0])
132133

133134
if content:
134-
library_version.documentation_url = documentation_url
135+
library_version.documentation_url = documentation_url.replace(
136+
"doc/libs/boost_", "doc/libs/"
137+
)
135138
library_version.save()
136139
else:
137140
logger.info(f"No valid docs in S3 for key {documentation_url}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
from django import template
3+
4+
register = template.Library()
5+
6+
7+
@register.simple_tag
8+
def doc_url_with_latest(documentation_url, version_str, latest_str):
9+
"""
10+
Replace the version segment in a documentation URL with the latest string.
11+
Only replaces if version_str matches latest_str.
12+
13+
Usage: {% doc_url_with_latest library_version.documentation_url version_str LATEST_RELEASE_URL_PATH_STR %}
14+
Example: /doc/libs/1_89_0/libs/accumulators/index.html -> /doc/libs/latest/libs/accumulators/index.html
15+
"""
16+
if not documentation_url or version_str != latest_str:
17+
return documentation_url
18+
19+
# Pattern matches /doc/libs/{version}/ where version is typically digits/underscores
20+
return re.sub(r"(doc/libs/)([^/]+)(\S+)", rf"\1{latest_str}\3", documentation_url)

libraries/tests/test_tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ def test_get_and_store_library_version_documentation_urls_for_version(
4242
# Refresh the library_version object from the database
4343
library_version.refresh_from_db()
4444
# Assert that the docs_path was updated as expected
45+
slug = version.boost_url_slug.replace("boost_", "")
4546
assert (
4647
library_version.documentation_url
47-
== f"/doc/libs/{version.boost_url_slug}/libs/{library_name}/index.html"
48+
== f"/doc/libs/{slug}/libs/{library_name}/index.html"
4849
)
4950

5051

libraries/tests/test_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_library_detail_context_get_documentation_url_no_docs_link(
249249
response = tp.get(url)
250250
tp.response_200(response)
251251
assert "documentation_url" in response.context
252-
assert response.context["documentation_url"] == "/doc/libs/1_79_0"
252+
assert response.context["documentation_url"] is None
253253

254254

255255
def test_library_detail_context_get_documentation_url_missing_docs_bool(
@@ -267,7 +267,7 @@ def test_library_detail_context_get_documentation_url_missing_docs_bool(
267267
response = tp.get(url)
268268
tp.response_200(response)
269269
assert "documentation_url" in response.context
270-
assert response.context["documentation_url"] == "/doc/libs/1_79_0"
270+
assert response.context["documentation_url"] is None
271271

272272

273273
def test_library_detail_context_get_documentation_url_docs_present(

libraries/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ def generate_canonical_library_uri(uri):
193193

194194

195195
def get_documentation_url(library_version, latest):
196+
url = library_version.documentation_url
197+
if url and latest:
198+
url = library_doc_latest_transform(url)
199+
return url
200+
201+
202+
def get_documentation_url_redirect(library_version, latest):
196203
"""Get the documentation URL for the current library."""
197204

198205
def find_documentation_url(library_version):

libraries/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
determine_selected_boost_version,
3333
set_selected_boost_version,
3434
get_documentation_url,
35+
get_documentation_url_redirect,
3536
get_prioritized_version,
3637
get_version_from_cookie,
3738
)
@@ -337,7 +338,9 @@ def dispatch(self, request, *args, **kwargs):
337338
library_slug=self.kwargs.get("library_slug"),
338339
version_slug=get_prioritized_version(request),
339340
)
340-
return redirect(get_documentation_url(library_version, latest=False))
341+
return redirect(
342+
get_documentation_url_redirect(library_version, latest=False)
343+
)
341344
response = super().dispatch(request, *args, **kwargs)
342345
set_selected_boost_version(
343346
self.kwargs.get("version_slug", LATEST_RELEASE_URL_PATH_STR), response

templates/libraries/detail.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@
7070
<a class="block items-center py-1 px-2 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange"
7171
href="{{ documentation_url }}">
7272
<span class="dark:text-white text-slate">Documentation</span>
73-
<span class="block text-xs break-words text-wrap whitespace-pre-line mb-2">{{ request.get_host }}{{ documentation_url|cut:"https://" }}</span>
73+
<span class="block text-xs break-words text-wrap whitespace-pre-line mb-2">{{ request.get_host }}{{ documentation_url|cut:"https://" }}</span>
7474
</a>
75+
{% else %}
76+
<div class="block items-center py-1 px-2 rounded">
77+
<span class="dark:text-white text-slate">Documentation</span>
78+
<span class="block text-xs break-words text-wrap whitespace-pre-line mb-2">No documentation for this version</span>
79+
</div>
7580
{% endif %}
7681
</div>
7782
<div class="-ml-2 min-h-16">
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
<a class="text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange text-base block py-3 text-center" href="{{ library_version.documentation_url }}" title="Documentation">
2-
<i class="fa fa-book align-top"></i>
3-
</a>
1+
{% load doc_url_with_latest %}
2+
3+
{% if library_version.documentation_url %}
4+
<a class="text-sky-600 dark:text-sky-300 hover:text-orange dark:hover:text-orange text-base block py-3 text-center" href="{% doc_url_with_latest library_version.documentation_url version_str LATEST_RELEASE_URL_PATH_STR %}" title="Documentation">
5+
<i class="fa fa-book align-top"></i>
6+
</a>
7+
{% endif %}

0 commit comments

Comments
 (0)