Add icons to known links (#6).
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 15 KiB |
|
@ -45,9 +45,10 @@
|
||||||
|
|
||||||
.release-link {
|
.release-link {
|
||||||
a {
|
a {
|
||||||
|
align-items: center;
|
||||||
background-color: var(--background-1);
|
background-color: var(--background-1);
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
display: block;
|
display: flex;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
|
@ -55,4 +56,10 @@
|
||||||
background-color: var(--foreground-1);
|
background-color: var(--foreground-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
height: 3rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,14 +71,20 @@ export default class ReleasePage extends Component<Props, State> {
|
||||||
? undefined
|
? undefined
|
||||||
: html`<img class="cover-art" src="${release.image}" />`;
|
: html`<img class="cover-art" src="${release.image}" />`;
|
||||||
|
|
||||||
const urls = release.links.map(
|
const urls = release.links.map((link) => {
|
||||||
(link) =>
|
let linkImage;
|
||||||
html`
|
if (link.icon !== undefined) {
|
||||||
|
linkImage = html`<img src="/assets/icons/${link.icon}" />`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
<li class="release-link">
|
<li class="release-link">
|
||||||
<${ExternalAnchor} url="${link.original}" text="${link.text}" />
|
<a href="${link.original}" rel="noopener noreferrer">
|
||||||
|
${linkImage} ${link.text}
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
`,
|
`;
|
||||||
);
|
});
|
||||||
|
|
||||||
const releaseUrl = `https://musicbrainz.org/release/${mbid}`;
|
const releaseUrl = `https://musicbrainz.org/release/${mbid}`;
|
||||||
if (urls.length === 0) {
|
if (urls.length === 0) {
|
||||||
|
|
|
@ -1,57 +1,71 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"icon": "7digital.png",
|
||||||
"regex": "7digital\\.com$",
|
"regex": "7digital\\.com$",
|
||||||
"text": "7digital"
|
"text": "7digital"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "amazon.png",
|
||||||
"regex": "amazon\\.com$",
|
"regex": "amazon\\.com$",
|
||||||
"text": "Amazon"
|
"text": "Amazon"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "apple-music.png",
|
||||||
"regex": "(itunes|music)\\.apple\\.com$",
|
"regex": "(itunes|music)\\.apple\\.com$",
|
||||||
"text": "Apple Music"
|
"text": "Apple Music"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "bandcamp.png",
|
||||||
"regex": "bandcamp\\.com$",
|
"regex": "bandcamp\\.com$",
|
||||||
"text": "Bandcamp"
|
"text": "Bandcamp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "beatport.png",
|
||||||
"regex": "beatport\\.com$",
|
"regex": "beatport\\.com$",
|
||||||
"text": "Beatport"
|
"text": "Beatport"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "deezer.png",
|
||||||
"regex": "deezer\\.com$",
|
"regex": "deezer\\.com$",
|
||||||
"text": "Deezer"
|
"text": "Deezer"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "discogs.png",
|
||||||
"regex": "discogs\\.com$",
|
"regex": "discogs\\.com$",
|
||||||
"text": "Discogs"
|
"text": "Discogs"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "monstercat-music.jpg",
|
||||||
"regex": "music\\.monstercat\\.com$",
|
"regex": "music\\.monstercat\\.com$",
|
||||||
"text": "Monstercat Music"
|
"text": "Monstercat Music"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "qobuz.png",
|
||||||
"regex": "qobuz\\.com$",
|
"regex": "qobuz\\.com$",
|
||||||
"text": "Qobuz"
|
"text": "Qobuz"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "soundcloud.png",
|
||||||
"regex": "soundcloud\\.com$",
|
"regex": "soundcloud\\.com$",
|
||||||
"text": "SoundCloud"
|
"text": "SoundCloud"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "spotify.png",
|
||||||
"regex": "spotify\\.com$",
|
"regex": "spotify\\.com$",
|
||||||
"text": "Spotify"
|
"text": "Spotify"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "tidal.png",
|
||||||
"regex": "tidal\\.com$",
|
"regex": "tidal\\.com$",
|
||||||
"text": "Tidal"
|
"text": "Tidal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "youtube-music.png",
|
||||||
"regex": "music\\.youtube\\.com$",
|
"regex": "music\\.youtube\\.com$",
|
||||||
"text": "YouTube Music"
|
"text": "YouTube Music"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"icon": "youtube.png",
|
||||||
"__comment": "Make sure we don't match the YouTube Music sub-domain",
|
"__comment": "Make sure we don't match the YouTube Music sub-domain",
|
||||||
"regex": "^(www\\.)?(youtu\\.be|youtube\\.com)$",
|
"regex": "^(www\\.)?(youtu\\.be|youtube\\.com)$",
|
||||||
"text": "YouTube"
|
"text": "YouTube"
|
||||||
|
|
|
@ -8,16 +8,19 @@
|
||||||
import knownLinks from './known-links.json';
|
import knownLinks from './known-links.json';
|
||||||
|
|
||||||
type KnownLink = {
|
type KnownLink = {
|
||||||
|
icon: string | undefined;
|
||||||
regex: RegExp;
|
regex: RegExp;
|
||||||
text: string;
|
text: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const known: KnownLink[] = knownLinks.map((data: Record<string, unknown>) => ({
|
const known: KnownLink[] = knownLinks.map((data: Record<string, unknown>) => ({
|
||||||
|
icon: data.icon as string | undefined,
|
||||||
regex: new RegExp(data.regex as string),
|
regex: new RegExp(data.regex as string),
|
||||||
text: data.text as string,
|
text: data.text as string,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default class RelationLink {
|
export default class RelationLink {
|
||||||
|
public readonly icon: string | undefined;
|
||||||
public readonly isKnown: boolean;
|
public readonly isKnown: boolean;
|
||||||
public readonly link: URL;
|
public readonly link: URL;
|
||||||
public readonly original: string;
|
public readonly original: string;
|
||||||
|
@ -28,6 +31,7 @@ export default class RelationLink {
|
||||||
this.link = new URL(relationUrl);
|
this.link = new URL(relationUrl);
|
||||||
|
|
||||||
const knownLink = known.find(({regex}) => regex.test(this.link.host));
|
const knownLink = known.find(({regex}) => regex.test(this.link.host));
|
||||||
|
this.icon = knownLink?.icon;
|
||||||
this.isKnown = knownLink !== undefined;
|
this.isKnown = knownLink !== undefined;
|
||||||
this.text = knownLink?.text ?? this.link.host;
|
this.text = knownLink?.text ?? this.link.host;
|
||||||
}
|
}
|
||||||
|
|