fetch release version from PyPI
This commit is contained in:
parent
1674bcaaeb
commit
a477b4ccfd
|
@ -24,7 +24,7 @@ contents:
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 visible-md-block visible-lg-block">
|
<div class="col-md-4 visible-md-block visible-lg-block">
|
||||||
<div class="download-btn"><a href="downloads/"
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,21 +3,17 @@
|
||||||
import "bootstrap";
|
import "bootstrap";
|
||||||
|
|
||||||
function initDownloadButton() {
|
function initDownloadButton() {
|
||||||
const downloadButton = document.querySelector(".download-btn");
|
const downloadLink = document.querySelector(".download-btn a");
|
||||||
if (downloadButton) {
|
if (downloadLink) {
|
||||||
fetch("https://api.github.com/repos/lektor/lektor/releases", {
|
// See https://warehouse.pypa.io/api-reference/json.html#project
|
||||||
method: "GET",
|
fetch("https://pypi.org/pypi/lektor/json", { method: "GET" })
|
||||||
})
|
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((releases) => {
|
.then((project) => {
|
||||||
const tag = releases[0].tag_name;
|
const version = project.info.version;
|
||||||
const link = downloadButton.querySelector("a");
|
|
||||||
if (link) {
|
|
||||||
const span = document.createElement("span");
|
const span = document.createElement("span");
|
||||||
span.className = "version";
|
span.className = "version";
|
||||||
span.innerText = tag;
|
span.innerText = version;
|
||||||
link.append(span);
|
downloadLink.append(span);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
Loading…
Reference in New Issue