Skip to content

Commit

Permalink
feat: pass URLs through CDN (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
M7mdisk authored Jul 25, 2024
1 parent 69968a9 commit 289cf15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion templates/docs/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h4 class="p-table-of-contents__header">On this page</h4>
<div class="l-docs__main u-text-max-width">
<main class="u-fixed-width">
<div class="p-strip is-shallow" style="overflow: visible;">
{{ document.body_html | safe }}
{{ document.body_html | safe | serve_assets }}
</div>
<div class="p-notification--information">
<div class="p-notification__content">
Expand Down
17 changes: 17 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,20 @@ def inject_utilities():
@app.context_processor
def inject_today_date():
return {"current_year": datetime.date.today().year}


S3_BUCKET_URL = "https://discourse-charmhub-io.s3.eu-west-2.amazonaws.com"
CDN_PREFIX = "https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto/"


@app.template_filter("serve_assets")
def serve_assets(text):
"""
This is a template filter that prefixes assets with the CDN so that they are serves through it.
Purpose:
This is partially a workaround for the fact that google chrome flags the S3 bucket URL as a lookalike for charmhub.io and prompts the user to visit the latter.
# noqa: E501
"""

return text.replace(S3_BUCKET_URL, CDN_PREFIX + S3_BUCKET_URL)

0 comments on commit 289cf15

Please sign in to comment.