Use playlist's page title as link text

This commit is contained in:
Maciej Pędzich 2024-11-23 19:45:20 +01:00
parent 4ecd9df628
commit 66531d5b54
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D

View File

@ -132,7 +132,11 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
if (found) { if (found) {
const html = await spotifyResponse.text(); const html = await spotifyResponse.text();
const { author: authorUrl, description } = await getMetaData({ const {
author: authorUrl,
description,
title
} = await getMetaData({
html, html,
customRules: { customRules: {
author: { author: {
@ -146,32 +150,33 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
} }
}); });
let authorName = (authorUrl as string).endsWith('/user/spotify') // let authorName = (authorUrl as string).endsWith('/user/spotify')
? 'Spotify' // ? 'Spotify'
: ''; // : '';
if (authorName === '') { // if (authorName === '') {
const playlistAuthorResponse = await fetch(authorUrl as string); // const playlistAuthorResponse = await fetch(authorUrl as string);
if (!playlistAuthorResponse.ok) // if (!playlistAuthorResponse.ok)
throw new Error( // throw new Error(
`Received ${playlistAuthorResponse.status} status code from ${authorUrl}` // `Received ${playlistAuthorResponse.status} status code from ${authorUrl}`
); // );
const authorPageHtml = await playlistAuthorResponse.text(); // const authorPageHtml = await playlistAuthorResponse.text();
const { title: authorPageTitle } = await getMetaData({ // const { title: authorPageTitle } = await getMetaData({
html: authorPageHtml // html: authorPageHtml
}); // });
authorName = authorPageTitle as string; // authorName = authorPageTitle as string;
} // }
const playlistMeta = (description || '') // const playlistMeta = (description || '')
.split(' · ') // .split(' · ')
.filter((text) => text !== 'Playlist') // .filter((text) => text !== 'Playlist')
.concat(authorName as string); // .concat(authorName as string);
details = playlistMeta.join(' · '); // details = playlistMeta.join(' · ');
details = title!;
} }
numProcessedEntries++; numProcessedEntries++;