Skip to content

Commit

Permalink
Fix 404 error when docs version switching (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-narozniak authored Dec 21, 2023
1 parent 1d6c13a commit 577bd7e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion doc/source/_templates/sidebar/versioning.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,40 @@
}
</style>

<script>
function checkPageExistence(versionName, current_language, pagename) {
var newUrl = `https://flower.dev/docs/framework/${versionName}/${current_language}/${pagename}.html`;
var fallbackUrl = `https://flower.dev/docs/framework/${versionName}/${current_language}/index.html#references`;

fetch(newUrl)
.then(response => {
if (response.ok) {
window.location.href = newUrl;
} else {
window.location.href = fallbackUrl;
}
})
.catch(error => {
console.error('Error:', error);
window.location.href = fallbackUrl;
});
}
</script>

<div class="wrap-collabsible">
<input id="collapsible" class="toggle" type="checkbox">
<label for="collapsible" class="lbl-toggle">Versions</label>
<div class="collapsible-content">
<div class="content-inner">
<ul>
{%- for item in versions %}
<li><a href="https://flower.dev/docs/framework/{{ item.name }}/{{ current_language }}/{{ pagename }}.html" style="text-decoration:none">{{ item.name }}</a></li>
<li>
<a href="javascript:void(0);"
onclick="checkPageExistence('{{ item.name }}', '{{ current_language }}', '{{ pagename }}')"
style="text-decoration:none">
{{ item.name }}
</a>
</li>
{%- endfor %}
</ul>
</div>
Expand Down

0 comments on commit 577bd7e

Please sign in to comment.