Skip to content

Commit 383e5b5

Browse files
refactor: remove duplicated code
1 parent ce234ae commit 383e5b5

15 files changed

+301
-331
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default [
2020
"base_url": "readonly",
2121
"base_path": "readonly",
2222
"igdbImageUrl": "readonly",
23+
"getRegionFlag": "readonly",
2324
"makeBadge": "readonly",
2425
"addDlRow": "readonly",
2526
"loadItemDetail": "readonly",

gh-pages-template/assets/js/collection_detail.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

gh-pages-template/assets/js/franchise_detail.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

gh-pages-template/assets/js/game_detail.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,27 +434,6 @@ function renderCharacters(data) {
434434
}
435435
}
436436

437-
/**
438-
* Map region string (from release_region.region) to an emoji flag.
439-
* @param {string} regionName
440-
* @returns {string}
441-
*/
442-
function getRegionFlag(regionName) {
443-
const map = {
444-
"europe": "🇪🇺",
445-
"north_america": "🇺🇸",
446-
"australia": "🇦🇺",
447-
"new_zealand": "🇳🇿",
448-
"japan": "🇯🇵",
449-
"china": "🇨🇳",
450-
"asia": "🌏",
451-
"worldwide": "🌍",
452-
"korea": "🇰🇷",
453-
"brazil": "🇧🇷",
454-
};
455-
return map[regionName] || "🌐";
456-
}
457-
458437
/**
459438
* Initialize game banner with cycling images (mimics beautiful-jekyll-next behavior)
460439
*/
@@ -551,7 +530,6 @@ if (typeof module !== "undefined") {
551530
renderVideos,
552531
renderExternalLinks,
553532
renderCharacters,
554-
getRegionFlag,
555533
initGameBanner,
556534
};
557535
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* group_detail.js
3+
* Renders a single collection (series) or franchise detail page.
4+
* Depends on item_detail.js being loaded first.
5+
*
6+
* The page must define a `GAMEDB_GROUP_TYPE` global before loading this script:
7+
* <script>globalThis.GAMEDB_GROUP_TYPE = "collection";</script> (for collections)
8+
* <script>globalThis.GAMEDB_GROUP_TYPE = "franchise";</script> (for franchises)
9+
*
10+
* Expected DOM element IDs follow the pattern `<type>-*`, e.g.:
11+
* collection-name, collection-igdb-link, collection-games-section, collection-games
12+
* franchise-name, franchise-igdb-link, franchise-games-section, franchise-games
13+
*/
14+
15+
const GROUP_CONFIG = {
16+
collection: {
17+
endpoint: "collections",
18+
defaultTitle: "Series",
19+
defaultName: "Unknown Series",
20+
},
21+
franchise: {
22+
endpoint: "franchises",
23+
defaultTitle: "Franchise",
24+
defaultName: "Unknown Franchise",
25+
},
26+
};
27+
28+
function renderGroup(data) {
29+
const type = globalThis.GAMEDB_GROUP_TYPE || "collection";
30+
const config = GROUP_CONFIG[type];
31+
32+
document.title = (data.name || config.defaultTitle) + " – GameDB";
33+
document.getElementById(`${type}-name`).textContent = data.name || config.defaultName;
34+
35+
// IGDB link
36+
if (data.url) {
37+
const igdbLink = document.getElementById(`${type}-igdb-link`);
38+
igdbLink.href = data.url;
39+
igdbLink.classList.remove("d-none");
40+
}
41+
42+
// Games
43+
if (data.games && data.games.length > 0) {
44+
const section = document.getElementById(`${type}-games-section`);
45+
section.classList.remove("d-none");
46+
renderGameList(document.getElementById(`${type}-games`), data.games);
47+
}
48+
}
49+
50+
document.addEventListener("DOMContentLoaded", () => {
51+
const type = globalThis.GAMEDB_GROUP_TYPE || "collection";
52+
const config = GROUP_CONFIG[type];
53+
loadItemDetail(config.endpoint, renderGroup);
54+
});
55+
56+
/* istanbul ignore next */
57+
if (typeof module !== "undefined") {
58+
module.exports = {
59+
GROUP_CONFIG,
60+
renderGroup,
61+
};
62+
}

