Skip to content

Commit

Permalink
fix(view-on-gh): 🐛 error in view on github when url with hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-Liuxf committed Jun 5, 2024
1 parent ec8f174 commit c4a2c07
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@
const repo_url = "{{ site.github.repository_url }}";
const repo_branch = "{{ site.github.source.branch }}";
const repo_path = "{{ site.github.source.path }}";
const current_url = window.location.href;
const full_url = window.location.href;
const page_hash = window.location.hash;
const page_search = window.location.search;
const current_url = window.location.origin + window.location.pathname;
const paths = current_url.split('/');
const pattern = /^(zh-CN|zh-TW|en-US|fr-FR)$/;
const lang_index = paths.findIndex(path => pattern.test(path));
const is_main_page = paths.length === 5 && current_url.endsWith('/');

// Get the params and #id in current_url
const params = current_url.split('?')[1];
const hash = current_url.split('#')[1];

document.documentElement.lang = lang_index !== -1 ? paths[lang_index] : 'en-US';

const returnToBackPage = () => {
Expand Down

0 comments on commit c4a2c07

Please sign in to comment.