diff options
Diffstat (limited to 'themes/danix-xyz-hacker')
| -rw-r--r-- | themes/danix-xyz-hacker/assets/js/language-switcher.js | 24 | ||||
| -rw-r--r-- | themes/danix-xyz-hacker/hugo.toml | 0 | ||||
| -rw-r--r-- | themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/language-switcher.js b/themes/danix-xyz-hacker/assets/js/language-switcher.js new file mode 100644 index 0000000..3d8ffac --- /dev/null +++ b/themes/danix-xyz-hacker/assets/js/language-switcher.js @@ -0,0 +1,24 @@ +document.addEventListener('DOMContentLoaded', function() { + // Get all language switcher elements + const langSwitchers = document.querySelectorAll('[data-lang-switch]'); + + if (!langSwitchers || langSwitchers.length === 0) { + return; + } + + // Add click event listener to each language switcher + langSwitchers.forEach(function(switcher) { + switcher.addEventListener('click', function(e) { + e.preventDefault(); + + // Get the language code from the data attribute + const langCode = this.getAttribute('data-lang-switch'); + + // Store the language preference in localStorage + localStorage.setItem('preferred-language', langCode); + + // Navigate to the language-specific URL + window.location.href = this.href; + }); + }); +}); diff --git a/themes/danix-xyz-hacker/hugo.toml b/themes/danix-xyz-hacker/hugo.toml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/themes/danix-xyz-hacker/hugo.toml diff --git a/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html b/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html index 5b84fdd..00d99e3 100644 --- a/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html +++ b/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html @@ -42,6 +42,7 @@ {{ range .Site.Languages }} {{ $current := eq . $.Page.Language }} <a + data-lang-switch="{{ .Lang }}" href="{{ .LanguagePrefix }}" class="flex-1 py-2 px-3 text-center rounded transition-colors {{ if $current }}bg-accent text-white{{ else }}bg-surface hover:bg-surface/80{{ end }}" > |
