Move Category Metadata to homepages-repo (#1331)

This commit is contained in:
infinite-persistence 2022-04-13 22:23:00 +08:00
commit 57ba9c278b
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 62 additions and 104 deletions

View file

@ -1,92 +0,0 @@
const PAGES = require('../../ui/constants/pages');
// Uncomment as you add metadata
module.exports.CATEGORY_METADATA = {
// [PAGES.ARTISTS]: () => ({
// title: 'Artists',
// description: "", <------ FILL
// image: '', <------ FILL
// }),
[PAGES.CREATIVE_ARTS]: () => ({
title: 'The Arts',
description: `Odysee's home for art, animation, comedy, and everything inbetween`,
image: '',
}),
[PAGES.EDUCATION]: () => ({
title: 'Education',
description: `Who needs school when there's Odysee?`,
image: '',
}),
[PAGES.FEATURED]: () => ({
title: 'Featured',
description: 'Showcasing some of the best content Odysee has to offer',
image: '',
}),
[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]: () => ({
title: 'Gaming',
description: 'Pew pew bzzz gaming on Odysee',
image: 'https://player.odycdn.com/speech/category-gaming:5.jpg',
}),
[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]: () => ({
title: 'Lab',
description: 'Science - the real kind, on Odysee',
image: '',
}),
[PAGES.NEWS]: () => ({
title: 'News & Politics',
description: `Stay up to date with all that's happening around the world on Odysee`,
image: '',
}),
[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]: () => ({
title: 'Music',
description: 'Get your groove on with Odysee',
image: 'https://player.odycdn.com/speech/category-music:8.jpg',
}),
[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]: () => ({
title: 'Tech',
description: 'Hardware, software, startups, photography on Odysee',
image: '',
}),
[PAGES.UNIVERSE]: () => ({
title: 'Universe',
description: 'Podcasts, life, learning, and everything else on Odysee',
image: '',
}),
[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

@ -11,7 +11,6 @@ const {
URL, URL,
} = require('../../config.js'); } = require('../../config.js');
const { CATEGORY_METADATA } = require('./category-metadata');
const { const {
generateDirectUrl, generateDirectUrl,
generateEmbedUrl, generateEmbedUrl,
@ -23,6 +22,7 @@ const {
} = require('../../ui/util/web'); } = require('../../ui/util/web');
const { getJsBundleId } = require('../bundle-id.js'); const { getJsBundleId } = require('../bundle-id.js');
const { lbryProxy: Lbry } = require('../lbry'); const { lbryProxy: Lbry } = require('../lbry');
const { getHomepageJSON } = require('./getHomepageJSON');
const { buildURI, parseURI, normalizeClaimUrl } = require('./lbryURI'); const { buildURI, parseURI, normalizeClaimUrl } = require('./lbryURI');
const fs = require('fs'); const fs = require('fs');
const moment = require('moment'); const moment = require('moment');
@ -36,6 +36,10 @@ Lbry.setDaemonConnectionString(PROXY_URL);
const BEGIN_STR = '<!-- VARIABLE_HEAD_BEGIN -->'; const BEGIN_STR = '<!-- VARIABLE_HEAD_BEGIN -->';
const FINAL_STR = '<!-- VARIABLE_HEAD_END -->'; const FINAL_STR = '<!-- VARIABLE_HEAD_END -->';
// ****************************************************************************
// Helpers
// ****************************************************************************
function insertToHead(fullHtml, htmlToInsert) { function insertToHead(fullHtml, htmlToInsert) {
const beginIndex = fullHtml.indexOf(BEGIN_STR); const beginIndex = fullHtml.indexOf(BEGIN_STR);
const finalIndex = fullHtml.indexOf(FINAL_STR); const finalIndex = fullHtml.indexOf(FINAL_STR);
@ -56,9 +60,27 @@ function truncateDescription(description, maxChars = 200) {
return chars.length > maxChars ? truncated + '...' : truncated; return chars.length > maxChars ? truncated + '...' : truncated;
} }
function getCategoryMetaRenderFn(path) { function getCategoryMeta(path) {
const page = Object.keys(CATEGORY_METADATA).find((x) => path === `/$/${x}` || path === `/$/${x}/`); const homepage = getHomepageJSON();
return CATEGORY_METADATA[page];
if (path === `/$/${PAGES.WILD_WEST}` || path === `/$/${PAGES.WILD_WEST}/`) {
return {
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',
};
} else if (homepage && homepage.en) {
const data = Object.values(homepage.en).find((x) => path === `/$/${x.name}` || path === `/$/${x.name}/`);
if (data) {
return {
title: data.label,
description: data.description,
image: data.image,
};
}
}
return null;
} }
// //
@ -299,6 +321,31 @@ 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);
}
function buildCategoryPageHead(html, requestPath, categoryMeta) {
const categoryPageMetadata = buildOgMetadata({
title: categoryMeta.title,
description: categoryMeta.description,
image: categoryMeta.image,
path: requestPath,
});
return insertToHead(html, categoryPageMetadata);
}
async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) { async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
let claim; let claim;
try { try {
@ -315,6 +362,10 @@ async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
return claim; return claim;
} }
// ****************************************************************************
// getHtml
// ****************************************************************************
let html; let html;
async function getHtml(ctx) { async function getHtml(ctx) {
if (!html) { if (!html) {
@ -371,14 +422,13 @@ async function getHtml(ctx) {
return insertToHead(html); return insertToHead(html);
} }
const categoryMetaFn = getCategoryMetaRenderFn(requestPath); const categoryMeta = getCategoryMeta(requestPath);
if (categoryMetaFn) { if (categoryMeta) {
const categoryMeta = categoryMetaFn(query); return buildCategoryPageHead(html, requestPath, categoryMeta);
const categoryPageMetadata = buildOgMetadata({ }
...categoryMeta,
path: requestPath, if (requestPath === `/$/${PAGES.SEARCH}` || requestPath === `/$/${PAGES.SEARCH}/`) {
}); return buildSearchPageHead(html, requestPath, query.q);
return insertToHead(html, categoryPageMetadata);
} }
if (!requestPath.includes('$')) { if (!requestPath.includes('$')) {