Skip to content

Commit 91fdbd6

Browse files
committed
fix: add missing SITEURL interpolation to support relative path deployment
1 parent aa95e38 commit 91fdbd6

15 files changed

Lines changed: 83 additions & 29 deletions

File tree

pelicanconf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
]
8686

8787
PLUGINS = [
88+
"auto_siteurl",
8889
"author_metadata",
8990
"download_metadata",
9091
"draft_override",

plugins/auto_siteurl/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .auto_siteurl import register
2+
3+
__all__ = ["register"]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
auto_siteurl — Automatically prefix root-absolute paths in content with SITEURL.
3+
4+
When deployed at a subpath (e.g. https://example.com/pr/428), root-absolute
5+
paths like href="/download" break because they resolve to the domain root
6+
instead of the subpath. This plugin prepends SITEURL so they become
7+
href="https://example.com/pr/428/download".
8+
9+
Scope — what this plugin covers:
10+
- href and src attributes in rendered article/page content (the HTML
11+
generated from .md files). This avoids having to patch every content
12+
file with {filename} syntax.
13+
14+
What this plugin does NOT cover (handled separately):
15+
- Template files (*.html under theme/templates/): these use Jinja2
16+
directly and need explicit {{ SITEURL }} interpolation at the point
17+
of use (e.g. href="{{ SITEURL }}/path").
18+
- Static CSS files (*.css under theme/static/): these are not processed
19+
by Pelican at all. Use CSS-relative paths instead (e.g. url('../images/')
20+
rather than url('/theme/images/')).
21+
- feed.xml: generated by Pelican's feed writer, which constructs URLs
22+
independently of the content pipeline.
23+
"""
24+
25+
import re
26+
import logging
27+
from pelican import signals
28+
29+
logger = logging.getLogger(__name__)
30+
31+
32+
def prefix_absolute_paths(content_object):
33+
siteurl = content_object.settings.get("SITEURL", "")
34+
if not siteurl:
35+
return
36+
37+
if not hasattr(content_object, "_content") or not content_object._content:
38+
return
39+
40+
# Replace href="/path" → href="SITEURL/path" and src="/path" → src="SITEURL/path".
41+
# The negative lookahead (?!/) skips protocol-relative URLs like //cdn.example.com.
42+
content_object._content = re.sub(
43+
r'(href|src)="/(?!/)',
44+
lambda m: f'{m.group(1)}="{siteurl}/',
45+
content_object._content,
46+
)
47+
48+
49+
def register():
50+
signals.content_object_init.connect(prefix_absolute_paths)

theme/static/css/custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ html.transition-theme *:after {
5757
max-width: 384px;
5858
height: auto;
5959
float: right;
60-
shape-outside: url('/theme/images/ev/umbrella.png');
60+
shape-outside: url('../images/ev/umbrella.png');
6161
shape-margin: 2rem;
6262
margin-left: 2rem;
6363
margin-top: 60px;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#hardware.cover-bg {
2-
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('/theme/images/cover/hardware-bg.jpg');
2+
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('../../images/cover/hardware-bg.jpg');
33
}
44

55
#library.cover-bg {
6-
background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('/theme/images/cover/library-bg.jpg');
6+
background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('../../images/cover/library-bg.jpg');
77
}
88

99
#broadcast.cover-bg {
10-
background-image: url('/theme/images/cover/broadcast-bg.jpg');
10+
background-image: url('../../images/cover/broadcast-bg.jpg');
1111
}

theme/static/css/pages/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.splash.cover-bg {
2-
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.9)), url('/theme/images/cover/splash-bg.jpg');
2+
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.9)), url('../../images/cover/splash-bg.jpg');
33
}
44

55
.splash .splash-logo {
@@ -28,5 +28,5 @@
2828
}
2929

3030
#opensource.cover-bg {
31-
background-image: url('/theme/images/cover/code-bg.jpg');
31+
background-image: url('../../images/cover/code-bg.jpg');
3232
}

theme/templates/article.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1>{{ article.title }}</h1>
4848
{% if article.authors %}
4949
<div class="docs-section author-box">
5050
{% for author in article.authors %}
51-
{{ utils.author_box(author) }}
51+
{{ utils.author_box(author, siteurl=SITEURL) }}
5252
{% endfor %}
5353
</div>
5454
{% endif %}

theme/templates/author.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
{% block extra_content %}
99
<div class="docs-section author-box">
10-
{{ utils.author_box(author, more_button=False) }}
10+
{{ utils.author_box(author, more_button=False, siteurl=SITEURL) }}
1111
</div>
1212
{% endblock %}

theme/templates/navbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<ul class="navbar-list navbar-hamburger-content">
1212
{% for item in NAV_MENU %}
1313
<li class="navbar-item{% if item.css %} {{ item.css }}{% endif %} {% if item.children %}has-dropdown{% endif %}">
14-
<a class="navbar-link" href="{{ item.url }}">{{ item.title|replace(" ", "&nbsp;") }}</a>
14+
<a class="navbar-link" href="{{ SITEURL }}{{ item.url }}">{{ item.title|replace(" ", "&nbsp;") }}</a>
1515
{% if item.children %}
1616
<ul class="navbar-list navbar-dropdown">
1717
{% for child in item.children %}
1818
<li class="navbar-item{% if child.css %} {{ child.css }}{% endif %}">
19-
<a class="navbar-link" href="{{ child.url }}">{{ child.title|replace(" ", "&nbsp;") }}</a>
19+
<a class="navbar-link" href="{{ SITEURL }}{{ child.url }}">{{ child.title|replace(" ", "&nbsp;") }}</a>
2020
</li>
2121
{% endfor %}
2222
</ul>

theme/templates/pages/contact.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div id="get-in-touch" class="docs-section container">
77
<h1><a class="headline-link" href="#get-in-touch">{% trans %}Get in Touch{% endtrans %}</a></h1>
88
<p>
9-
{% with support_page_link="/support", bug_tracker_link="https://github.com/mixxxdj/mixxx/issues/", zulip_web_link="https://mixxx.zulipchat.com/" %}{% trans %}Please refer to the <a href="{{ support_page_link }}">Support page</a> if you need help setting up or using Mixxx. If you think you've found a bug, please file a bug report in our <a href="{{ bug_tracker_link }}">bug tracker</a>. If you would like to get in touch with Mixxx developers, <a href="{{ zulip_web_link }}">Zulip</a> is the best way to reach us.{% endtrans %}{% endwith %}
9+
{% with support_page_link="/support", bug_tracker_link="https://github.com/mixxxdj/mixxx/issues/", zulip_web_link="https://mixxx.zulipchat.com/" %}{% trans %}Please refer to the <a href="{{ SITEURL }}{{ support_page_link }}">Support page</a> if you need help setting up or using Mixxx. If you think you've found a bug, please file a bug report in our <a href="{{ bug_tracker_link }}">bug tracker</a>. If you would like to get in touch with Mixxx developers, <a href="{{ zulip_web_link }}">Zulip</a> is the best way to reach us.{% endtrans %}{% endwith %}
1010
</p>
1111
<p>
1212
{% with project_manager_link="mailto:hardware@mixxx.org" %}{% trans %}If you're a DJ hardware manufacturer and would like your product to work with Mixxx, please contact us at, <a href="{{ project_manager_link }}">hardware@mixxx.org</a>. We accept donations and loans of DJ equipment which we use to improve both specific and general hardware support in Mixxx.{% endtrans %}{% endwith %}

0 commit comments

Comments
 (0)