fetch release version from PyPI

This commit is contained in:
Jakob Schnitzer 2022-12-18 10:13:25 +01:00
parent 1674bcaaeb
commit a477b4ccfd
2 changed files with 11 additions and 15 deletions

View File

@ -24,7 +24,7 @@ contents:
</div>
<div class="col-md-4 visible-md-block visible-lg-block">
<div class="download-btn"><a href="downloads/"
><i class="glyphicon glyphicon-download-alt"></i> Download</a></div>
><i class="glyphicon glyphicon-download-alt"></i> Download Lektor</a></div>
</div>
</div>
</div>

View File

@ -3,21 +3,17 @@
import "bootstrap";
function initDownloadButton() {
const downloadButton = document.querySelector(".download-btn");
if (downloadButton) {
fetch("https://api.github.com/repos/lektor/lektor/releases", {
method: "GET",
})
const downloadLink = document.querySelector(".download-btn a");
if (downloadLink) {
// See https://warehouse.pypa.io/api-reference/json.html#project
fetch("https://pypi.org/pypi/lektor/json", { method: "GET" })
.then((res) => res.json())
.then((releases) => {
const tag = releases[0].tag_name;
const link = downloadButton.querySelector("a");
if (link) {
const span = document.createElement("span");
span.className = "version";
span.innerText = tag;
link.append(span);
}
.then((project) => {
const version = project.info.version;
const span = document.createElement("span");
span.className = "version";
span.innerText = version;
downloadLink.append(span);
})
.catch((err) => {
console.error(