2020-07-06 23:39:35 +02:00
|
|
|
const {
|
|
|
|
URL,
|
2021-06-07 20:48:00 +02:00
|
|
|
DOMAIN,
|
2020-07-06 23:39:35 +02:00
|
|
|
SITE_TITLE,
|
|
|
|
SITE_CANONICAL_URL,
|
|
|
|
OG_HOMEPAGE_TITLE,
|
|
|
|
OG_TITLE_SUFFIX,
|
|
|
|
OG_IMAGE_URL,
|
|
|
|
SITE_DESCRIPTION,
|
|
|
|
SITE_NAME,
|
2021-07-23 17:34:11 +02:00
|
|
|
FAVICON,
|
2021-08-05 07:41:06 +02:00
|
|
|
LBRY_WEB_API,
|
2020-07-06 23:39:35 +02:00
|
|
|
} = require('../../config.js');
|
2021-08-05 07:41:06 +02:00
|
|
|
|
|
|
|
const { Lbry } = require('lbry-redux');
|
2021-04-14 10:13:38 +02:00
|
|
|
const { generateEmbedUrl, generateStreamUrl, generateDirectUrl } = require('../../ui/util/web');
|
2020-01-23 21:41:14 +01:00
|
|
|
const PAGES = require('../../ui/constants/pages');
|
2021-03-08 08:28:35 +01:00
|
|
|
const { CATEGORY_METADATA } = require('./category-metadata');
|
2021-08-07 11:00:33 +02:00
|
|
|
const { parseURI, normalizeURI } = require('lbry-redux');
|
2019-11-07 20:39:22 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2021-04-14 10:13:38 +02:00
|
|
|
const moment = require('moment');
|
2021-01-27 20:27:59 +01:00
|
|
|
const removeMd = require('remove-markdown');
|
2020-08-19 23:09:30 +02:00
|
|
|
const { getJsBundleId } = require('../bundle-id.js');
|
|
|
|
const jsBundleId = getJsBundleId();
|
2021-08-05 07:41:06 +02:00
|
|
|
const SDK_API_PATH = `${LBRY_WEB_API}/api/v1`;
|
|
|
|
const PROXY_URL = `${SDK_API_PATH}/proxy`;
|
|
|
|
Lbry.setDaemonConnectionString(PROXY_URL);
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2020-01-23 21:41:14 +01:00
|
|
|
function insertToHead(fullHtml, htmlToInsert) {
|
2021-08-02 16:10:49 +02:00
|
|
|
const beginStr = '<!-- VARIABLE_HEAD_BEGIN -->';
|
|
|
|
const finalStr = '<!-- VARIABLE_HEAD_END -->';
|
|
|
|
|
|
|
|
const beginIndex = fullHtml.indexOf(beginStr);
|
|
|
|
const finalIndex = fullHtml.indexOf(finalStr);
|
|
|
|
|
|
|
|
if (beginIndex > -1 && finalIndex > -1 && finalIndex > beginIndex) {
|
|
|
|
return `${fullHtml.slice(0, beginIndex)}${
|
|
|
|
htmlToInsert || buildOgMetadata()
|
|
|
|
}<script src="/public/ui-${jsBundleId}.js" async></script>${fullHtml.slice(finalIndex + finalStr.length)}`;
|
|
|
|
}
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function truncateDescription(description) {
|
|
|
|
return description.length > 200 ? description.substr(0, 200) + '...' : description;
|
|
|
|
}
|
|
|
|
|
2021-08-07 11:00:33 +02:00
|
|
|
function normalizeClaimUrl(url) {
|
|
|
|
return normalizeURI(url.replace(/:/g, '#'));
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
function escapeHtmlProperty(property) {
|
|
|
|
return property
|
|
|
|
? String(property)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''')
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
|
2021-03-08 08:28:35 +01:00
|
|
|
function getCategoryMeta(path) {
|
|
|
|
const page = Object.keys(CATEGORY_METADATA).find((x) => path.endsWith(x) || path.endsWith(`${x}/`));
|
|
|
|
return CATEGORY_METADATA[page];
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:41:14 +01:00
|
|
|
//
|
|
|
|
// Normal metadata with option to override certain values
|
2020-01-28 19:00:45 +01:00
|
|
|
//
|
2020-01-23 21:41:14 +01:00
|
|
|
function buildOgMetadata(overrideOptions = {}) {
|
2021-05-27 23:00:19 +02:00
|
|
|
const { title, description, image } = overrideOptions;
|
2021-01-27 20:27:59 +01:00
|
|
|
const cleanDescription = removeMd(description || SITE_DESCRIPTION);
|
2020-01-23 21:41:14 +01:00
|
|
|
const head =
|
2020-07-06 23:39:35 +02:00
|
|
|
`<title>${SITE_TITLE}</title>\n` +
|
2020-01-23 21:41:14 +01:00
|
|
|
`<meta property="og:url" content="${URL}" />\n` +
|
2020-10-05 20:54:51 +02:00
|
|
|
`<meta property="og:title" content="${title || OG_HOMEPAGE_TITLE || SITE_TITLE}" />\n` +
|
2020-07-02 03:34:50 +02:00
|
|
|
`<meta property="og:site_name" content="${SITE_NAME || SITE_TITLE}"/>\n` +
|
2021-01-27 20:27:59 +01:00
|
|
|
`<meta property="og:description" content="${cleanDescription}" />\n` +
|
2021-05-27 23:00:19 +02:00
|
|
|
`<meta property="og:image" content="${image || OG_IMAGE_URL || `${URL}/public/v2-og.png`}" />\n` +
|
2020-01-23 21:41:14 +01:00
|
|
|
'<meta name="twitter:card" content="summary_large_image"/>\n' +
|
2021-03-08 08:28:35 +01:00
|
|
|
`<meta name="twitter:title" content="${
|
2021-05-27 23:00:19 +02:00
|
|
|
(title && title + ' ' + OG_TITLE_SUFFIX) || OG_HOMEPAGE_TITLE || SITE_TITLE
|
2021-03-08 08:28:35 +01:00
|
|
|
}" />\n` +
|
2021-01-27 20:27:59 +01:00
|
|
|
`<meta name="twitter:description" content="${cleanDescription}" />\n` +
|
2021-05-27 23:00:19 +02:00
|
|
|
`<meta name="twitter:image" content="${image || OG_IMAGE_URL || `${URL}/public/v2-og.png`}"/>\n` +
|
2020-07-01 00:44:46 +02:00
|
|
|
`<meta name="twitter:url" content="${URL}" />\n` +
|
2020-07-06 23:39:35 +02:00
|
|
|
'<meta property="fb:app_id" content="1673146449633983" />\n' +
|
2020-08-07 18:17:29 +02:00
|
|
|
`<link rel="canonical" content="${SITE_CANONICAL_URL || URL}"/>` +
|
2021-03-08 08:28:35 +01:00
|
|
|
`<link rel="search" type="application/opensearchdescription+xml" title="${
|
|
|
|
SITE_NAME || SITE_TITLE
|
|
|
|
}" href="${URL}/opensearch.xml">`;
|
2020-07-01 00:44:46 +02:00
|
|
|
return head;
|
|
|
|
}
|
2020-01-23 21:41:14 +01:00
|
|
|
|
2021-06-02 22:36:45 +02:00
|
|
|
function conditionallyAddPWA() {
|
|
|
|
let head = '';
|
2021-06-07 20:48:00 +02:00
|
|
|
if (DOMAIN === 'odysee.com') {
|
2021-07-23 17:34:11 +02:00
|
|
|
head += '<link rel="manifest" href="./public/pwa/manifest.json"/>';
|
2021-06-03 17:36:55 +02:00
|
|
|
head += '<link rel="apple-touch-icon" sizes="180x180" href="./public/pwa/icon-180.png">';
|
|
|
|
head += '<script src="./serviceWorker.js"></script>';
|
2021-06-02 22:36:45 +02:00
|
|
|
}
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2021-07-23 17:34:11 +02:00
|
|
|
function addFavicon() {
|
|
|
|
let head = '';
|
|
|
|
head += `<link rel="icon" type="image/png" href="${FAVICON || './public/favicon.png'}" />`;
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2021-06-02 23:03:09 +02:00
|
|
|
function buildHead() {
|
2021-07-23 17:34:11 +02:00
|
|
|
const head =
|
|
|
|
'<!-- VARIABLE_HEAD_BEGIN -->' +
|
|
|
|
addFavicon() +
|
|
|
|
conditionallyAddPWA() +
|
|
|
|
buildOgMetadata() +
|
|
|
|
'<!-- VARIABLE_HEAD_END -->';
|
2020-01-23 21:41:14 +01:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2021-06-03 17:36:55 +02:00
|
|
|
function buildBasicOgMetadata() {
|
2021-07-23 17:34:11 +02:00
|
|
|
const head = '<!-- VARIABLE_HEAD_BEGIN -->' + addFavicon() + buildOgMetadata() + '<!-- VARIABLE_HEAD_END -->';
|
2021-06-03 17:36:55 +02:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:41:14 +01:00
|
|
|
//
|
|
|
|
// Metadata used for urls that need claim information
|
|
|
|
// Also has option to override defaults
|
2020-01-28 19:00:45 +01:00
|
|
|
//
|
2020-01-23 21:41:14 +01:00
|
|
|
function buildClaimOgMetadata(uri, claim, overrideOptions = {}) {
|
|
|
|
// Initial setup for claim based og metadata
|
2020-01-28 19:00:45 +01:00
|
|
|
const { claimName } = parseURI(uri);
|
2021-08-05 07:41:06 +02:00
|
|
|
const { meta, value, signing_channel } = claim;
|
|
|
|
const fee = value && value.fee && (Number(value.fee.amount) || 0);
|
|
|
|
const tags = value && value.tags;
|
|
|
|
const media = value && (value.video || value.audio || value.image);
|
|
|
|
const source = value && value.source;
|
|
|
|
const channel = signing_channel && signing_channel.name;
|
|
|
|
const thumbnail = value && value.thumbnail && value.thumbnail.url;
|
|
|
|
const mediaType = source && source.media_type;
|
|
|
|
const mediaDuration = media && media.duration;
|
|
|
|
const claimTitle = escapeHtmlProperty((value && value.title) || claimName);
|
2021-08-06 03:28:12 +02:00
|
|
|
const releaseTime = (value && value.release_time) || (meta && meta.creation_timestamp) || 0;
|
2021-08-05 07:41:06 +02:00
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
const claimDescription =
|
2021-08-05 07:41:06 +02:00
|
|
|
value && value.description && value.description.length > 0
|
|
|
|
? escapeHtmlProperty(truncateDescription(value.description))
|
2020-07-06 23:39:35 +02:00
|
|
|
: `View ${claimTitle} on ${SITE_NAME}`;
|
2021-08-05 07:41:06 +02:00
|
|
|
|
|
|
|
const claimLanguage =
|
|
|
|
value && value.languages && value.languages.length > 0 ? escapeHtmlProperty(value.languages[0]) : 'en_US';
|
2020-04-08 20:49:37 +02:00
|
|
|
|
2020-04-02 23:47:16 +02:00
|
|
|
let imageThumbnail;
|
|
|
|
|
2021-08-05 07:41:06 +02:00
|
|
|
if (fee <= 0 && mediaType && mediaType.startsWith('image/')) {
|
2020-05-07 16:52:55 +02:00
|
|
|
imageThumbnail = generateStreamUrl(claim.name, claim.claim_id);
|
2020-04-02 23:47:16 +02:00
|
|
|
}
|
2021-08-05 07:41:06 +02:00
|
|
|
|
|
|
|
const claimThumbnail = escapeHtmlProperty(thumbnail) || imageThumbnail || OG_IMAGE_URL || `${URL}/public/v2-og.png`;
|
2020-01-23 21:41:14 +01:00
|
|
|
|
|
|
|
// Allow for ovverriding default claim based og metadata
|
|
|
|
const title = overrideOptions.title || claimTitle;
|
|
|
|
const description = overrideOptions.description || claimDescription;
|
2021-01-27 20:27:59 +01:00
|
|
|
const cleanDescription = removeMd(description);
|
2019-11-07 20:39:22 +01:00
|
|
|
|
|
|
|
let head = '';
|
|
|
|
|
2021-07-23 17:34:11 +02:00
|
|
|
head += `${addFavicon()}`;
|
2019-11-07 20:39:22 +01:00
|
|
|
head += '<meta charset="utf8"/>';
|
2020-01-23 21:41:14 +01:00
|
|
|
head += `<title>${title}</title>`;
|
2021-01-27 20:27:59 +01:00
|
|
|
head += `<meta name="description" content="${cleanDescription}"/>`;
|
2021-08-05 07:41:06 +02:00
|
|
|
|
|
|
|
if (tags && tags.length > 0) {
|
|
|
|
head += `<meta name="keywords" content="${tags.toString()}"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
2020-01-28 20:43:02 +01:00
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
head += `<meta name="twitter:image" content="${claimThumbnail}"/>`;
|
2021-01-27 20:27:59 +01:00
|
|
|
head += `<meta property="og:description" content="${cleanDescription}"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
head += `<meta property="og:image" content="${claimThumbnail}"/>`;
|
|
|
|
head += `<meta property="og:locale" content="${claimLanguage}"/>`;
|
2020-07-06 23:39:35 +02:00
|
|
|
head += `<meta property="og:site_name" content="${SITE_NAME}"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
head += `<meta property="og:type" content="website"/>`;
|
2020-01-23 21:41:14 +01:00
|
|
|
head += `<meta property="og:title" content="${title}"/>`;
|
2020-07-01 00:44:46 +02:00
|
|
|
head += `<meta name="twitter:title" content="${title}"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
// below should be canonical_url, but not provided by chainquery yet
|
2019-11-20 21:57:38 +01:00
|
|
|
head += `<meta property="og:url" content="${URL}/${claim.name}:${claim.claim_id}"/>`;
|
2020-07-01 00:44:46 +02:00
|
|
|
head += `<meta name="twitter:url" content="${URL}/${claim.name}:${claim.claim_id}"/>`;
|
2020-07-06 23:39:35 +02:00
|
|
|
head += `<link rel="canonical" content="${SITE_CANONICAL_URL || URL}/${claim.name}:${claim.claim_id}"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2021-08-05 07:41:06 +02:00
|
|
|
if (mediaType && (mediaType.startsWith('video/') || mediaType.startsWith('audio/'))) {
|
2020-01-28 20:45:47 +01:00
|
|
|
const videoUrl = generateEmbedUrl(claim.name, claim.claim_id);
|
2019-11-07 20:39:22 +01:00
|
|
|
head += `<meta property="og:video" content="${videoUrl}" />`;
|
|
|
|
head += `<meta property="og:video:secure_url" content="${videoUrl}" />`;
|
2021-08-05 07:41:06 +02:00
|
|
|
head += `<meta property="og:video:type" content="${mediaType}" />`;
|
|
|
|
if (channel) {
|
|
|
|
head += `<meta name="og:video:series" content="${channel}"/>`;
|
2020-07-28 03:47:32 +02:00
|
|
|
}
|
2020-01-28 20:37:03 +01:00
|
|
|
head += `<meta name="twitter:card" content="player"/>`;
|
2020-01-28 20:45:47 +01:00
|
|
|
head += `<meta name="twitter:player" content="${videoUrl}" />`;
|
2021-08-06 03:28:12 +02:00
|
|
|
if (releaseTime) {
|
|
|
|
var release = new Date(releaseTime * 1000).toISOString();
|
2020-07-28 03:47:32 +02:00
|
|
|
head += `<meta property="og:video:release_date" content="${release}"/>`;
|
|
|
|
}
|
2021-08-05 07:41:06 +02:00
|
|
|
if (mediaDuration) {
|
|
|
|
head += `<meta property="og:video:duration" content="${mediaDuration}"/>`;
|
2020-07-28 03:47:32 +02:00
|
|
|
}
|
2021-08-05 07:41:06 +02:00
|
|
|
if (media && media.width && media.height) {
|
|
|
|
head += `<meta property="og:video:width" content="${media.width}"/>`;
|
|
|
|
head += `<meta property="og:video:height" content="${media.height}"/>`;
|
|
|
|
head += `<meta name="twitter:player:width" content="${media.width}">`;
|
|
|
|
head += `<meta name="twitter:player:height" content="${media.height}">`;
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
2020-01-28 20:43:02 +01:00
|
|
|
} else {
|
|
|
|
head += `<meta name="twitter:card" content="summary_large_image"/>`;
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2021-08-05 07:41:06 +02:00
|
|
|
function buildGoogleVideoMetadata(uri, claim) {
|
|
|
|
const { claimName } = parseURI(uri);
|
|
|
|
const { meta, value } = claim;
|
2021-08-05 07:56:06 +02:00
|
|
|
const media = value && value.video;
|
2021-08-05 07:41:06 +02:00
|
|
|
const source = value && value.source;
|
|
|
|
const thumbnail = value && value.thumbnail && value.thumbnail.url;
|
|
|
|
const mediaType = source && source.media_type;
|
|
|
|
const mediaDuration = media && media.duration;
|
|
|
|
const claimTitle = escapeHtmlProperty((value && value.title) || claimName);
|
2021-08-06 03:28:12 +02:00
|
|
|
const releaseTime = (value && value.release_time) || (meta && meta.creation_timestamp) || 0;
|
2021-04-14 10:13:38 +02:00
|
|
|
|
|
|
|
const claimDescription =
|
2021-08-05 07:41:06 +02:00
|
|
|
value && value.description && value.description.length > 0
|
|
|
|
? escapeHtmlProperty(truncateDescription(value.description))
|
2021-04-14 10:13:38 +02:00
|
|
|
: `View ${claimTitle} on ${SITE_NAME}`;
|
2021-08-05 07:41:06 +02:00
|
|
|
|
|
|
|
if (!mediaType || !mediaType.startsWith('video/')) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
const claimThumbnail = escapeHtmlProperty(thumbnail) || OG_IMAGE_URL || `${URL}/public/v2-og.png`;
|
2021-04-14 10:13:38 +02:00
|
|
|
|
|
|
|
// https://developers.google.com/search/docs/data-types/video
|
|
|
|
const googleVideoMetadata = {
|
|
|
|
// --- Must ---
|
|
|
|
'@context': 'https://schema.org',
|
|
|
|
'@type': 'VideoObject',
|
|
|
|
name: `${claimTitle}`,
|
|
|
|
description: `${removeMd(claimDescription)}`,
|
|
|
|
thumbnailUrl: `${claimThumbnail}`,
|
2021-08-06 03:28:12 +02:00
|
|
|
uploadDate: `${new Date(releaseTime * 1000).toISOString()}`,
|
2021-04-14 10:13:38 +02:00
|
|
|
// --- Recommended ---
|
2021-08-05 07:41:06 +02:00
|
|
|
duration: mediaDuration ? moment.duration(mediaDuration * 1000).toISOString() : undefined,
|
2021-04-14 10:13:38 +02:00
|
|
|
contentUrl: generateDirectUrl(claim.name, claim.claim_id),
|
|
|
|
embedUrl: generateEmbedUrl(claim.name, claim.claim_id),
|
|
|
|
};
|
|
|
|
|
2021-04-21 08:12:09 +02:00
|
|
|
if (
|
|
|
|
!googleVideoMetadata.description.replace(/\s/g, '').length ||
|
|
|
|
googleVideoMetadata.thumbnailUrl.startsWith('data:image') ||
|
|
|
|
!googleVideoMetadata.thumbnailUrl.startsWith('http')
|
|
|
|
) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-04-14 10:13:38 +02:00
|
|
|
return (
|
|
|
|
'<script type="application/ld+json">\n' + JSON.stringify(googleVideoMetadata, null, ' ') + '\n' + '</script>\n'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-05 07:41:06 +02:00
|
|
|
async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
|
|
|
|
let claim;
|
|
|
|
try {
|
|
|
|
const response = await Lbry.resolve({ urls: [url] });
|
|
|
|
if (response && response[url] && !response[url].error) {
|
|
|
|
claim = response && response[url];
|
2021-08-07 11:00:33 +02:00
|
|
|
const isRepost = claim.reposted_claim && claim.reposted_claim.name && claim.reposted_claim.claim_id;
|
|
|
|
if (isRepost && !ignoreRedirect) {
|
|
|
|
ctx.redirect(`/${claim.reposted_claim.name}:${claim.reposted_claim.claim_id}`);
|
|
|
|
return;
|
2021-08-05 07:41:06 +02:00
|
|
|
}
|
2020-07-28 21:28:51 +02:00
|
|
|
}
|
2021-08-05 07:41:06 +02:00
|
|
|
} catch {}
|
|
|
|
return claim;
|
2020-01-23 21:41:14 +01:00
|
|
|
}
|
|
|
|
|
2020-07-08 20:09:06 +02:00
|
|
|
let html;
|
2020-07-01 00:44:46 +02:00
|
|
|
async function getHtml(ctx) {
|
2020-07-08 20:09:06 +02:00
|
|
|
if (!html) {
|
|
|
|
html = fs.readFileSync(path.join(__dirname, '/../dist/index.html'), 'utf8');
|
|
|
|
}
|
2020-07-08 19:02:18 +02:00
|
|
|
|
2020-07-08 20:09:06 +02:00
|
|
|
const requestPath = decodeURIComponent(ctx.path);
|
2020-07-08 19:02:18 +02:00
|
|
|
if (requestPath.length === 0) {
|
2020-07-01 00:44:46 +02:00
|
|
|
const ogMetadata = buildBasicOgMetadata();
|
|
|
|
return insertToHead(html, ogMetadata);
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 21:41:14 +01:00
|
|
|
const invitePath = `/$/${PAGES.INVITE}/`;
|
2020-01-28 19:00:45 +01:00
|
|
|
const embedPath = `/$/${PAGES.EMBED}/`;
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2020-07-08 19:02:18 +02:00
|
|
|
if (requestPath.includes(invitePath)) {
|
2020-01-23 21:41:14 +01:00
|
|
|
try {
|
2021-08-07 11:00:33 +02:00
|
|
|
const inviteChannel = requestPath.slice(invitePath.length);
|
|
|
|
const inviteChannelUrl = normalizeClaimUrl(inviteChannel);
|
2021-08-05 07:41:06 +02:00
|
|
|
const claim = await resolveClaimOrRedirect(ctx, inviteChannelUrl);
|
2020-01-23 21:41:14 +01:00
|
|
|
const invitePageMetadata = buildClaimOgMetadata(inviteChannelUrl, claim, {
|
2020-10-01 22:59:11 +02:00
|
|
|
title: `Join ${claim.name} on ${SITE_NAME}`,
|
|
|
|
description: `Join ${claim.name} on ${SITE_NAME}, a content wonderland owned by everyone (and no one).`,
|
2020-01-23 21:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return insertToHead(html, invitePageMetadata);
|
|
|
|
} catch (e) {
|
|
|
|
// Something about the invite channel is messed up
|
|
|
|
// Enter generic invite metadata
|
|
|
|
const invitePageMetadata = buildOgMetadata({
|
2020-10-01 22:59:11 +02:00
|
|
|
title: `Join a friend on ${SITE_NAME}`,
|
|
|
|
description: `Join a friend on ${SITE_NAME}, a content wonderland owned by everyone (and no one).`,
|
2020-01-23 21:41:14 +01:00
|
|
|
});
|
|
|
|
return insertToHead(html, invitePageMetadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 19:02:18 +02:00
|
|
|
if (requestPath.includes(embedPath)) {
|
2021-08-07 11:00:33 +02:00
|
|
|
const claimUri = normalizeClaimUrl(requestPath.replace(embedPath, ''));
|
2021-08-05 07:41:06 +02:00
|
|
|
const claim = await resolveClaimOrRedirect(ctx, claimUri, true);
|
2020-01-28 19:00:45 +01:00
|
|
|
|
|
|
|
if (claim) {
|
2020-01-28 20:45:47 +01:00
|
|
|
const ogMetadata = buildClaimOgMetadata(claimUri, claim);
|
2021-04-14 10:13:38 +02:00
|
|
|
const googleVideoMetadata = buildGoogleVideoMetadata(claimUri, claim);
|
|
|
|
return insertToHead(html, ogMetadata.concat('\n', googleVideoMetadata));
|
2020-01-28 19:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return insertToHead(html);
|
|
|
|
}
|
|
|
|
|
2021-03-08 08:28:35 +01:00
|
|
|
const categoryMeta = getCategoryMeta(requestPath);
|
|
|
|
if (categoryMeta) {
|
|
|
|
const categoryPageMetadata = buildOgMetadata({
|
|
|
|
title: categoryMeta.title,
|
|
|
|
description: categoryMeta.description,
|
|
|
|
image: categoryMeta.image,
|
|
|
|
});
|
|
|
|
return insertToHead(html, categoryPageMetadata);
|
|
|
|
}
|
|
|
|
|
2020-07-08 19:02:18 +02:00
|
|
|
if (!requestPath.includes('$')) {
|
2021-08-07 11:00:33 +02:00
|
|
|
const claimUri = normalizeClaimUrl(requestPath.slice(1));
|
2021-08-05 07:41:06 +02:00
|
|
|
const claim = await resolveClaimOrRedirect(ctx, claimUri);
|
2020-07-28 21:14:27 +02:00
|
|
|
|
2020-01-23 21:41:14 +01:00
|
|
|
if (claim) {
|
|
|
|
const ogMetadata = buildClaimOgMetadata(claimUri, claim);
|
2021-04-14 10:13:38 +02:00
|
|
|
const googleVideoMetadata = buildGoogleVideoMetadata(claimUri, claim);
|
|
|
|
return insertToHead(html, ogMetadata.concat('\n', googleVideoMetadata));
|
2020-01-23 21:41:14 +01:00
|
|
|
}
|
2019-11-07 20:39:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-03 17:36:55 +02:00
|
|
|
const ogMetadataAndPWA = buildHead();
|
|
|
|
return insertToHead(html, ogMetadataAndPWA);
|
2020-07-01 00:44:46 +02:00
|
|
|
}
|
2020-07-02 03:34:50 +02:00
|
|
|
|
2021-06-02 23:03:09 +02:00
|
|
|
module.exports = { insertToHead, buildHead, getHtml };
|