Skip to content

Commit

Permalink
Auto detect os & persist selected os (#2758)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Malecki-Jurek <[email protected]>
  • Loading branch information
piotr-m-jurek and Piotr Malecki-Jurek authored Oct 11, 2024
1 parent 707b1b6 commit 275e1bd
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/ocamlorg_frontend/pages/install.eml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ Layout.render
~description:"Quick setup instructions to install OCaml on your system."
~canonical:"" @@
<div class="lg:py-8 py-6">
<div class="container-fluid" x-data='{ operating_system: detect_os () }'>
<div class="container-fluid" x-data='{ operating_system: persist_os_link() }'>
<div class="prose dark:prose-invert mb-6">
<h1 class="sr-only ">
Install OCaml
</h1>
<div class="hidden lg:flex gap-2">
<button class="btn flex gap-2" :class='operating_system == "linux_mac_bsd"? "": "btn-ghost"' @click="operating_system = 'linux_mac_bsd'; change_anchor('linux_mac_bsd'); "> Linux, macOS or *BSD</button>
<button class="btn flex gap-2" :class='operating_system == "win"? "": "btn-ghost"' @click="operating_system = 'win'; change_anchor('windows'); ""><%s! Icons.microsoft_windows "w-6 h-6" %> Windows</button>
<button class="btn flex gap-2" :class='operating_system == "linux_mac_bsd"? "": "btn-ghost"' @click='operating_system = "linux_mac_bsd"; change_anchor("linux_mac_bsd"); '>
Linux, macOS or *BSD
</button>
<button class="btn flex gap-2" :class='operating_system == "win"? "": "btn-ghost"' @click='operating_system = "win"; change_anchor("windows"); '>
<%s! Icons.microsoft_windows "w-6 h-6" %> Windows
</button>
</div>
<div class="w-full flex md:hidden">
% let render_multi_button ~title ~active_tab ~class_ =
Expand Down Expand Up @@ -200,25 +204,37 @@ Layout.render
</div>
</div>
<script>
function detect_os ()
{
let os = navigator.userAgent;
let result="linux_mac_bsd";
if (os.search('Win')!==-1){
result="win";
}
return result;
function detect_os() {
const agent = navigator.userAgent;
if (agent.includes('Win')) {
return "win";
}
return "linux_mac_bsd";
}

function change_anchor (os_str)
{
window.location.hash = os_str
function change_anchor (os_str) {
window.location.hash = os_str;
}

function anchor_os_loc ()
{
function anchor_os_loc() {
if (window.location.hash) {
return;
}
window.location.hash = detect_os();
}

function persist_os_link () {
const hash_to_system = {
"#windows": "win",
"#linux_mac_bsd": "linux_mac_bsd"
};
if (window.location.hash) {
return hash_to_system[window.location.hash]
}
return detect_os ()
}


anchor_os_loc();

</script>

0 comments on commit 275e1bd

Please sign in to comment.