// @ts-check
import "bootstrap";
function initDownloadButton() {
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((project) => {
const version = project.info.version;
const span = document.createElement("span");
span.className = "version";
span.innerText = version;
downloadLink.append(span);
})
.catch((err) => {
console.error(
"fetching the latest Lektor version from the Github API failed: ",
err
);
});
}
}
function initGoogleSearch() {
const container = document.querySelector(".google-custom-search");
if (!container) {
return;
}
const cx = "012722186170730423054:utwznhnrrmi";
const gcse = document.createElement("script");
gcse.type = "text/javascript";
gcse.async = true;
gcse.src =
(document.location.protocol == "https:" ? "https:" : "http:") +
"//cse.google.com/cse.js?cx=" +
cx;
const firstScript = document.getElementsByTagName("script")[0];
if (!firstScript || !firstScript.parentNode) {
return;
}
firstScript.parentNode.insertBefore(gcse, firstScript);
container.insertAdjacentHTML(
"beforeend",
`