Skip to content

Commit 8c4387a

Browse files
committed
fix js files
1 parent 6e444a5 commit 8c4387a

3 files changed

Lines changed: 31 additions & 64 deletions

File tree

website/assets/js/collection.js

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ function updatePagination() {
780780
});
781781
}
782782

783-
document.addEventListener('DOMContentLoaded', loadCollection);
783+
document.addEventListener('DOMContentLoaded', () => {
784+
if (window.location.pathname.includes('collection.html')) loadCollection();
785+
});
784786

785787

786788

@@ -868,20 +870,12 @@ function getEntityLabel(graph, entityData) {
868870
// Handle other labels
869871
return entity.label ||
870872
entity['rdfs:label'] ||
873+
entity.title ||
871874
entity.card_name ||
872875
idToFind.split(':').pop().replace(/-/g, ' ');
873876
}
874877

875-
/**
876-
* Helper: Converts GitHub blob URLs to raw image URLs
877-
*/
878-
function getLocalImagePath(imageUrl) {
879-
if (!imageUrl) return 'assets/images/placeholder_card.jpg';
880-
if (imageUrl.includes('github.com') && imageUrl.includes('/blob/')) {
881-
return imageUrl.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/');
882-
}
883-
return imageUrl;
884-
}
878+
885879

886880
/**
887881
* Fills the HTML placeholders with deck metadata
@@ -1140,7 +1134,9 @@ function renderDeckCards(graph, deckId) {
11401134
}
11411135
}
11421136

1143-
document.addEventListener('DOMContentLoaded', initDeckPage);
1137+
document.addEventListener('DOMContentLoaded', () => {
1138+
if (window.location.pathname.includes('deck.html')) initDeckPage();
1139+
});
11441140

11451141

11461142
// --- CARD PAGE --- //
@@ -1195,50 +1191,9 @@ async function initCardPage() {
11951191
}
11961192
}
11971193

1198-
/**
1199-
* Helper: Finds an entity in the graph by ID and returns its human-readable label
1200-
*/
1201-
function getEntityLabel(graph, entityData) {
1202-
if (!entityData) return null;
12031194

1204-
// If it's an array, take the first one or handle both
1205-
const data = Array.isArray(entityData) ? entityData[0] : entityData;
12061195

1207-
const idToFind = typeof data === 'string' ? data : data['@id'];
1208-
if (!idToFind) return null;
12091196

1210-
const entity = graph.find(obj => obj['@id'] === idToFind);
1211-
1212-
if (!entity) {
1213-
// Safe split: only if idToFind exists and contains ':'
1214-
return idToFind.includes(':') ? idToFind.split(':').pop().replace(/-/g, ' ') : idToFind;
1215-
}
1216-
1217-
// Priority: Lineage Label > Full Name > Standard Labels
1218-
if (entity.lineage_label) return entity.lineage_label;
1219-
if (entity.given_name || entity.family_name) {
1220-
const first = entity.given_name || "";
1221-
const last = entity.family_name || "";
1222-
return `${first} ${last}`.trim();
1223-
}
1224-
1225-
return entity.label ||
1226-
entity['rdfs:label'] ||
1227-
entity.title ||
1228-
entity.card_name ||
1229-
idToFind.split(':').pop().replace(/-/g, ' ');
1230-
}
1231-
1232-
/**
1233-
* Helper: Converts GitHub blob URLs to raw image URLs
1234-
*/
1235-
function getLocalImagePath(imageUrl) {
1236-
if (!imageUrl) return 'assets/images/placeholder_card.jpg';
1237-
if (imageUrl.includes('github.com') && imageUrl.includes('/blob/')) {
1238-
return imageUrl.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/');
1239-
}
1240-
return imageUrl;
1241-
}
12421197

12431198
/**
12441199
* Fills the HTML placeholders with card metadata
@@ -1966,7 +1921,9 @@ function closeSymbolismOverlay() {
19661921
}
19671922

19681923
document.addEventListener('DOMContentLoaded', () => {
1969-
initCardPage();
1924+
if (window.location.pathname.includes('card.html')) {
1925+
initCardPage();
1926+
}
19701927

19711928
// Close listeners
19721929
const closeBtn = document.getElementById('closeSymbolism');

website/assets/js/explore.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ function createTopicCard(title, subtitle, linkUrl) {
283283
return linkWrapper;
284284
}
285285

286-
document.addEventListener('DOMContentLoaded', initExplorePage);
286+
document.addEventListener('DOMContentLoaded', () => {
287+
if (window.location.pathname.includes('explore.html')) initExplorePage();
288+
});
287289

288290

289291
// DEEPENING //
@@ -293,6 +295,7 @@ document.addEventListener('DOMContentLoaded', initExplorePage);
293295
*/
294296

