Skip to content

Commit

Permalink
Auto detect os & persist selected os
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Malecki-Jurek committed Oct 9, 2024
1 parent e63a0b3 commit ccd8274
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 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 @@ -47,7 +51,7 @@ Layout.render
run the following in your terminal to download and install the newest version of opam:
</p>

<%s! Copy_to_clipboard.small_code_snippet ~id:"install-opam" "bash -c \"sh <(curl -fsSL https://opam.ocaml.org/install.sh)\"" %>
<%s! Copy_to_clipboard.small_code_snippet ~id:"install-opam" "bash -c \"sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)\"" %>
<a target="_blank" href="https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" class="flex justify-end gap-1 pt-1 items-center"><%s! Icons.github "h-6 w-6" %> view script on GitHub</a>

<details>
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 ccd8274

Please sign in to comment.