Simplified component

This commit is contained in:
Logan 2024-09-07 19:35:31 -05:00
parent 4278156e4a
commit b9ce32ea8d
3 changed files with 141 additions and 185 deletions

View file

@ -1,52 +1,36 @@
function createH2(headerName) { async function figureGrid(jsonURL) {
return `<h2>${headerName}</h2><section>`; const response = await fetch(jsonURL);
} const json = await response.json();
function createFigure(imageURL, heading, subheading) {
return `<figure>
<img src="${imageURL}">
<figcaption>
<b>${heading}</b><br>
<em>${subheading}</em>
</figcaption>
</figure>`;
}
function createSection(headerName, figureArray) {
let figuresHTML = "";
for (let i = 0; i < figureArray.length; i++) {
let figure = figureArray[i];
figuresHTML = figuresHTML.concat(
createFigure(figure.url, figure.main, figure.sub)
);
}
return `<section>${figuresHTML}</section>`
}
function figureGrid(jsonURL, targetID) {
fetch(source)
.then((response) => response.json())
.then((json) => {
let html = ""; let html = "";
for (const headerName in json) { for (const headerName in json) {
let figureArray = json[category]; html = html.concat("<section>")
html = html.concat(createSection(headerName, figureArray)); let entries = json[headerName];
for (let i = 0; i < entries.length; i++) {
let entry = entries[i];
html = html.concat(
`<figure>
<img src="${entry.url}">
<figcaption>
<b>${entry.main}</b><br>
<em>${entry.sub}</em>
</figcaption>
</figure>`
);
}
html = html.concat("</section>")
} }
const thisScript = document.getElementById("albums");
return html; return html;
});
} }
class FigureGrid extends HTMLElement { class FigureGrid extends HTMLElement {
static observedAttributes = ["src"]; static observedAttributes = ["src"];
constructor() { constructor() {
super(); super();
this._internals = this.attachInternals();
} }
attributeChangedCallback(name, oldValue, newValue) { async attributeChangedCallback(name, oldValue, newValue) {
if (name == "src") { if (name == "src") {
this.innerHTML = this.innerHTML = await figureGrid(newValue);
} }
} }
} }

View file

