Make unknown links sorted at the bottom.
This commit is contained in:
parent
e3faf966df
commit
aeb3baaca2
|
@ -18,6 +18,7 @@ const known: KnownLink[] = knownLinks.map((data: Record<string, unknown>) => ({
|
|||
}));
|
||||
|
||||
export default class RelationLink {
|
||||
public readonly isKnown: boolean;
|
||||
public readonly link: URL;
|
||||
public readonly original: string;
|
||||
public readonly text: string;
|
||||
|
@ -27,6 +28,7 @@ export default class RelationLink {
|
|||
this.link = new URL(relationUrl);
|
||||
|
||||
const knownLink = known.find(({regex}) => regex.test(this.link.host));
|
||||
this.isKnown = knownLink !== undefined;
|
||||
this.text = knownLink?.text ?? this.link.host;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,14 @@ export default class Release {
|
|||
);
|
||||
const links = Array.from(relations)
|
||||
.map((url) => new RelationLink(url))
|
||||
.sort((a, b) => a.text.localeCompare(b.text));
|
||||
.sort((a, b) =>
|
||||
// Sort links that aren't known to us at the bottom.
|
||||
a.isKnown === b.isKnown
|
||||
? a.text.localeCompare(b.text)
|
||||
: b.isKnown
|
||||
? 1 // This return 1 or -1 is because .sort() expects a number.
|
||||
: -1,
|
||||
);
|
||||
|
||||
return new Release({
|
||||
artist,
|
||||
|
|
Loading…
Reference in New Issue