gh-pages-template/assets/js/item_detail.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010
* window.GAMEDB_CONFIG = { base_path: "{{ site.baseurl }}", base_url: "{{ site.url }}{{ site.baseurl }}" };
1111
*/
1212

13+
/**
14+
* Map a release region string (from release_region.region) to an emoji flag.
15+
* @param {string} regionName
16+
* @returns {string}
17+
*/
18+
function getRegionFlag(regionName) {
19+
const map = {
20+
"europe": "🇪🇺",
21+
"north_america": "🇺🇸",
22+
"australia": "🇦🇺",
23+
"new_zealand": "🇳🇿",
24+
"japan": "🇯🇵",
25+
"china": "🇨🇳",
26+
"asia": "🌏",
27+
"worldwide": "🌍",
28+
"korea": "🇰🇷",
29+
"brazil": "🇧🇷",
30+
};
31+
return map[regionName] || "🌐";
32+
}
33+
1334
const base_path = (globalThis.GAMEDB_CONFIG?.base_path
1435
? ("/" + globalThis.GAMEDB_CONFIG.base_path).replaceAll(/\/+/g, "/").replace(/\/$/, "")
1536
: "/GameDB");
@@ -235,6 +256,7 @@ if (typeof module !== "undefined") {
235256
module.exports = {
236257
getQueryParam,
237258
igdbImageUrl,
259+
getRegionFlag,
238260
makeBadge,
239261
addDlRow,
240262
showError,

gh-pages-template/assets/js/platform_detail.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ const CATEGORY_NAMES = {
2626
6: "Computer",
2727
};
2828

29-
function getRegionFlag(regionName) {
30-
const map = {
31-
"europe": "🇪🇺",
32-
"north_america": "🇺🇸",
33-
"australia": "🇦🇺",
34-
"new_zealand": "🇳🇿",
35-
"japan": "🇯🇵",
36-
"china": "🇨🇳",
37-
"asia": "🌏",
38-
"worldwide": "🌍",
39-
"korea": "🇰🇷",
40-
"brazil": "🇧🇷",
41-
};
42-
return map[regionName] || "🌐";
43-
}
44-
4529
/**
4630
* Render platform logo or placeholder
4731
*/
@@ -257,7 +241,6 @@ document.addEventListener("DOMContentLoaded", () => {
257241
/* istanbul ignore next */
258242
if (typeof module !== "undefined") {
259243
module.exports = {
260-
getRegionFlag,
261244
renderPlatformLogo,
262245
renderPlatformBadges,
263246
renderPlatformMetadata,

gh-pages-template/browse/collections.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- /assets/css/hide-heading.css
77
js:
88
- /GameDB/assets/js/item_detail.js
9-
- /GameDB/assets/js/collection_detail.js
9+
- /GameDB/assets/js/group_detail.js
1010
ext-css:
1111
- href: https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200
1212
---
@@ -15,6 +15,7 @@
1515
globalThis.GAMEDB_CONFIG = {
1616
base_path: "{{ site.baseurl }}"
1717
};
18+
globalThis.GAMEDB_GROUP_TYPE = "collection";
1819
</script>
1920

2021
<div id="item-loading" class="text-center py-5">

gh-pages-template/browse/franchises.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- /assets/css/hide-heading.css
77
js:
88
- /GameDB/assets/js/item_detail.js
9-
- /GameDB/assets/js/franchise_detail.js
9+
- /GameDB/assets/js/group_detail.js
1010
ext-css:
1111
- href: https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200
1212
---
@@ -15,6 +15,7 @@
1515
globalThis.GAMEDB_CONFIG = {
1616
base_path: "{{ site.baseurl }}"
1717
};
18+
globalThis.GAMEDB_GROUP_TYPE = "franchise";
1819
</script>
1920

2021
<div id="item-loading" class="text-center py-5">

tests/collection_detail.test.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)