@ -1,207 +1,207 @@
{ {
"chill": [ "chill": [
{ {
"name": "Cosmos", "main": "Cosmos",
"artist": "Yuji Ohno", "sub": "Yuji Ohno",
"link": "cosmos" "url": "/res/albums/cosmos.webp"
}, },
{ {
"name": "Deep Breakfast", "main": "Deep Breakfast",
"artist": "Ray Lynch", "sub": "Ray Lynch",
"link": "deep_breakfast" "url": "/res/albums/deep_breakfast.webp"
}, },
{ {
"name": "Dune", "main": "Dune",
"artist": "David Matthews", "sub": "David Matthews",
"link": "dune" "url": "/res/albums/dune.webp"
}, },
{ {
"name": "God's Trashmen Sent to Right the Mess", "main": "God's Trashmen Sent to Right the Mess",
"artist": "Fievel is Glauque", "sub": "Fievel is Glauque",
"link": "gods_trashmen" "url": "/res/albums/gods_trashmen.webp"
}, },
{ {
"name": "MACROCOSM", "main": "MACROCOSM",
"artist": "BALTHVS", "sub": "BALTHVS",
"link": "macrocosm" "url": "/res/albums/macrocosm.webp"
}, },
{ {
"name": "Ciao! Baby", "main": "Ciao! Baby",
"artist": "The Marshmallow Kisses", "sub": "The Marshmallow Kisses",
"link": "ciao_baby" "url": "/res/albums/ciao_baby.webp"
}, },
{ {
"name": "an anxious object", "main": "an anxious object",
"artist": "mouse on the keys", "sub": "mouse on the keys",
"link": "mouse_on_the_keys" "url": "/res/albums/mouse_on_the_keys.webp"
}, },
{ {
"name": "Funky Stuff", "main": "Funky Stuff",
"artist": " Jiro Inagaki", "sub": " Jiro Inagaki",
"link": "funky_stuff" "url": "/res/albums/funky_stuff.webp"
}, },
{ {
"name": "Make Up City", "main": "Make Up City",
"artist": "CASIOPEA", "sub": "CASIOPEA",
"link": "make_up_city" "url": "/res/albums/make_up_city.webp"
}, },
{ {
"name": "Mint Jams", "main": "Mint Jams",
"artist": "CASIOPEA", "sub": "CASIOPEA",
"link": "mint_jams" "url": "/res/albums/mint_jams.webp"
} }
], ],
"experimental": [ "experimental": [
{ {
"name": "Departing", "main": "Departing",
"artist": "Jesus Molina", "sub": "Jesus Molina",
"link": "departing" "url": "/res/albums/departing.webp"
}, },
{ {
"name": "Choose your Weapon", "main": "Choose your Weapon",
"artist": "Hiatus Kaiyote", "sub": "Hiatus Kaiyote",
"link": "choose_your_weapon" "url": "/res/albums/choose_your_weapon.webp"
}, },
{ {
"name": "Hold Your Horse Is", "main": "Hold Your Horse Is",
"artist": "Hella", "sub": "Hella",
"link": "hold_your_horse_is" "url": "/res/albums/hold_your_horse_is.webp"
}, },
{ {
"name": "Mother Earth's Plantasia", "main": "Mother Earth's Plantasia",
"artist": "Mort Garson", "sub": "Mort Garson",
"link": "plantasia" "url": "/res/albums/plantasia.webp"
}, },
{ {
"name": "The Wozard of Iz - An Electronic Odyssey", "main": "The Wozard of Iz - An Electronic Odyssey",
"artist": "Mort Garson", "sub": "Mort Garson",
"link": "wozard_of_iz" "url": "/res/albums/wozard_of_iz.webp"
}, },
{ {
"name": "Los Desamores de Dewey Martino", "main": "Los Desamores de Dewey Martino",
"artist": "Dewey Martino", "sub": "Dewey Martino",
"link": "los_desamores_de_dewey_martino" "url": "/res/albums/los_desamores_de_dewey_martino.webp"
}, },
{ {
"name": "New History Warfare Vol. 3: To See More Light", "main": "New History Warfare Vol. 3: To See More Light",
"artist": "Colin Stetson", "sub": "Colin Stetson",
"link": "new_history_warfare_3" "url": "/res/albums/new_history_warfare_3.webp"
}, },
{ {
"name": "Hylics 2 Original Soundtrack", "main": "Hylics 2 Original Soundtrack",
"artist": "Chuck Salamone", "sub": "Chuck Salamone",
"link": "hylics2" "url": "/res/albums/hylics2.webp"
} }
], ],
"electronic": [ "electronic": [
{ {
"name": "H.A.Q.Q.", "main": "H.A.Q.Q.",
"artist": "Liturgy", "sub": "Liturgy",
"link": "haqq" "url": "/res/albums/haqq.webp"
}, },
{ {
"name": "One Year Madness", "main": "One Year Madness",
"artist": "Golemm", "sub": "Golemm",
"link": "one_year_madness" "url": "/res/albums/one_year_madness.webp"
}, },
{ {
"name": "Cyberspace", "main": "Cyberspace",
"artist": "Yameii Online", "sub": "Yameii Online",
"link": "cyberspace" "url": "/res/albums/cyberspace.webp"
}, },
{ {
"name": "Wlfgrl", "main": "Wlfgrl",
"artist": "Machine Girl", "sub": "Machine Girl",
"link": "wlfgrl" "url": "/res/albums/wlfgrl.webp"
}, },
{ {
"name": "...Because I'm Young Arrogant and Hate Everything You Stand For", "main": "...Because I'm Young Arrogant and Hate Everything You Stand For",
"artist": "Machine Girl", "sub": "Machine Girl",
"link": "young_arrogant" "url": "/res/albums/young_arrogant.webp"
}, },
{ {
"name": "Parousia", "main": "Parousia",
"artist": "XI", "sub": "XI",
"link": "parousia" "url": "/res/albums/parousia.webp"
}, },
{ {
"name": "www.", "main": "www.",
"artist": "cosmic collective", "sub": "cosmic collective",
"link": "www" "url": "/res/albums/www.webp"
}, },
{ {
"name": "TMP2", "main": "TMP2",
"artist": "Graham Kartna", "sub": "Graham Kartna",
"link": "tmp2" "url": "/res/albums/tmp2.webp"
} }
], ],
"high energy": [ "high energy": [
{ {
"name": "Each and Every Word Leaves Me Here Alone", "main": "Each and Every Word Leaves Me Here Alone",
"artist": "Foreground Eclipse", "sub": "Foreground Eclipse",
"link": "fge_1" "url": "/res/albums/fge_1.webp"
}, },
{ {
"name": "Missing, Loving, Suffering", "main": "Missing, Loving, Suffering",
"artist": "Foreground Eclipse", "sub": "Foreground Eclipse",
"link": "fge_2" "url": "/res/albums/fge_2.webp"
}, },
{ {
"name": "ITEKOMA HITS", "main": "ITEKOMA HITS",
"artist": "Otoboke Beaver", "sub": "Otoboke Beaver",
"link": "itekoma_hits" "url": "/res/albums/itekoma_hits.webp"
}, },
{ {
"name": "World is Yours", "main": "World is Yours",
"artist": "MASS OF THE FERMENTING DREGS", "sub": "MASS OF THE FERMENTING DREGS",
"link": "world_is_yours" "url": "/res/albums/world_is_yours.webp"
}, },
{ {
"name": "New Levels New Devils", "main": "New Levels New Devils",
"artist": "Polyphia", "sub": "Polyphia",
"link": "new_levels_new_devils" "url": "/res/albums/new_levels_new_devils.webp"
} }
], ],
"misc": [ "misc": [
{ {
"name": "27 Demos", "main": "27 Demos",
"artist": "Margo Guryan ", "sub": "Margo Guryan ",
"link": "27_demos" "url": "/res/albums/27_demos.webp"
}, },
{ {
"name": "the first glass beach album", "main": "the first glass beach album",
"artist": "Glass Beach", "sub": "Glass Beach",
"link": "glass_beach" "url": "/res/albums/glass_beach.webp"
}, },
{ {
"name": "Her Abiding Memory", "main": "Her Abiding Memory",
"artist": "Pitcher56", "sub": "Pitcher56",
"link": "her_abiding_memory" "url": "/res/albums/her_abiding_memory.webp"
}, },
{ {
"name": "High Society", "main": "High Society",
"artist": "Enon", "sub": "Enon",
"link": "high_society" "url": "/res/albums/high_society.webp"
}, },
{ {
"name": "Live at Bush Hall", "main": "Live at Bush Hall",
"artist": "Black Country, New Road", "sub": "Black Country, New Road",
"link": "live_at_bush_hall" "url": "/res/albums/live_at_bush_hall.webp"
}, },
{ {
"name": "Mass Teen Fainting", "main": "Mass Teen Fainting",
"artist": "Plumtree", "sub": "Plumtree",
"link": "mass_teen_fainting" "url": "/res/albums/mass_teen_fainting.webp"
}, },
{ {
"name": "My Caution Line", "main": "My Caution Line",
"artist": "Citrobal", "sub": "Citrobal",
"link": "my_caution_line" "url": "/res/albums/my_caution_line.webp"
}, },
{ {
"name": "Oncle Jazz", "main": "Oncle Jazz",
"artist": "Men I Trust", "sub": "Men I Trust",
"link": "oncle_jazz" "url": "/res/albums/oncle_jazz.webp"
} }
] ]
} }

View file

@ -2,33 +2,5 @@
Music is a huge passion of mine. I prefer listening to albums in full from Music is a huge passion of mine. I prefer listening to albums in full from
start to finish in order. My favorite albums are usually experimental, unique, start to finish in order. My favorite albums are usually experimental, unique,
or have a particular theme they explore or have a particular theme they explore
<script id="albums">
const thisScript = document.getElementById("albums");
fetch("/music/albums.json")
.then((response) => response.json())
.then((json) => {
let html = "";
for (const category in json) {
let albums = json[category];
html = html.concat(`<h2>${category}</h2><section>`);
for (let i = 0; i < albums.length; i++) {
let album = albums[i];
let link = "/res/albums/" + album.link + ".webp";
let name = album.name;
let artist = album.artist;
let template = `<figure>
<img src="${link}">
<figcaption>
<b>${name}</b><br/><em>${artist}</em>
</figcaption>
</figure>`;
html = html.concat(template);
}
html = html.concat("</section>")
}
let section = document.createElement("div");
section.innerHTML = html;
thisScript.replaceWith(section); // lol
});
</script>
<figure-grid src="/music/albums.json"></figure-grid> <figure-grid src="/music/albums.json"></figure-grid>