I am trying to add to my website a download link to the latest github release of a project. For example the link https://github.com/mongodb/mongo/archive/r3.0.0-rc7.zip does link to the latest release (as of today), but I do not want to hard-code the version number on the web site.
I found several questions about this issue, answers using curl, ajax or php.
I tried the solution using ajax which uses the github release API:
<!DOCTYPE html>
<HTML> <BODY>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
GetLatestReleaseInfo();
});
function GetLatestReleaseInfo() {
$.getJSON("https://github.com/mongodb/mongo/releases").done(function (json) {
var release = json[0];
var asset = release.assets[0];
var downloadURL = "https://github.com/mongodb/mongo/releases" + release.tag_name + "/" + asset.name;
$(".mongodb-download").attr("href", downloadURL);
});
}
</script>
<a href="GetLatestReleaseInfo();">Link</a>
<a href="" onclick="location.href=this.href+downloadURL;return false;">Link2</a>
<a href="" onclick="location.href=this.href+mongodb-download;return false;">Link3</a>
</BODY>
</HTML>
but I do not manage to call the javascript function correctly, as it seems in my tries above (Link, Link2 and Link3). I'm not very familiar with javascript or ajax, so I'd appreciate any help; maybe there is a simpler way without Ajax?