mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-01 09:45:10 +00:00
w3c validation
This commit is contained in:
parent
cd9337f2d4
commit
249f06bd21
1 changed files with 31 additions and 16 deletions
|
@ -42,27 +42,36 @@ async function getClaimsFromChannel(claimId, count) {
|
||||||
return await doClaimSearch(options);
|
return await doClaimSearch(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFeed(channelClaim) {
|
async function getFeed(channelClaim, feedLink) {
|
||||||
const replaceLineFeeds = (str) => str.replace(/(?:\r\n|\r|\n)/g, '<br>');
|
const replaceLineFeeds = (str) => str.replace(/(?:\r\n|\r|\n)/g, '<br />');
|
||||||
|
const fmtDescription = (description) => replaceLineFeeds(description);
|
||||||
|
const sanitizeThumbsUrl = (url) => {
|
||||||
|
if (typeof url === 'string' && url.startsWith('https://')) {
|
||||||
|
return encodeURI(url).replace(/&/g, '%26');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
const value = channelClaim.value;
|
const value = channelClaim.value;
|
||||||
const title = value ? value.title : channelClaim.name;
|
const title = value ? value.title : channelClaim.name;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
title: title + ' on ' + SITE_NAME,
|
|
||||||
description: value && value.description ? replaceLineFeeds(value.description) : '',
|
|
||||||
link: `${URL}/${channelClaim.name}:${channelClaim.claim_id}`,
|
|
||||||
favicon: URL + '/public/favicon.png',
|
favicon: URL + '/public/favicon.png',
|
||||||
generator: SITE_NAME + ' RSS Feed',
|
generator: SITE_NAME + ' RSS Feed',
|
||||||
image: value && value.thumbnail ? value.thumbnail.url : '',
|
title: title + ' on ' + SITE_NAME,
|
||||||
|
description: fmtDescription(value && value.description ? value.description : ''),
|
||||||
|
link: encodeURI(`${URL}/${channelClaim.name}:${channelClaim.claim_id}`),
|
||||||
|
image: sanitizeThumbsUrl(value && value.thumbnail ? value.thumbnail.url : ''),
|
||||||
|
feedLinks: {
|
||||||
|
rss: encodeURI(feedLink),
|
||||||
|
},
|
||||||
author: {
|
author: {
|
||||||
name: channelClaim.name,
|
name: encodeURI(channelClaim.name),
|
||||||
link: URL + '/' + channelClaim.name + ':' + channelClaim.claim_id,
|
link: encodeURI(URL + '/' + channelClaim.name + ':' + channelClaim.claim_id),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const feed = new Feed(options);
|
const feed = new Feed(options);
|
||||||
|
|
||||||
const latestClaims = await getClaimsFromChannel(channelClaim.claim_id, NUM_ENTRIES);
|
const latestClaims = await getClaimsFromChannel(channelClaim.claim_id, NUM_ENTRIES);
|
||||||
|
|
||||||
latestClaims.forEach((c) => {
|
latestClaims.forEach((c) => {
|
||||||
|
@ -70,12 +79,12 @@ async function getFeed(channelClaim) {
|
||||||
const value = c.value;
|
const value = c.value;
|
||||||
|
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
guid: c.claim_id,
|
|
||||||
id: c.claim_id,
|
id: c.claim_id,
|
||||||
title: value ? value.title : c.name,
|
guid: encodeURI(URL + '/' + c.name + ':' + c.claim_id),
|
||||||
description: value && value.description ? replaceLineFeeds(value.description) : '',
|
title: value && value.title ? value.title : c.name,
|
||||||
image: value && value.thumbnail ? value.thumbnail.url : '',
|
description: fmtDescription(value && value.description ? value.description : ''),
|
||||||
link: URL + '/' + c.name + ':' + c.claim_id,
|
image: sanitizeThumbsUrl(value && value.thumbnail ? value.thumbnail.url : ''),
|
||||||
|
link: encodeURI(URL + '/' + c.name + ':' + c.claim_id),
|
||||||
date: new Date(meta ? meta.creation_timestamp * 1000 : null),
|
date: new Date(meta ? meta.creation_timestamp * 1000 : null),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -83,6 +92,12 @@ async function getFeed(channelClaim) {
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postProcess(feed) {
|
||||||
|
// Handle 'Feed' creating an invalid MIME type when trying to guess
|
||||||
|
// from 'https://thumbnails.lbry.com/UCgQ8eREJzR1dO' style of URLs.
|
||||||
|
return feed.replace(/type="image\/\/.*"\/>/g, 'type="image/*"/>');
|
||||||
|
}
|
||||||
|
|
||||||
async function getRss(ctx) {
|
async function getRss(ctx) {
|
||||||
if (!ctx.params.claimName || !ctx.params.claimId) {
|
if (!ctx.params.claimName || !ctx.params.claimId) {
|
||||||
return 'Invalid URL';
|
return 'Invalid URL';
|
||||||
|
@ -93,8 +108,8 @@ async function getRss(ctx) {
|
||||||
return channelClaim;
|
return channelClaim;
|
||||||
}
|
}
|
||||||
|
|
||||||
const feed = await getFeed(channelClaim);
|
const feed = await getFeed(channelClaim, `${URL}/$/rss/${ctx.params.claimName}/${ctx.params.claimId}`);
|
||||||
return feed.rss2();
|
return postProcess(feed.rss2());
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getRss };
|
module.exports = { getRss };
|
||||||
|
|
Loading…
Add table
Reference in a new issue