Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,42 @@ module Sync = struct
let cmd = Cmd.v info term
end

let find_latest_stable bundles =
bundles
|> List.filter_map (fun (b : Metadata.Bundle.t) ->
match b.tag with
| None -> None
| Some tag ->
(match Scanf.sscanf_opt tag "%d.%d.%d" (fun x y z -> x, y, z) with
| None -> None
| Some tup -> Some (tup, b)))
|> List.sort (fun ((maj, min, patch), _) ((maj', min', patch'), _) ->
(* reverse sort, biggest first *)
Comment thread
Leonidas-from-XIV marked this conversation as resolved.
match Int.compare maj' maj with
| 0 ->
(match Int.compare min' min with
| 0 -> Int.compare patch' patch
| otherwise -> otherwise)
| otherwise -> otherwise)
|> function
| [] -> None
| (_, bundle) :: _ -> Some bundle
;;

module Http = struct
let serve dev metadata_file port =
let title = "Dune Nightly" in
let base_url = Config.Server.url in
let bundles = Metadata.import_from_json metadata_file in
let latest_release =
match find_latest_stable bundles with
| None -> "<RELEASE>"
| Some bundle ->
(* guaranteed to exist at this point *)
Option.get bundle.tag
in
let routes =
let main_page = Web.generate_main_page ~title ~base_url bundles in
let main_page = Web.generate_main_page ~title ~base_url ~latest_release bundles in
Web.Route.empty
|> Web.Route.add ~path:"/" main_page
|> Web.Route.add ~path:"/index.html" main_page
Expand Down
56 changes: 19 additions & 37 deletions lib/component.mlx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
module Info = struct
let curl_with_sh url =
Format.sprintf "curl -fsSL %s | sh" url |> JSX.string
let curl_with_sh ~url ~sh_args =
let sh_args = match sh_args with
| None -> ""
| Some x -> " " ^ x
in
Printf.sprintf "curl -fsSL %s | sh%s" url sh_args |> JSX.string

let curl_with_sh_nightly ~url = curl_with_sh ~url ~sh_args:None

let curl_with_sh_stable ~url ~version =
let sh_args = Some (Printf.sprintf "-s - --release %s" version) in
curl_with_sh ~url ~sh_args
end

module Link = struct
Expand All @@ -25,43 +35,15 @@ end
module Curl = struct
let make ~script () =
<div class_="w-full pl-4 bg-secondary text-white flex flex-row items-center justify-between rounded-md">
<span id="install-cmd" class_="pr-2 font-mono">
<span class_="pr-2 font-mono curl-cmd">
script
</span>
<Icons.copy id="copy-btn" class_="rounded-tr-md rounded-br-md cursor-pointer bg-copy" />
<Icons.ok id="copy-btn-active" class_="h-[52px] w-[52px] flex items-center justify-center hidden rounded-tr-md rounded-br-md cursor-pointer bg-primary-light" />
<script>
(JSX.unsafe {|
function activeButton(active) {
const copyBtn = document.querySelector('#copy-btn');
const copyBtnActive = document.querySelector('#copy-btn-active');
if (active) {
copyBtn.classList.add("hidden")
copyBtnClicked.classList.remove("hidden")
} else {
copyBtnClciked.classList.add("hidden")
copyBtn.classList.remove("hidden")
}
}

document.addEventListener('DOMContentLoaded', () => {
const installCmd = document.querySelector('#install-cmd');
const copyBtn = document.querySelector('#copy-btn');
const copyBtnActive = document.querySelector('#copy-btn-active');
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(installCmd.innerText)
copyBtn.classList.add("hidden")
copyBtnActive.classList.remove("hidden")
setTimeout(() => {
copyBtnActive.classList.add("hidden")
copyBtn.classList.remove("hidden")
}, 2000);
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
});
|})
</script>
<div class_="curl-copy-btn cursor-pointer" onclick="(function(btn) { var container = btn.parentElement; var cmd = container.querySelector('.curl-cmd'); var okBtn = container.querySelector('.curl-copy-ok'); navigator.clipboard.writeText(cmd.innerText).then(function() { btn.classList.add('hidden'); okBtn.classList.remove('hidden'); setTimeout(function() { okBtn.classList.add('hidden'); btn.classList.remove('hidden'); }, 2000); }); })(this)">
<Icons.copy id="" class_="rounded-tr-md rounded-br-md bg-copy" />
</div>
<div class_="curl-copy-ok hidden">
<Icons.ok id="" class_="h-[52px] w-[52px] flex items-center justify-center rounded-tr-md rounded-br-md bg-primary-light" />
</div>
</div>
end

Expand Down
4 changes: 2 additions & 2 deletions lib/container.mlx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let navbar () =
<a id="share-menu" class_="p-2.5 hover:text-primary-light" onclick="onItemClick(this)" href="/#feedback">"Share Feedback"</a>
<a id="faq-menu" class_="p-2.5 hover:text-primary-light" onclick="onItemClick(this)" href="/#faq">"FAQs"</a>
<a id="manual-menu" class_="p-2.5 hover:text-primary-light" onclick="onItemClick(this)" href="/#manual-installation">"Manual Installation"</a>
<a id="release-menu" class_="p-2.5 hover:text-primary-light" onclick="onItemClick(this)" href="/#release-history">"Last Month Release History"</a>
<a id="release-menu" class_="p-2.5 hover:text-primary-light" onclick="onItemClick(this)" href="/#build-history">"Last Month Build History"</a>
</div>
</nav>

Expand All @@ -58,7 +58,7 @@ let footer_info () =
<a class_="hover:text-primary-light" href="/#feedback">"Share Feedback"</a>
<a class_="hover:text-primary-light" href="/#faq">"FAQs"</a>
<a class_="hover:text-primary-light" href="/#manual-installation">"Manual Installation"</a>
<a class_="hover:text-primary-light" href="/#release-history">"Last Month Release History"</a>
<a class_="hover:text-primary-light" href="/#build-history">"Last Month Build History"</a>
</div>
<div class_="bg-primary-light/20 rounded-md border border-primary-light flex justify-start items-center px-5 py-2 gap-4">
<Icons.github class_="fill-primary-light" />
Expand Down
46 changes: 27 additions & 19 deletions lib/main.mlx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ let warning () =
</div>


let getting_started ~install_url () =
let getting_started ~install_url ~latest_release:version () =
<section id="download" class_="w-full flex justify-center pt-9 pb-12 px-5 lg:px-0">
<div class_="w-full lg:w-lg flex flex-col">

<h2 class_="mb-5">"Install Dune"</h2>
<h4>
<span class_="mr-2.5"><Icons.terminal /></span>
"Copy & Install"
"Copy & Install (nightly)"
</h4>
<Curl script=(Info.curl_with_sh_nightly ~url:install_url) />

<h4>
<span class_="mr-2.5"><Icons.terminal /></span>
"Copy & Install (stable)"
</h4>
<Curl script=(Info.curl_with_sh install_url) />
<Curl script=(Info.curl_with_sh_stable ~url:install_url ~version) />

<h3 class_="mt-10 mb-2.5">"Getting Started"</h3>
<p>"You can create and run your first hello-world program using Dune like this"</p>
<h4 class_="mt-2.5">
Expand Down Expand Up @@ -237,7 +245,7 @@ let installation_target ~base_url ~bundle target =
<a class_="text-black underline hover:text-primary-light" href=cert_href>"Certificate"</a>
</li>

let manual_installation ~base_url ~releases () =
let manual_installation ~base_url ~builds () =
<section id="manual-installation" class_="w-full flex justify-center border-t border-b border-black/20 py-10 bg-section-manual px-5 lg:px-0">
<div class_="w-full lg:w-lg flex flex-col gap-2 ">
<h2 class_="mb-2"> "Manual Installation" </h2>
Expand All @@ -246,20 +254,20 @@ let manual_installation ~base_url ~releases () =
</p>
<h3 class_="mb-2.5"> "Featured Downloads" </h3>
<p class_="mb-4">
"This is the latest release of the Dune nightly. See the "
<Link class_="text-[var(--accent)]" href="#release-history">"release history"</Link>
" section for all past releases."
"This is the latest build of the Dune nightly. See the "
<Link class_="text-[var(--accent)]" href="#build-history">"build history"</Link>
" section for all past builds."
</p>
<ul class_="flex flex-row gap-2.5 justify-around flex-wrap items-center align-center mb-5">
(let bundle: Metadata.Bundle.t = releases |> List.hd in
(let bundle: Metadata.Bundle.t = builds |> List.hd in
bundle.targets
|> List.map (installation_target ~base_url ~bundle)
|> JSX.list)
</ul>

<h3 class_="mb-2.5"> "Installing the binary" </h3>
<p>
"After downloading a binary release of Dune, make it executable and place it somewhere reachable by your PATH:"
"After downloading a binary build of Dune, make it executable and place it somewhere reachable by your PATH:"
</p>
<h4 class_="mt-2.5">
<span class_="mr-2.5"><Icons.terminal /></span>
Expand Down Expand Up @@ -307,19 +315,19 @@ let release_information ~base_url ~bundle ~target () =
</tr>


let release_history ~base_url ~releases () =
let build_history ~base_url ~builds () =
let open Metadata in
<section id="release-history" class_="w-full flex justify-center py-10 px-5 lg:px-0">
<section id="build-history" class_="w-full flex justify-center py-10 px-5 lg:px-0">
<div class_="w-full lg:w-lg flex flex-col gap-2 text-left">
<h2 class_="mb-4"> "Last Month Release History" </h2>
<h2 class_="mb-4"> "Last Month Build History" </h2>
Comment thread
Leonidas-from-XIV marked this conversation as resolved.
<p>
"Here is a list of the "
(JSX.int (List.length releases))
(JSX.int (List.length builds))
" latest builds of the Dune nightly."
</p>
<div class_="w-full flex flex-col gap-4">
(
releases
builds
|> List.map (fun (bundle: Bundle.t) ->
let date = Bundle.get_date_string_from ~prefix:"nightly-" bundle in
let summary = Format.sprintf "dune %s" date in
Expand Down Expand Up @@ -347,15 +355,15 @@ let release_history ~base_url ~releases () =
</div>
</section>

let page ~base_url ~releases () =
let releases = Core.List.take 30 releases in
let page ~base_url ~latest_release ~builds () =
let builds = Core.List.take 30 builds in
let install_url = Filename.concat base_url "install" in
<main class_="flex flex-col w-full">
<header_info />
<warning />
<getting_started install_url />
<getting_started install_url latest_release />
<feedback />
<faq />
<manual_installation base_url releases />
<release_history base_url releases />
<manual_installation base_url builds />
<build_history base_url builds />
</main>
4 changes: 2 additions & 2 deletions lib/web.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let export_website_to_string ~title content = Container.page ~title content |> JSX.render

let generate_main_page ~title ~base_url releases =
Main.page ~base_url ~releases () |> export_website_to_string ~title
let generate_main_page ~title ~base_url ~latest_release builds =
Main.page ~base_url ~latest_release ~builds () |> export_website_to_string ~title
;;

let generate_error_page ~title reason =
Expand Down
27 changes: 25 additions & 2 deletions static/install
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ success_bold() {
printf "%b%s %b" "${Bold_Green}" "$*" "${Color_Off}"
}

while [ "$#" -gt "0" ]; do
arg="$1"
shift
case "$arg" in
-r|--release)
if [ "$#" -eq "0" ]; then
error "--release must be passed an argument"
fi
release="$1"
shift
;;
*)
error "Unknown argument: ${arg}"
;;
esac
done

tildify() {
case "$1" in
"$HOME"/*)
Expand Down Expand Up @@ -78,7 +95,13 @@ esac

tar_target_name="dune-$target"
tar_target="$tar_target_name.tar.gz"
dune_tar_uri="https://nightly.dune.build/latest/$target"

release=${release:-nightly}
if [ "$release" = "nightly" ]; then
dune_tar_uri="https://nightly.dune.build/latest/${target}"
else
dune_tar_uri="https://nightly.dune.build/stable/${release}/${target}"
fi

install_dir="$HOME/.local"
bin_dir="${install_dir}/bin"
Expand Down Expand Up @@ -345,4 +368,4 @@ fi
# end of main
}

main
main "$@"
16 changes: 16 additions & 0 deletions static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ video {
--tw-contain-style: ;
}

.container {
width: 100%;
}

@media (min-width: 60em) {
.container {
max-width: 60em;
}
}

@media (min-width: 80em) {
.container {
max-width: 80em;
}
}

.absolute {
position: absolute;
}
Expand Down