Skip to content

Commit

Permalink
include publication date with version, simplify template, render publ…
Browse files Browse the repository at this point in the history
…ication dates
  • Loading branch information
sabine committed Jan 12, 2024
1 parent 6379be7 commit 38dc25f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions src/ocamlorg_frontend/components/package_breadcrumbs.eml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ let render_package_and_version
| Overview _ -> Url.Package.overview package.name ?version
| Documentation _ -> Url.Package.documentation package.name ?version ?hash ?page
in
let version_options v =
<% if v = package.latest_version then ( %>
let version_options (v: Package.version_with_publication_date) =
<% if v.version = package.latest_version then ( %>
<option value="<%s url None %>" <%s if package.version = Latest then "selected" else "" %>>
<%s "latest (" ^ package.latest_version ^ ")" %>
</option>
<% ); %>
<option value="<%s url (Some v) %>" <%s if package.version = Specific v then "selected" else "" %>>
<%s v %>
<option value="<%s url (Some v.version) %>" <%s if package.version = Specific v.version then "selected" else "" %>>
<%s v.version %>
</option>
in
<div class="flex gap-4">
Expand Down
7 changes: 6 additions & 1 deletion src/ocamlorg_frontend/package.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
type version = Latest | Specific of string
type documentation_status = Success | Failure | Unknown

type version_with_publication_date = {
version: string;
publication: float;
}

type package = {
name : string;
synopsis : string;
description : string;
license : string;
version : version;
versions : string list;
versions : version_with_publication_date list;
latest_version : string;
tags : string list;
rev_deps : string list;
Expand Down
44 changes: 15 additions & 29 deletions src/ocamlorg_frontend/pages/package_versions.eml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
let render (package : Package.package)
let render
(package : Package.package)
=
Layout.render
~title:(Printf.sprintf "%s Versions" package.name)
~description:"Package Versions" @@
let version = Package.specific_version package in
<div class="bg-default dark:bg-dark-default py-8">
<div class="container-fluid flex items-center gap-2">
<a href="/p/<%s package.name %>" class="h-11 w-11 m-5 border-primary-600 border-2 rounded-full flex items-center justify-center"><%s! Icons.arrow_left "h-6 w-6 text-primary-600"; %></a>
<h1 class="text-2xl font-medium"><%s package.name %> Versions </h1><div class="text-2xl">(<%i List.length package.versions %>)</div>
<a href="/p/<%s package.name %>" class="h-11 w-11 m-5 border-primary border-2 rounded-full flex items-center justify-center"><%s! Icons.arrow_left "h-6 w-6 text-primary"; %></a>
<h1 class="text-2xl font-medium"><%s package.name %> Versions (<%i List.length package.versions %>) </h1>
</div>
<div class="container-fluid flex justify-center">
<table class="table-auto border-separate border-spacing-y-6">
Expand All @@ -19,43 +21,27 @@ Layout.render
</tr>
</thead>
<tbody>
<% package.versions |> List.iter (fun (version : string) -> %>
<% package.versions |> List.iter (fun (item: Package.version_with_publication_date) -> %>
<tr class="tr-selected">
<% if List.nth package.versions 0 = version then ( %>
<td class="hidden sm:table-cell text-left font-normal py-5 px-4 bg-primary-200 rounded-l">
<div class="bg-primary-600 h-3 w-3 rounded-full"></div>
<td class="hidden sm:table-cell text-left font-normal py-5 px-4 <%s if version = item.version then "bg-primary-200 rounded-l" else "" %>">
<% if version = item.version then ( %><div class="bg-primary h-3 w-3 rounded-full"></div><% ) else ( %><div class="bg-gray-200 h-2 w-2 rounded-full ml-0.5"></div><% ); %>
<div class="absolute h-[4.5rem] pl-1">
<% if List.nth package.versions (List.length package.versions -1) <> item then ( %>
<div class="-ml-px w-1 border-solid border-r-2 border-gray-200 h-full"></div>
<% ); %>
</div>
</td>
<td class="text-left bg-primary-200">
<a href="/p/<%s package.name %>/<%s version %>" class="p-5 hover:no-underline hover:text-primary-600 focus:text-primary-600 focus:no-underline font-bold focus:font-bold text-base md:mr-10"><%s version %></a>
<a href="/p/<%s package.name %>/<%s item.version %>" class="p-5 hover:no-underline hover:text-primary focus:text-primary focus:no-underline <%s if version = item.version then "font-bold focus:font-bold" else "" %> text-base md:mr-10">
<%s item.version %>
</a>
</td>
<td class="pr-4 text-left text-sm bg-primary-200">
<%s Utils.human_date_of_timestamp package.publication %>
<%s Utils.human_date_of_timestamp item.publication %>
</td>
<td class="text-left text-sm bg-primary-200 rounded-r">
<a href="/p/<%s package.name %>/<%s version %>/doc/index.html" class="text-primary-600 flex items-center p-2 font-medium sm:p-4"><%s! Icons.document "h-5 w-5"; %> Documentation</a>
</td>
<% ) else ( %>
<td class="hidden sm:table-cell text-left font-normal py-5 px-4">
<div class="bg-gray-200 h-2 w-2 rounded-full ml-0.5"></div>
<div class="absolute h-[4.5rem] pl-1">
<% if List.nth package.versions (List.length package.versions -1) <> version then ( %>
<div class="-ml-px w-1 border-solid border-r-2 border-gray-200 h-full"></div>
<% ); %>
</div>
</td>
<td class="text-left">
<a href="/p/<%s package.name %>/<%s version %>" class="p-5 hover:no-underline hover:text-primary-600 focus:text-primary-600 focus:no-underline hover:font-bold focus:font-bold text-base md:mr-10"><%s version %></a>
</td>
<td class="pr-4 text-left text-sm">
<%s Utils.human_date_of_timestamp package.publication %>
</td>
<td class="text-left text-sm">
<a href="/p/<%s package.name %>/<%s version %>/doc/index.html" class="text-primary-600 flex items-center p-2 font-medium sm:p-4"><%s! Icons.document "h-5 w-5"; %> Documentation</a>
<a href="/p/<%s package.name %>/<%s item.version %>/doc/index.html" class="text-primary flex items-center p-2 font-medium sm:p-4"><%s! Icons.document "h-5 w-5"; %> Documentation</a>
</td>
<% ); %>
</tr>
<% ); %>
</tbody>
Expand Down
13 changes: 10 additions & 3 deletions src/ocamlorg_package/lib/ocamlorg_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,16 @@ let get_by_name t name =
|> Option.map Version.Map.bindings
|> Option.map (List.map (fun (version, info) -> { name; version; info }))

type version_with_publication_date = {
version : Version.t;
publication: float;
}

let get_versions t name =
t.packages |> Name.Map.find_opt name
|> Option.map (fun p -> p |> Version.Map.bindings |> List.rev_map fst)
|> Option.map (fun p -> p |> Version.Map.bindings |> List.map (fun (version, info) -> { version; publication = info.Info.publication}))
|> Option.value ~default:[]
|> List.sort (fun v1 v2 -> Version.compare v2.version v1.version)

let get_latest t name = get_latest' t.packages name

Expand Down Expand Up @@ -404,8 +411,8 @@ let latest_documented_version t name =
| None -> aux (List.tl vlist))
in
match get_versions t name with
| None -> Lwt.return None
| Some vlist -> aux vlist
| [] -> Lwt.return None
| vlist -> aux (vlist |> List.map (fun v -> v.version))

let is_latest_version t name version =
match get_latest t name with
Expand Down
7 changes: 6 additions & 1 deletion src/ocamlorg_package/lib/ocamlorg_package.mli
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ val stats : state -> Statistics.t option
val get_by_name : state -> Name.t -> t list option
(** Get the list of packages with the given name. *)

val get_versions : state -> Name.t -> Version.t list option
type version_with_publication_date = {
version : Version.t;
publication: float;
}

val get_versions : state -> Name.t -> version_with_publication_date list
(** Get the list of versions for a package name, newest coming first. *)

val get_latest : state -> Name.t -> t option
Expand Down
5 changes: 1 addition & 4 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ let changelog req =
Data.Changelog.all
|> List.concat_map (fun (change : Data.Changelog.t) -> change.tags)
|> List.sort_uniq String.compare
|> List.sort_uniq String.compare
in
let changes =
match current_tag with
Expand Down Expand Up @@ -472,9 +471,7 @@ module Package_helper = struct
(** Query all the versions of a package. *)
let versions state name =
Ocamlorg_package.get_versions state name
|> Option.value ~default:[]
|> List.sort (Fun.flip Ocamlorg_package.Version.compare)
|> List.map Ocamlorg_package.Version.to_string
|> List.map (fun (v: Ocamlorg_package.version_with_publication_date) -> Ocamlorg_frontend.Package.{version = Ocamlorg_package.Version.to_string v.version; publication = v.publication})

let frontend_package ?on_latest_url state (package : Ocamlorg_package.t) :
Ocamlorg_frontend.Package.package =
Expand Down

0 comments on commit 38dc25f

Please sign in to comment.