295297
document.addEventListener('DOMContentLoaded', async () => {
298+
if (!window.location.pathname.includes('deepening.html')) return;
296299
const urlParams = new URLSearchParams(window.location.search);
297300
const topicId = urlParams.get('id');
298301

@@ -655,6 +658,7 @@ function renderImageSection(container, src, alt, caption = null) {
655658

656659
// PERSON //
657660
document.addEventListener('DOMContentLoaded', async () => {
661+
if (!window.location.pathname.includes('person.html')) return;
658662
const urlParams = new URLSearchParams(window.location.search);
659663
const personId = urlParams.get('id'); // e.g., 'person-waite'
660664

@@ -695,7 +699,7 @@ document.addEventListener('DOMContentLoaded', async () => {
695699
}
696700
});
697701

698-
function getLocalImagePath(imageUrl) {
702+
function getLocalPersonImagePath(imageUrl) {
699703
if (!imageUrl) return 'assets/images/explore/people/portrait-placeholder.jpg';
700704
if (imageUrl.includes('github.com') && imageUrl.includes('/blob/')) {
701705
return imageUrl.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/');
@@ -812,7 +816,7 @@ function fillPersonMetadata(person, extraTexts, graph) {
812816
const imgEl = document.getElementById('person-portrait');
813817
if (imgEl) {
814818
const rawUrl = person.person_portrait_url ? (person.person_portrait_url['@id'] || person.person_portrait_url) : null;
815-
imgEl.src = getLocalImagePath(rawUrl);
819+
imgEl.src = getLocalPersonImagePath(rawUrl);
816820
imgEl.alt = fullName;
817821
}
818822

website/assets/js/main.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,10 @@ document.addEventListener('DOMContentLoaded', () => {
415415

416416
// CARD OF THE DAY //
417417
(function () {
418-
const GRAPH_PATH = "website/assets/json/smtGraph.jsonld";
419-
const TEXTS_PATH = "website/assets/json/texts.json";
418+
const isRoot = !window.location.pathname.includes('/website/');
419+
const basePath = isRoot ? 'website/' : '';
420+
const GRAPH_PATH = `${basePath}assets/json/smtGraph.jsonld`;
421+
const TEXTS_PATH = `${basePath}assets/json/texts.json`;
420422

421423
// ----- Constants for Mapping -----
422424
const MAJOR_NUMBER_MAP = {
@@ -482,7 +484,9 @@ document.addEventListener('DOMContentLoaded', () => {
482484
function githubUrlToLocal(url) {
483485
const marker = "website/";
484486
const idx = url.indexOf(marker);
485-
return idx !== -1 ? url.slice(idx) : url;
487+
let path = idx !== -1 ? url.slice(idx + marker.length) : url;
488+
if (path.startsWith('/')) path = path.slice(1);
489+
return `${basePath}${path}`;
486490
}
487491

488492
function graphIdToCardParam(graphId) {
@@ -532,6 +536,8 @@ document.addEventListener('DOMContentLoaded', () => {
532536
}
533537

534538
async function loadCardOfTheDay() {
539+
if (!document.getElementById("dailyCardImage")) return;
540+
535541
try {
536542
const [graphResponse, textsResponse] = await Promise.all([
537543
fetch(GRAPH_PATH),
@@ -570,7 +576,7 @@ document.addEventListener('DOMContentLoaded', () => {
570576
const title = selected.title || "Tarot Card";
571577
const localImg = githubUrlToLocal(selected.image_url?.["@id"] || "");
572578
const cardParam = graphIdToCardParam(selected["@id"] || "");
573-
const cardLink = `website/card.html?id=${cardParam}`;
579+
const cardLink = `${basePath}card.html?id=${cardParam}`;
574580

575581
// Update DOM
576582
const imgEl = document.getElementById("dailyCardImage");
@@ -598,7 +604,7 @@ document.addEventListener('DOMContentLoaded', () => {
598604
The mundane mirrored. <br>Explore the <span class="highlight">four suits</span> and their meanings.
599605
</h3>
600606
</div>
601-
<a href="website/deepening.html?id=suits_page" id="dailyCardDiscoverMore" class="discover-more">
607+
<a href="${basePath}deepening.html?id=suits_page" id="dailyCardDiscoverMore" class="discover-more">
602608
<span class="discover-svg">
603609
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
604610
<circle cx="4" cy="8" r="1.5"/><circle cx="8" cy="8" r="1.5"/><circle cx="12" cy="8" r="1.5"/>
@@ -628,7 +634,7 @@ document.addEventListener('DOMContentLoaded', () => {
628634
evolutionCards.forEach(evo => {
629635
const evoImg = githubUrlToLocal(evo.image_url?.["@id"] || "");
630636
const evoParam = graphIdToCardParam(evo["@id"] || "");
631-
const evoUrl = `website/card.html?id=${evoParam}`;
637+
const evoUrl = `${basePath}card.html?id=${evoParam}`;
632638
evoHtml += `
633639
<div class="mini-card-thumb">
634640
<a href="${evoUrl}">
@@ -639,7 +645,7 @@ document.addEventListener('DOMContentLoaded', () => {
639645
});
640646

641647
const archetypeParam = archetypeId ? graphIdToCardParam(archetypeId) : "";
642-
const archetypeLink = archetypeParam ? `website/deepening.html?id=${archetypeParam}` : cardLink;
648+
const archetypeLink = archetypeParam ? `${basePath}deepening.html?id=${archetypeParam}` : cardLink;
643649

644650
rightColHtml = `
645651
<div class="evolution-frame compact-evolution mt-0 mx-0">

0 commit comments

Comments
 (0)