Restore metadata back to simple objects

The fn version was only needed for Search Page, and that was making it hard to move the metadata to the homepage repo.

Revert back to original, then handle Search separately.
This commit is contained in:
infinite-persistence 2022-04-13 19:59:18 +08:00
parent e9214be2c1
commit 3f1417a412
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 62 additions and 45 deletions

View file

@ -3,90 +3,79 @@ const PAGES = require('../../ui/constants/pages');
// Uncomment as you add metadata
module.exports.CATEGORY_METADATA = {
// [PAGES.ARTISTS]: () => ({
// [PAGES.ARTISTS]: {
// title: 'Artists',
// description: "", <------ FILL
// image: '', <------ FILL
// }),
[PAGES.CREATIVE_ARTS]: () => ({
// },
[PAGES.CREATIVE_ARTS]: {
title: 'The Arts',
description: `Odysee's home for art, animation, comedy, and everything inbetween`,
image: '',
}),
[PAGES.EDUCATION]: () => ({
},
[PAGES.EDUCATION]: {
title: 'Education',
description: `Who needs school when there's Odysee?`,
image: '',
}),
[PAGES.FEATURED]: () => ({
},
[PAGES.FEATURED]: {
title: 'Featured',
description: 'Showcasing some of the best content Odysee has to offer',
image: '',
}),
[PAGES.FINANCE]: () => ({
},
[PAGES.FINANCE]: {
title: 'Finance 2.0',
description: 'Crypto, Money, Economics, Markets on Odysee',
image: 'https://player.odycdn.com/speech/category-finance:c.jpg',
}),
[PAGES.GAMING]: () => ({
},
[PAGES.GAMING]: {
title: 'Gaming',
description: 'Pew pew bzzz gaming on Odysee',
image: 'https://player.odycdn.com/speech/category-gaming:5.jpg',
}),
[PAGES.GENERAL]: () => ({
},
[PAGES.GENERAL]: {
title: 'Cheese',
description: 'Cheese is the answer to life, the universe, and everything. We have primo cheese on Odysee',
image: 'https://player.odycdn.com/speech/category-primary1:5.jpg',
}),
[PAGES.LAB]: () => ({
},
[PAGES.LAB]: {
title: 'Lab',
description: 'Science - the real kind, on Odysee',
image: '',
}),
[PAGES.NEWS]: () => ({
},
[PAGES.NEWS]: {
title: 'News & Politics',
description: `Stay up to date with all that's happening around the world on Odysee`,
image: '',
}),
[PAGES.MOVIES]: () => ({
},
[PAGES.MOVIES]: {
title: 'Movies',
description: `Do you love B rated movies? We've got you covered on Odysee`,
image: 'https://player.odycdn.com/speech/category-movies:2.jpg',
}),
[PAGES.MUSIC]: () => ({
},
[PAGES.MUSIC]: {
title: 'Music',
description: 'Get your groove on with Odysee',
image: 'https://player.odycdn.com/speech/category-music:8.jpg',
}),
[PAGES.POP_CULTURE]: () => ({
},
[PAGES.POP_CULTURE]: {
title: 'Big Hits',
description: 'Animation, pop culture, comedy, and all the other weird on Odysee',
image: '',
}),
[PAGES.SEARCH]: ({ q = '' }) => {
if (!q) {
return {};
}
return {
title: `"${q}" Search Results`,
description: `Find the best "${q}" content on Odysee`,
urlQueryString: `q=${q}`,
};
},
[PAGES.TECH]: () => ({
[PAGES.TECH]: {
title: 'Tech',
description: 'Hardware, software, startups, photography on Odysee',
image: '',
}),
[PAGES.UNIVERSE]: () => ({
},
[PAGES.UNIVERSE]: {
title: 'Universe',
description: 'Podcasts, life, learning, and everything else on Odysee',
image: '',
}),
[PAGES.WILD_WEST]: () => ({
},
[PAGES.WILD_WEST]: {
title: 'Wild West',
description: 'Boosted by user credits, this is what the community promotes on Odysee',
image: 'https://player.odycdn.com/speech/category-wildwest:1.jpg',
}),
},
};

View file

@ -36,6 +36,10 @@ Lbry.setDaemonConnectionString(PROXY_URL);
const BEGIN_STR = '<!-- VARIABLE_HEAD_BEGIN -->';
const FINAL_STR = '<!-- VARIABLE_HEAD_END -->';
// ****************************************************************************
// Helpers
// ****************************************************************************
function insertToHead(fullHtml, htmlToInsert) {
const beginIndex = fullHtml.indexOf(BEGIN_STR);
const finalIndex = fullHtml.indexOf(FINAL_STR);
@ -56,7 +60,7 @@ function truncateDescription(description, maxChars = 200) {
return chars.length > maxChars ? truncated + '...' : truncated;
}
function getCategoryMetaRenderFn(path) {
function getCategoryMeta(path) {
const page = Object.keys(CATEGORY_METADATA).find((x) => path === `/$/${x}` || path === `/$/${x}/`);
return CATEGORY_METADATA[page];
}
@ -299,6 +303,21 @@ function buildGoogleVideoMetadata(uri, claim) {
);
}
function buildSearchPageHead(html, requestPath, queryStr) {
const searchPageMetadata = buildOgMetadata({
...(queryStr
? {
title: `"${queryStr}" Search Results`,
description: `Find the best "${queryStr}" content on Odysee`,
image: '', // TODO: get Search Page image
urlQueryString: `q=${queryStr}`,
}
: {}),
path: requestPath,
});
return insertToHead(html, searchPageMetadata);
}
async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
let claim;
try {
@ -315,6 +334,10 @@ async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
return claim;
}
// ****************************************************************************
// getHtml
// ****************************************************************************
let html;
async function getHtml(ctx) {
if (!html) {
@ -371,16 +394,21 @@ async function getHtml(ctx) {
return insertToHead(html);
}
const categoryMetaFn = getCategoryMetaRenderFn(requestPath);
if (categoryMetaFn) {
const categoryMeta = categoryMetaFn(query);
const categoryMeta = getCategoryMeta(requestPath);
if (categoryMeta) {
const categoryPageMetadata = buildOgMetadata({
...categoryMeta,
title: categoryMeta.title,
description: categoryMeta.description,
image: categoryMeta.image,
path: requestPath,
});
return insertToHead(html, categoryPageMetadata);
}
if (requestPath === `/$/${PAGES.SEARCH}` || requestPath === `/$/${PAGES.SEARCH}/`) {
return buildSearchPageHead(html, requestPath, query.q);
}
if (!requestPath.includes('$')) {
const parsedUri = parseURI(normalizeClaimUrl(requestPath.slice(1)));
const claimUri = buildURI({ ...parsedUri, startTime: undefined });