From 96f6f66acec6d4d16815abc908e8d1f2f014ca08 Mon Sep 17 00:00:00 2001 From: jessop Date: Tue, 30 Jun 2020 18:44:46 -0400 Subject: [PATCH] build custom metadata from config --- .env.defaults | 2 ++ config.js | 2 ++ static/app-strings.json | 1 + web/.env.defaults | 2 ++ web/src/html.js | 50 ++++++++++++++++++++++++++++++----------- web/webpack.config.js | 4 ++++ 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/.env.defaults b/.env.defaults index 4d3218a30..8abed1216 100644 --- a/.env.defaults +++ b/.env.defaults @@ -5,6 +5,8 @@ WEB_SERVER_PORT=1337 DOMAIN=lbry.tv URL=https://lbry.tv SITE_TITLE=lbry.tv +SITE_MOTTO=Content Freedom +SITE_DESCRIPTION=Meet LBRY, an open, free, and community-controlled content wonderland. LOGO_TITLE=LBRY LBRY_WEB_API=https://api.lbry.tv LBRY_WEB_STREAMING_API=https://cdn.lbryplayer.xyz diff --git a/config.js b/config.js index 4aee543b3..745c2b037 100644 --- a/config.js +++ b/config.js @@ -8,6 +8,8 @@ const config = { DOMAIN: process.env.DOMAIN, URL: process.env.URL, //lbry.tv', SITE_TITLE: process.env.SITE_TITLE, + SITE_MOTTO: process.env.SITE_MOTTO, + SITE_DESCRIPTION: process.env.SITE_DESCRIPTION, LBRY_WEB_API: process.env.LBRY_WEB_API, //api.lbry.tv', LBRY_WEB_STREAMING_API: process.env.LBRY_WEB_STREAMING_API, //cdn.lbryplayer.xyz', WELCOME_VERSION: process.env.WELCOME_VERSION, diff --git a/static/app-strings.json b/static/app-strings.json index 66a367130..8869a3e58 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1259,6 +1259,7 @@ "Email Preferences": "Email Preferences", "Opt out of any topics you don't want to receive email about.": "Opt out of any topics you don't want to receive email about.", "Uncheck your email below if you want to stop receiving messages.": "Uncheck your email below if you want to stop receiving messages.", + "Delete Your Channel": "Delete Your Channel", "Remove from Blocked List": "Remove from Blocked List", "Are you sure you want to remove this from the list?": "Are you sure you want to remove this from the list?", "Cover": "Cover", diff --git a/web/.env.defaults b/web/.env.defaults index f486f5dd3..2d4d084a5 100644 --- a/web/.env.defaults +++ b/web/.env.defaults @@ -5,6 +5,8 @@ WEB_SERVER_PORT=1337 DOMAIN=lbry.tv URL=https://lbry.tv SITE_TITLE=lbry.tv +SITE_MOTTO=Content Freedom +SITE_DESCRIPTION=Meet LBRY, an open, free, and community-controlled content wonderland. LOGO_TITLE=lbry.tv LBRY_WEB_API=https://api.lbry.tv LBRY_WEB_STREAMING_API=https://cdn.lbryplayer.xyz diff --git a/web/src/html.js b/web/src/html.js index 234fc2369..e95fb6ba5 100644 --- a/web/src/html.js +++ b/web/src/html.js @@ -1,4 +1,4 @@ -const { URL } = require('../../config.js'); +const { URL, SITE_TITLE, SITE_DESCRIPTION, SITE_MOTTO } = require('../../config.js'); const { generateEmbedUrl, generateStreamUrl } = require('../../ui/util/web'); const PAGES = require('../../ui/constants/pages'); const { getClaim } = require('./chainquery'); @@ -8,6 +8,7 @@ const path = require('path'); let html = fs.readFileSync(path.join(__dirname, '/../dist/index.html'), 'utf8'); +module.exports = { insertToHead, buildBasicOgMetadata, getHtml }; function insertToHead(fullHtml, htmlToInsert) { return fullHtml.replace( /.*/s, @@ -38,15 +39,35 @@ function buildOgMetadata(overrideOptions = {}) { const head = 'lbry.tv\n' + `\n` + - `\n` + - '\n' + - `\n` + - `\n` + + `\n` + + `\n` + + `\n` + + `\n` + '\n' + - `\n` + + `\n` + + `\n` + + `\n` + + `\n` + ''; + return head; +} +function buildBasicOgMetadata() { + const head = + ' ' + + 'lbry.tv\n' + + `\n` + + `\n` + + `\n` + + `\n` + + `\n` + + '\n' + + `\n` + + `\n` + + `\n` + + `\n` + + '' + + ' '; return head; } @@ -69,7 +90,7 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { if (Number(claim.fee) <= 0 && claim.source_media_type && claim.source_media_type.startsWith('image/')) { imageThumbnail = generateStreamUrl(claim.name, claim.claim_id); } - const claimThumbnail = escapeHtmlProperty(claim.thumbnail_url) || imageThumbnail || `${URL}/v2-og.png`; + const claimThumbnail = escapeHtmlProperty(claim.thumbnail_url) || imageThumbnail || `${URL}/public/v2-og.png`; // Allow for ovverriding default claim based og metadata const title = overrideOptions.title || claimTitle; @@ -91,8 +112,10 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { head += ``; head += ``; head += ``; + head += ``; // below should be canonical_url, but not provided by chainquery yet head += ``; + head += ``; if ( claim.source_media_type && @@ -131,11 +154,11 @@ async function getClaimFromChainquery(url) { return undefined; } -module.exports.getHtml = async function getHtml(ctx) { +async function getHtml(ctx) { const path = decodeURIComponent(ctx.path); - if (path.length === 0) { - return insertToHead(html); + const ogMetadata = buildBasicOgMetadata(); + return insertToHead(html, ogMetadata); } const invitePath = `/$/${PAGES.INVITE}/`; @@ -187,5 +210,6 @@ module.exports.getHtml = async function getHtml(ctx) { } } - return insertToHead(html); -}; + const ogMetadata = buildBasicOgMetadata(); + return insertToHead(html, ogMetadata); +} diff --git a/web/webpack.config.js b/web/webpack.config.js index 828c7e6a2..70be866ff 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -5,6 +5,7 @@ const baseConfig = require('../webpack.base.config.js'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const { DefinePlugin, ProvidePlugin } = require('webpack'); const SentryWebpackPlugin = require('@sentry/webpack-plugin'); +const { insertToHead, buildBasicOgMetadata } = require('./src/html'); const STATIC_ROOT = path.resolve(__dirname, '../static/'); const UI_ROOT = path.resolve(__dirname, '../ui/'); @@ -18,6 +19,9 @@ let plugins = [ { from: `${STATIC_ROOT}/index-web.html`, to: `${DIST_ROOT}/index.html`, + transform(content, path) { + return insertToHead(content.toString(), buildBasicOgMetadata()); + }, }, { from: `${STATIC_ROOT}/img/favicon.png`,