Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds hash/latest functionality #435

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions layouts/shortcodes/latest-redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,31 @@
{{- end -}}
{{/* new `currentVersion` contains only the valid pages in the correct section/langauge/version */}}
var docs_location;
var final_hash = "";
var last_hash_location;
{{/* do we have a hash in the URL? */}}
if (window.location && window.location.hash) {
{{/* get the hash portion and snip off the first character (will always be #) */}}
docs_location = window.location.hash.slice(1);
{{/* get the last hash value for any incoming hash links */}}
last_hash_location = docs_location.lastIndexOf("#");
{{/* if the last hash value exists, put it in `final_hash` and change docs_location to remove it */}}
if (last_hash_location !== -1) {
final_hash = window.location.hash.slice(last_hash_location+1);
docs_location = window.location.hash.slice(1, last_hash_location+1);
}

{{/* does it have a trailing slash? If not, add one to match the Hugo output */}}
if (docs_location[docs_location.length-1] !== '/') {
docs_location = docs_location + '/';
}
{{/* Is the passed URL fragment in the array? */}}
if (currentVersion.indexOf(docs_location) !== -1) {
{{/* reconstruct the URL with the latest version */}}
location.assign(currentURLPrefix + docs_location);
location.assign(currentURLPrefix + docs_location + final_hash);
} else {
{{/* otherwise just go to the top of the current version */}}
location.assign(currentURLPrefix);
location.assign(currentURLPrefix + final_hash);
}
}
})();
Expand Down