calculate a baseurl

This commit is contained in:
John Hess 2024-06-05 14:26:24 -05:00
parent f3d3e77f0f
commit e78ccc9758

View file

@ -9,12 +9,15 @@
console.log("butter-dir-listing.js loaded!");
const supported_extensions = [".apk"];
const usbRoot = "/usb-butter/";
const inferredBaseURL = window.location.pathname.split("/usb-butter/")[0] + "/";
console.log("Inferred Base URL:", inferredBaseURL);
const getFolderDivHTML = (directory_name, number_of_items, href) => {
return `
<a class="container" href="${href}">
<div class="logo-container">
<img src="/assets/images/directory.svg" alt="directory">
<img src="${inferredBaseURL}assets/images/directory.svg" alt="directory">
</div>
<div class="text-container">
<div class="upper-text">${directory_name}</div>
@ -33,7 +36,7 @@ const getFileDivHTML = (file_name, size, date, href) => {
return `
<a class="container" href="${href}">
<div class="logo-container">
<img src="/assets/images/${icon}" alt="directory">
<img src="${inferredBaseURL}assets/images/${icon}" alt="directory">
</div>
<div class="text-container">
<div class="upper-text">${file_name}</div>
@ -99,7 +102,6 @@ window.onload = function () {
const listDiv = document.querySelector('div.list');
// Header with breadcrumbs
const usbRoot = "/usb-butter/";
const h2Path = document.querySelector('h2').textContent;
console.log("H2 Path:", h2Path);
const path = h2Path.replace('Index of ', '').replace(usbRoot, '');
@ -108,8 +110,8 @@ window.onload = function () {
const breadcrumbs = document.createElement("div");
breadcrumbs.classList.add('breadcrumbs');
let breadcrumbHTML = `
<a href="/"><img class="home-icon" src="/assets/images/home.svg" alt="home"></a>
<a href="${usbRoot}" class="crumb"><img class="path-next" src="/assets/images/next.svg">Explore</a>
<a href="/"><img class="home-icon" src="${inferredBaseURL}assets/images/home.svg" alt="home"></a>
<a href="${usbRoot}" class="crumb"><img class="path-next" src="${inferredBaseURL}assets/images/next.svg">Explore</a>
`;
pathSteps = path.split('/');
let pathToHere = usbRoot;
@ -117,7 +119,7 @@ window.onload = function () {
pathToHere += step + '/';
if (step !== "") {
breadcrumbHTML += `
<a href="${pathToHere}" class="crumb"><img class="path-next" src="/assets/images/next.svg">${step}</a>`;
<a href="${pathToHere}" class="crumb"><img class="path-next" src="${inferredBaseURL}assets/images/next.svg">${step}</a>`;
}
});
breadcrumbs.innerHTML = breadcrumbHTML;