From c0b02e771faf2e30adfd31adabcd4c68727e22f4 Mon Sep 17 00:00:00 2001 From: neil Date: Tue, 27 Dec 2022 17:52:49 +0800 Subject: [PATCH] #232 package bottle info --- src/assets/scripts/package-bottles.jsx | 68 ++++++++++++++++++++++++ src/layouts/page/package-detail.html | 45 +++++++++++++++- src/layouts/partials/package-bottle.html | 7 +++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/assets/scripts/package-bottles.jsx create mode 100644 src/layouts/partials/package-bottle.html diff --git a/src/assets/scripts/package-bottles.jsx b/src/assets/scripts/package-bottles.jsx new file mode 100644 index 0000000..8e10065 --- /dev/null +++ b/src/assets/scripts/package-bottles.jsx @@ -0,0 +1,68 @@ +function PackageBottles() { + const [bottles, setBottles] = React.useState(); + + React.useEffect(() => { + const url = window.location.pathname.replace('/+', 'https://app.tea.xyz/api/bottles/'); + fetch(url) + .then((res) => res.json()) + .then((res) => setBottles(res)); + }, []); + + if (!bottles) return null; + + const names = [...new Set(bottles.map((b) => b.name))]; + + return ( +
+ {names.map((name) => ( + + ))} +
+ ); + + function Bottle({ name }) { + const [expanded, toggleExpanded] = React.useState(false); + const versions = [ + ...new Set(bottles.map((b) => b.version)), + ]; + return ( +
toggleExpanded(!expanded)}> +
+

+ {versions.length} version{versions.length === 1 ? "" : "s"} bottled +

+
+ + + + + + + + + + + + {versions.map((v) => { + const available = new Set( + bottles + .filter((b) => b.name === name && b.version == v) + .map((b) => `${b.platform}-${b.arch}`) + ); + return ( + + + + + + + + ); + })} + +
versiondarwin-aarch64darwin-x86-64linux-aarch64linux-x86-64
{v}{available.has("darwin-aarch64") ? "✅" : "❌"}{available.has("darwin-x86-64") ? "✅" : "❌"}{available.has("linux-aarch64") ? "✅" : "❌"}{available.has("linux-x86-64") ? "✅" : "❌"}
+
+ ); + } +} +ReactDOM.render(React.createElement(PackageBottles), document.getElementById("packageApp")); diff --git a/src/layouts/page/package-detail.html b/src/layouts/page/package-detail.html index d8ad331..a72ca06 100644 --- a/src/layouts/page/package-detail.html +++ b/src/layouts/page/package-detail.html @@ -30,10 +30,18 @@ +
+
+
+ + {{- partial "package-bottle.html" .Title -}} + +
+
Copy the tea one-liner below into your terminal to install  {{- .Title -}}. tea will interpret the documentation and take care of any dependencies. @@ -71,6 +79,41 @@ box-shadow: inset 0vw 0vw 0vw 0.335vw #1a1a1a !important; } - + table{ + color: #fff; + width: 100%; + } + table, th, td { + border: 1px solid #949494; + font-family: "sono", sans-serif; + padding: 20px; + } + + .expand{ + cursor: pointer; + } + + @media screen and (max-width: 576px) { + + .bottles-container{ + padding: 0px !important; + } + + table, th, td { + border: 1px solid #949494; + font-family: "sono", sans-serif; + padding: 10px; + font-size: 12px; + } + + .title-col{ + padding: 4vw !important; + + } + + } + + + {{ end }} diff --git a/src/layouts/partials/package-bottle.html b/src/layouts/partials/package-bottle.html new file mode 100644 index 0000000..df01ef9 --- /dev/null +++ b/src/layouts/partials/package-bottle.html @@ -0,0 +1,7 @@ +
+ + +
+ {{ $packageApp := resources.Get "scripts/package-bottles.jsx" | babel -}} + +
\ No newline at end of file