Skip to content

Commit

Permalink
404: Fix PR URLs on readthedocs.build domain
Browse files Browse the repository at this point in the history
  • Loading branch information
adriendupuis committed Jun 26, 2024
1 parent 5d34f32 commit e8ff3a4
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion theme/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,38 @@

{% block content %}
<div class="page-not-found">
<img src="{{ base_url }}/images/404.png" alt="Not found" />
<img src="{{ base_url }}{% if base_url|last != '/' %}/{% endif %}images/404.png" alt="Not found" />
<h1>Page not found.</h1>
<a href="/">Back to front page</a>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
<script>
if (location.host.endsWith('.readthedocs.build')) {
let basePart = '/en/latest/';
let readthedocsPart = location.pathname.split('/').slice(0, 3).join('/')+'/';
let urlElements = document.querySelectorAll('[href*="/en/latest/"], [src*="/en/latest/"]');
let head = document.getElementsByTagName('head')[0];
for (let urlElement of urlElements) {
switch (urlElement.tagName.toLowerCase()) {
case 'script':
let script = document.createElement('script');
script.setAttribute('src', urlElement.getAttribute('src').replace(basePart, readthedocsPart));
head.appendChild(script);
console.log(script);
break;
default:
let attributeName, attributeValue;
for (attributeName of ['href', 'src']) {
if (null !== (attributeValue = urlElement.getAttribute(attributeName))) {
break;
}
}
urlElement.setAttribute(attributeName, attributeValue.replace(basePart, readthedocsPart));
}
}
}
</script>
{% endblock %}

0 comments on commit e8ff3a4

Please sign in to comment.