fetch release version from PyPI
This commit is contained in:
parent
1674bcaaeb
commit
a477b4ccfd
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
.then((project) => {
|
||||
const version = project.info.version;
|
||||
const span = document.createElement("span");
|
||||
span.className = "version";
|
||||
span.innerText = tag;
|
||||
link.append(span);
|
||||
}
|
||||
span.innerText = version;
|
||||
downloadLink.append(span);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
|
|
Loading…
Reference in New Issue