Skip to content

Commit

Permalink
Merge pull request #658 from quanb-duy/404-message
Browse files Browse the repository at this point in the history
DP-2808 - 404 message for older versions
  • Loading branch information
hkad98 authored Apr 23, 2024
2 parents 09ec236 + d02f02b commit 96b5fce
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/layouts/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{ define "main" -}}
<div class="row default-404">
<div class="container">
<div class="row">
<div class="col-12 col-lg-6">
<h2 class="mt-0">404 Page</h2>
<h1>Ohh, there is nothing in here!</h1>

{{ if and (isset .Site.Params "404") (isset (index .Site.Params "404") "links") }}
<div class="mt-7">
<h2 class="mb-4">But you can try:</h2>
<ul class="mt-2">
{{ range index (index .Site.Params "404") "links" }}
<li>
<a href="{{ .link }}">{{ .title }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
</div>
<div class="col-12 col-lg-6 d-flex align-items-center justify-content-end">
<img class="mw-100" src="https://www.gooddata.com/img/pages/error/error-404_animation.svg" alt="Where did it go?">
</div>
</div>
</div>
</div>

<div class="row old-version__404 d-none">
<div class="container">
<div class="row">
<div class="col-12 col-lg-6">
<h2 class="mt-0">404 Page</h2>
<h1>This version is no longer live</h1>

{{ if and (isset .Site.Params "404") (isset (index .Site.Params "404") "links") }}
<div class="mt-7">
<h2 class="mb-4">But you can try:</h2>
<a href="https://gooddata.com/docs/python-sdk/latest/">Latest version of Python SDK</a>
<p>You can find past versions of the documentation in the Python SDK <a href="https://github.com/gooddata/gooddata-python-sdk">GitHub repository</a>. To retrieve older version, follow the instructions in the <a href="https://github.com/gooddata/gooddata-python-sdk/blob/master/CONTRIBUTING.md">README</a>.</p>
</div>
{{ end }}

</div>
<div class="col-12 col-lg-6 d-flex align-items-center justify-content-end">
<img class="mw-100" src="https://www.gooddata.com/img/pages/error/error-404_animation.svg" alt="Where did it go?">
</div>
</div>
</div>
</div>
{{- end }}
2 changes: 2 additions & 0 deletions docs/layouts/partials/hooks/body-end.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
<script src="/js/code-select.js"></script>
<script src="/js/content-select.js"></script>
<script src="/js/pactsafe.js"></script>
<script src="/js/404-old-version.js"></script>

26 changes: 26 additions & 0 deletions docs/static/js/404-old-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$(document).ready(function () {
const defaultError = document.querySelector(".default-404");
const newError = document.querySelector(".old-version__404");
const dropdownItems = document.getElementsByClassName("dropdown-item");
const availableVersions = ["latest"];

// put each available version into array availableVersions
[...dropdownItems].forEach((element) => {
availableVersions.push(element.innerText.trim());
});

if (window.location) {
// pathname of the current page
const pathname = window.location.pathname;

// extract version from pathname
const version = pathname.split('/')[1];

// Check if the version extracted is a valid version, if it is included in available versions and if it matches the regex digit format
if (version && !availableVersions.includes(version) && version.match(/^\d+\.\d+$/)) {
newError.classList.toggle("d-none");
defaultError.classList.toggle("d-none");
}
}

});

0 comments on commit 96b5fce

Please sign in to comment.