Skip to content

Commit

Permalink
Search!
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Feb 18, 2024
1 parent 86ff2dc commit 393b54f
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions artists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=yes">
<title>#listeningclub artist search</title>
</head>
<script>
async function fetchArtistsFromEntries() {
const tsv = await fetch("./entries.tsv");
const data = await tsv.text();
const rows = data.split("\n").map(r => r.split("\t"));
return rows.filter(r => r.length === 4 && !r[1].search(/^#.+vortex/i)).map(r => [r[3], r[0]]);
}

const seps = [" / ", " - ", " – ", " by "];

async function fetchArtistsFromVortices() {
const tsv = await fetch("./vortices.txt");
const data = await tsv.text();
let vortex = null;
const results = [];
for (let line of data.split("\n")) {
if (!line.trim().length) {
continue;
}
if (line.startsWith("#")) {
vortex = line;
continue;
}
if (line.startsWith("Date:")) {
continue;
}
line = line.replace(/^\d+[\s.:]*/g, '');
let found = false;
for (const sep of seps) {
if (line.includes(sep)) {
results.push([line.split(sep)[0], vortex]);
found = true;
break;
}
}
if (!found) {
console.log("Unable to parse:", line);
}
}
return results;
}

async function loadData() {
const artists = new Map();
const add = (artist, source) => {
if (artist === "Various" || artist === "Artist") {
return;
}
if (!artist) return;
if (!artists.has(artist)) {
artists.set(artist, new Set());
}
artists.get(artist).add(source);
};
for (const [artist, date] of await fetchArtistsFromEntries()) {
add(artist, date);
}
for (const [artist, vortex] of await fetchArtistsFromVortices()) {
add(artist, vortex);
}
return artists;
}

let artists = new Map();

function update() {
const ul = document.getElementById("artists");
const filter = (document.getElementById("filter").value ?? "").toLowerCase().trim();
const matching = Array.from(artists.keys()).filter(a => a ? a.toLowerCase().includes(filter) : true).sort();

const info = document.getElementById("info");
info.textContent = `Showing ${matching.length} of ${artists.size} artists.`;
ul.innerHTML = "";
for (const artist of matching) {
const sources = Array.from(artists.get(artist)).sort();
const li = document.createElement("li");
li.textContent = artist + " (" + sources.join(", ") + ")";
ul.appendChild(li);
}
}

async function init() {
artists = await loadData();
update();
}
</script>
<style>
* {
box-sizing: border-box;
}

body {
font-family: sans-serif;
font-size: 10pt;
line-height: 1.4;
}

main {
max-width: 60em;
margin: auto;
}

input {
width: 100%;
padding: 1em;
}
</style>
<body onload="init()">
<main>
<input type="search" id="filter" placeholder="Filter..." autofocus oninput="update()">
<p id="info"></p>
<ul id="artists"></ul>
</main>
</body>
</html>

0 comments on commit 393b54f

Please sign in to comment.