From 3246b44a86ff7afadbdfca7efd77a9e34d3c81a8 Mon Sep 17 00:00:00 2001 From: John Hess Date: Tue, 18 Feb 2025 14:04:48 -0600 Subject: [PATCH] Conditionally display maps and app store tiles --- .gitignore | 3 ++- _scss/pages/home.scss | 6 +++++ assets/js/butter-dir-listing.js | 6 ++++- assets/js/main.js | 41 ++++++++++++++++++++------------- index.html | 8 +++---- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index a82e296..2b92e77 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ vendor/bundle .DS_Store Gemfile.lock usb-butter* -simulated-usb-butter/appstore/* \ No newline at end of file +simulated-usb-butter/appstore/* +simulated-usb-butter/osm-map-files/* \ No newline at end of file diff --git a/_scss/pages/home.scss b/_scss/pages/home.scss index 51c1f41..4b33b5b 100644 --- a/_scss/pages/home.scss +++ b/_scss/pages/home.scss @@ -222,6 +222,12 @@ h1.homepage-title { text-decoration: none; } +// Apply/Remove this class to conditionally +// display the card +.hidden-card { + display: none; +} + .card-icon { width: 60px; height: 60px; diff --git a/assets/js/butter-dir-listing.js b/assets/js/butter-dir-listing.js index 0ba70ba..6bea0ae 100644 --- a/assets/js/butter-dir-listing.js +++ b/assets/js/butter-dir-listing.js @@ -11,6 +11,10 @@ const supported_extensions = ["apk", "deb", "dmg", "pdf", "exe", "jpg", "png", " const usbRoot = "usb-butter/"; const inferredBaseURL = window.location.pathname.split("/" + usbRoot)[0] + "/"; +// Don't display these in the dirlisting; they get first-class treatment +// on the homepage. +const foldersToHide = ["appstore", "osm-map-files"]; + const getFolderDivHTML = (directory_name, number_of_items, href) => { return ` @@ -91,7 +95,7 @@ function extractDirectoryListing(doc) { // Determine if it's a file or folder based on the class of the row or type if (type === 'Directory') { - if (name !== '..') { + if (name !== '..' && !foldersToHide.includes(name)) { folders.push({ name: name.replace('/', ''), // Remove the trailing slash lastModified: lastModified, diff --git a/assets/js/main.js b/assets/js/main.js index a48c957..c915928 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -7,9 +7,9 @@ MicroModal.init({ }); // Slick Slider [https://kenwheeler.github.io/slick/] -$(document).ready(function(){ +$(document).ready(function () { let prevButton = ''; - let nextButton = ''; + let nextButton = ''; $('.screens-slider').slick({ prevArrow: prevButton, nextArrow: nextButton, @@ -35,18 +35,27 @@ if (btnModal) { }); } -// If #usb-butter exists and a request to thishost.tld/usb-butter returns status 200 -// change display of #usb-butter to inherit -const usbButter = document.querySelector('#usb-butter'); -const usbButterPlaceholder = document.querySelector('#usb-butter-placeholder'); -if (usbButter && usbButterPlaceholder) { - fetch(usbButter.dataset.url) - .then(response => { - console.log(response); - if (response.status === 200) { - usbButter.style.display = 'flex'; - usbButterPlaceholder.style.display = 'none'; +function renderPlaceholders() { + const usbButter = document.querySelector('#usb-butter'); + const appstoreCard = document.querySelector('#appstore-card'); + const mapsCard = document.querySelector('#maps-card'); + const conditionalCards = [appstoreCard, usbButter, mapsCard]; + for (let card of conditionalCards) { + fetch(card.dataset.url) + .then(response => { + if (response.status === 200) { + card.classList.remove("hidden-card"); + if (card.dataset.placeholderId) { + const placeholder = document.querySelector(`#${card.dataset.placeholderId}`); + if (placeholder) { + placeholder.classList.add("hidden-card"); + } + } + } } - } - ); -} \ No newline at end of file + ); + } +} + + +renderPlaceholders(); \ No newline at end of file diff --git a/index.html b/index.html index dd8a8ee..9187766 100644 --- a/index.html +++ b/index.html @@ -15,8 +15,8 @@ layout: default
{% t explore_missing %}
-
Explore Icon {% t explore %} @@ -24,11 +24,11 @@ layout: default Message Icon {% t message_board %} - + App Store Icon {% t app_store %} - + Maps Icon {% t offline_maps %}