Skip to content

Commit

Permalink
add better connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
jman1593 committed Nov 5, 2024
1 parent 9d0db60 commit 4752b91
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 72 deletions.
165 changes: 93 additions & 72 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,61 @@
<script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-database-compat.js"></script>
<script type="module">
import games from "./cards-data.js";

// Mapping of hostnames to their corresponding page 2 sites
const siteMapping = {
"mathcord.netlify.app": "https://mathcord2.netlify.app",
"mathcord2.netlify.app": "https://mathcord2.netlify.app",
"strongdog.netlify.app": "https://strongdog2.netlify.app",
"strongdog2.netlify.app": "https://strongdog2.netlify.app",
"stroongdog.netlify.app": "https://stroongdog2.netlify.app",
"jman1593.github.io": "https://jman1593.github.io/strongdog2",
"strongdog-1.vercel.app": "https://strongdog2.vercel.app",
"strongdog.onrender.com": "https://strongdog2.onrender.com",
"127.0.0.1": "http://127.0.0.1:8080/strongdog2",
};

import { siteMapping } from "./site-mapping.js";

function getCardHTML(gameObject) {
const { href, imgSrc, name, page } = gameObject;
let adjustedHref = href;
let adjustedImgSrc = `./img/${imgSrc}`; // Default img src

if (page === 2) {
// Get the current hostname
const hostname = window.location.hostname;

// Determine the base URL for page 2
let page2BaseURL = "";

// Find the base URL for page 2 based on the current hostname
for (const key in siteMapping) {
if (hostname.includes(key)) {
page2BaseURL = siteMapping[key];
break;
}
}

if (page2BaseURL) {
// Remove leading './' from href and imgSrc if present
const adjustedGameHref = href.replace(/^\.\//, '');
adjustedHref = `${page2BaseURL}/${adjustedGameHref}`;

const adjustedImgPath = imgSrc.replace(/^\.\//, '');
adjustedImgSrc = `${page2BaseURL}/img/${adjustedImgPath}`;
} else {
// If no matching hostname is found, default to the original href
console.warn(`No page 2 site mapping found for hostname: ${hostname}`);
}
const { href, imgSrc, name, page } = gameObject;
let adjustedHref = href;
let adjustedImgSrc = `./img/${imgSrc}`; // Default img src

if (page === 2) {
// Get the current hostname
const hostname = window.location.hostname;

// Determine the base URL for page 2
let page2BaseURL = "";

// Find the base URL for page 2 based on the current hostname
for (const key in siteMapping) {
if (hostname.includes(key)) {
page2BaseURL = siteMapping[key];
break;
}
}

return `
<a href="${adjustedHref}" class="card">
<img src="${adjustedImgSrc}">
<figcaption>${name}</figcaption>
</a>
`;
}


if (page2BaseURL) {
// Remove leading './' from href and imgSrc if present
const adjustedGameHref = href.replace(/^\.\//, "");
adjustedHref = `${page2BaseURL}/${adjustedGameHref}`;

const adjustedImgPath = imgSrc.replace(/^\.\//, "");
adjustedImgSrc = `${page2BaseURL}/img/${adjustedImgPath}`;
} else {
// If no matching hostname is found, default to the original href
console.warn(`No page 2 site mapping found for hostname: ${hostname}`);
}
}

return `
<a href="${adjustedHref}" class="card">
<img src="${adjustedImgSrc}">
<figcaption>${name}</figcaption>
</a>
`;
}

// Generate the cards
let cardsHTMLArr = [];
for (let i = 0; i < games.length; ++i) {
cardsHTMLArr.push(getCardHTML(games[i]));
cardsHTMLArr.push(getCardHTML(games[i]));
}

const cardsHTMLStr = cardsHTMLArr.join("");

document.addEventListener(
"DOMContentLoaded",
() => (document.getElementById("allGameList").innerHTML = cardsHTMLStr)
);
</script>

document.addEventListener("DOMContentLoaded", () => {
document.getElementById("allGameList").innerHTML = cardsHTMLStr;
});
</script>
<script>
const firebaseConfig = {
apiKey: "AIzaSyBh-VnGiP4qZD0r14gfn9dr77GwtslpTqU",
Expand Down Expand Up @@ -1139,7 +1126,8 @@ <h2 style="text-align: center"><strong>StrongDogXP LLC</strong></h2>
});
</script>
<script type="module">
import games from './cards-data.js';
import games from "./cards-data.js";
import { siteMapping } from "./site-mapping.js";

document.addEventListener("DOMContentLoaded", function () {
const searchInput = document.querySelector(".search-bar");
Expand All @@ -1160,15 +1148,18 @@ <h2 style="text-align: center"><strong>StrongDogXP LLC</strong></h2>

// Hide results when clicking outside the search bar and results
document.addEventListener("click", function (event) {
if (!searchInput.contains(event.target) && !searchResults.contains(event.target)) {
if (
!searchInput.contains(event.target) &&
!searchResults.contains(event.target)
) {
searchResults.style.display = "none";
}
});

function updateSearchResults() {
const searchText = searchInput.value.toLowerCase();
const filteredGames = games
.filter(game => game.name.toLowerCase().includes(searchText))
.filter((game) => game.name.toLowerCase().includes(searchText))
.slice(0, 7); // Limit to top 7 results

searchResults.innerHTML = ""; // Clear previous results
Expand All @@ -1178,24 +1169,54 @@ <h2 style="text-align: center"><strong>StrongDogXP LLC</strong></h2>
return;
}

filteredGames.forEach(game => {
const cardImg = './img/' + game.imgSrc;
const cardTitle = game.name;
const cardHref = game.href;
filteredGames.forEach((game) => {
const { href, imgSrc, name, page } = game;
let adjustedHref = href;
let adjustedImgSrc = `./img/${imgSrc}`; // Default img src

if (page === 2) {
// Get the current hostname
const hostname = window.location.hostname;

// Determine the base URL for page 2
let page2BaseURL = "";

// Find the base URL for page 2 based on the current hostname
for (const key in siteMapping) {
if (hostname.includes(key)) {
page2BaseURL = siteMapping[key];
break;
}
}

if (page2BaseURL) {
// Remove leading './' from href and imgSrc if present
const adjustedGameHref = href.replace(/^\.\//, "");
adjustedHref = `${page2BaseURL}/${adjustedGameHref}`;

const adjustedImgPath = imgSrc.replace(/^\.\//, "");
adjustedImgSrc = `${page2BaseURL}/img/${adjustedImgPath}`;
} else {
console.warn(
`No page 2 site mapping found for hostname: ${hostname}`
);
}
}

const resultLink = document.createElement("a");
resultLink.href = cardHref;
resultLink.href = adjustedHref;
resultLink.innerHTML = `
<img src="${cardImg}" alt="${cardTitle}">
<span>${cardTitle}</span>
<img src="${adjustedImgSrc}" alt="${name}">
<span>${name}</span>
`;
searchResults.appendChild(resultLink);
});

searchResults.style.display = "block"; // Show results
}
});
</script>
</script>

</body>
<script>
document.addEventListener("DOMContentLoaded", () => {
Expand Down
12 changes: 12 additions & 0 deletions site-mapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const siteMapping = {
"mathcord.netlify.app": "https://mathcord2.netlify.app",
"mathcord2.netlify.app": "https://mathcord2.netlify.app",
"strongdog.netlify.app": "https://strongdog2.netlify.app",
"strongdog2.netlify.app": "https://strongdog2.netlify.app",
"stroongdog.netlify.app": "https://stroongdog2.netlify.app",
"jman1593.github.io": "https://jman1593.github.io/strongdog2",
"strongdog-1.vercel.app": "https://strongdog2.vercel.app",
"strongdog.onrender.com": "https://strongdog2.onrender.com",
"127.0.0.1": "http://127.0.0.1:8080/strongdog2/",
};

0 comments on commit 4752b91

Please sign in to comment.