Skip to content

Commit bedd36f

Browse files
committed
PR feedback: trailing slash footgun avoidance, clean up example
1 parent a8be871 commit bedd36f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

core/templatetags/custom_static.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ def large_static(file_path: str):
1414
"""
1515
# Strip any leading slashes to avoid footguns
1616
file_path = file_path.lstrip("/")
17+
18+
# Strip any trailing slashes to avoid assumptions
19+
static_url = settings.STATIC_URL.rstrip("/")
20+
static_aws_endpoint = settings.STATIC_CONTENT_AWS_S3_ENDPOINT_URL.rstrip("/")
21+
1722
if settings.LOCAL_DEVELOPMENT:
18-
return f"{settings.STATIC_URL}static-large/{file_path}"
23+
return f"{static_url}/static-large/{file_path}"
1924
else:
20-
return f"{settings.STATIC_CONTENT_AWS_S3_ENDPOINT_URL}/{settings.STATIC_CONTENT_BUCKET_NAME}/static/{file_path}"
25+
return f"{static_aws_endpoint}/{settings.STATIC_CONTENT_BUCKET_NAME}/static/{file_path}"

templates/v3/examples/_v3_example_section.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load custom_static %}
12
{% comment %}
23
V3 Component Demo Page
34
======================
@@ -722,12 +723,10 @@ <h3>{{ section_title }}</h3>
722723
{% endwith %}
723724

724725
{% with section_title="Image Handling Example" %}
725-
{% load custom_static %}
726726
<div class="v3-examples-section__block" id="{{ section_title|slugify }}">
727727
<h3>{{ section_title }}</h3>
728728
<div class="v3-examples-section__example-box">
729-
{% large_static '/img/v3/learn-page/Learn_Octopus.png' as img_url %}
730-
<img src="{{img_url}}" />
729+
<img src="{% large_static 'img/v3/learn-page/Learn_Octopus.png' %}" alt="Large Media Example" />
731730
</div>
732731
</div>
733732
{% endwith %}

0 commit comments

Comments
 (0)