Support for Category-Page Metadata definition.

## Issue
Part of 4786: Add support for web metadata on category pages

## Note
Remaining task: `category-metadata.js` needs to be filled first.
This commit is contained in:
infinite-persistence 2021-03-08 15:28:35 +08:00 committed by Sean Yesmunt
parent e8fdfa7e6c
commit 605d33331b
3 changed files with 98 additions and 5 deletions

View file

@ -7,6 +7,18 @@ exports.AUTH_WALLET_PASSWORD = 'walletpassword';
exports.BACKUP = 'backup';
exports.CHANNEL = 'channel';
exports.DISCOVER = 'discover';
exports.BIG_HITS = 'big_hits';
exports.COMMUNITY = 'community';
exports.ENLIGHTENMENT = 'enlightenment';
exports.FINANCE = 'finance';
exports.GAMING = 'gaming';
exports.GENERAL = 'general';
exports.LAB = 'lab';
exports.NEWS = 'news';
exports.RABBIT_HOLE = 'rabbithole';
exports.SCIENCE = 'science';
exports.TECHNOLOGY = 'technology';
exports.WILD_WEST = 'wildwest';
exports.HOME = 'home';
exports.HELP = 'help';
exports.LIBRARY = 'library';

View file

@ -0,0 +1,64 @@
const PAGES = require('../../ui/constants/pages');
module.exports.CATEGORY_METADATA = {
[PAGES.BIG_HITS]: {
title: '',
description: '',
image: '',
},
[PAGES.COMMUNITY]: {
title: '',
description: '',
image: '',
},
[PAGES.ENLIGHTENMENT]: {
title: '',
description: '',
image: '',
},
[PAGES.FINANCE]: {
title: '',
description: '',
image: '',
},
[PAGES.GAMING]: {
title: '',
description: '',
image: '',
},
[PAGES.GENERAL]: {
title: '',
description: '',
image: '',
},
[PAGES.LAB]: {
title: '',
description: '',
image: '',
},
[PAGES.NEWS]: {
title: '',
description: '',
image: '',
},
[PAGES.RABBIT_HOLE]: {
title: '',
description: '',
image: '',
},
[PAGES.SCIENCE]: {
title: '',
description: '',
image: '',
},
[PAGES.TECHNOLOGY]: {
title: '',
description: '',
image: '',
},
[PAGES.WILD_WEST]: {
title: '',
description: '',
image: '',
},
};

View file

@ -10,6 +10,7 @@ const {
} = require('../../config.js');
const { generateEmbedUrl, generateStreamUrl } = require('../../ui/util/web');
const PAGES = require('../../ui/constants/pages');
const { CATEGORY_METADATA } = require('./category-metadata');
const { getClaim } = require('./chainquery');
const { parseURI } = require('lbry-redux');
const fs = require('fs');
@ -43,6 +44,11 @@ function escapeHtmlProperty(property) {
: '';
}
function getCategoryMeta(path) {
const page = Object.keys(CATEGORY_METADATA).find((x) => path.endsWith(x) || path.endsWith(`${x}/`));
return CATEGORY_METADATA[page];
}
//
// Normal metadata with option to override certain values
//
@ -57,16 +63,17 @@ function buildOgMetadata(overrideOptions = {}) {
`<meta property="og:description" content="${cleanDescription}" />\n` +
`<meta property="og:image" content="${OG_IMAGE_URL || `${URL}/public/v2-og.png`}" />\n` +
'<meta name="twitter:card" content="summary_large_image"/>\n' +
`<meta name="twitter:title" content="${(title && title + OG_TITLE_SUFFIX) ||
OG_HOMEPAGE_TITLE ||
SITE_TITLE}" />\n` +
`<meta name="twitter:title" content="${
(title && title + OG_TITLE_SUFFIX) || OG_HOMEPAGE_TITLE || SITE_TITLE
}" />\n` +
`<meta name="twitter:description" content="${cleanDescription}" />\n` +
`<meta name="twitter:image" content="${OG_IMAGE_URL || `${URL}/public/v2-og.png`}"/>\n` +
`<meta name="twitter:url" content="${URL}" />\n` +
'<meta property="fb:app_id" content="1673146449633983" />\n' +
`<link rel="canonical" content="${SITE_CANONICAL_URL || URL}"/>` +
`<link rel="search" type="application/opensearchdescription+xml" title="${SITE_NAME ||
SITE_TITLE}" href="${URL}/opensearch.xml">`;
`<link rel="search" type="application/opensearchdescription+xml" title="${
SITE_NAME || SITE_TITLE
}" href="${URL}/opensearch.xml">`;
return head;
}
@ -229,6 +236,16 @@ async function getHtml(ctx) {
return insertToHead(html);
}
const categoryMeta = getCategoryMeta(requestPath);
if (categoryMeta) {
const categoryPageMetadata = buildOgMetadata({
title: categoryMeta.title,
description: categoryMeta.description,
image: categoryMeta.image,
});
return insertToHead(html, categoryPageMetadata);
}
if (!requestPath.includes('$')) {
const claimUri = requestPath.slice(1).replace(/:/g, '#');
const claim = await getClaimFromChainqueryOrRedirect(ctx, claimUri);