From 13ead2f1e7dbb1dd0ff479e8d4894a003610272f Mon Sep 17 00:00:00 2001 From: jessop Date: Tue, 28 Jan 2020 13:00:45 -0500 Subject: [PATCH 1/4] adds twitter player meta --- .lintstagedrc.json | 8 +++++--- lbrytv/src/html.js | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.lintstagedrc.json b/.lintstagedrc.json index b3430d6a4..6bafc1f42 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,7 +1,9 @@ { "linters": { "ui/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], - "lbrytv/component/*.{js,jsx,scss,json}": ["prettier --write", "git add"], - "ui/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"] - } + "lbrytv/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], + "ui/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"], + "lbrytv/**/*.{js,jsx,scss,json}": ["eslint", "git add"] + }, + "ignore": ["node_modules", "dist", "package-lock.json"] } diff --git a/lbrytv/src/html.js b/lbrytv/src/html.js index adbfb927c..c3ed63345 100644 --- a/lbrytv/src/html.js +++ b/lbrytv/src/html.js @@ -32,7 +32,7 @@ function escapeHtmlProperty(property) { // // Normal metadata with option to override certain values -// +// function buildOgMetadata(overrideOptions = {}) { const { title, description } = overrideOptions; const head = @@ -53,10 +53,10 @@ function buildOgMetadata(overrideOptions = {}) { // // Metadata used for urls that need claim information // Also has option to override defaults -// +// function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { // Initial setup for claim based og metadata - const { isChannel, claimName } = parseURI(uri); + const { claimName } = parseURI(uri); const claimTitle = escapeHtmlProperty(claim.title ? claim.title : claimName); const claimDescription = claim.description && claim.description.length > 0 @@ -64,12 +64,11 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { : `Watch ${claimTitle} on LBRY.tv`; const claimLanguage = escapeHtmlProperty(claim.language) || 'en_US'; const claimThumbnail = escapeHtmlProperty(claim.thumbnail_url) || `${URL}/og.png`; - const defaultClaimTitle = - claim.channel && !isChannel ? `${claimTitle} from ${claim.channel} on LBRY.tv` : `${claimTitle} on LBRY.tv`; // Allow for ovverriding default claim based og metadata const title = overrideOptions.title || claimTitle; const description = overrideOptions.description || claimDescription; + const embedPlayer = overrideOptions.embedPlayer; let head = ''; @@ -95,9 +94,12 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { head += ``; head += ``; head += ``; + head += ``; if (claim.frame_width && claim.frame_height) { head += ``; head += ``; + head += ``; + head += ``; } } @@ -126,6 +128,8 @@ module.exports.getHtml = async function getHtml(ctx) { } const invitePath = `/$/${PAGES.INVITE}/`; + const embedPath = `/$/${PAGES.EMBED}/`; + const embedPlayer = URL + path; if (path.includes(invitePath)) { const inviteChannel = path.slice(invitePath.length).replace(/:/g, '#'); @@ -151,6 +155,18 @@ module.exports.getHtml = async function getHtml(ctx) { } } + if (path.includes(embedPath)) { + const claimUri = path.replace(embedPath, '').replace(/:/g, '#'); + const claim = await getClaimFromChainquery(claimUri); + + if (claim) { + const ogMetadata = buildClaimOgMetadata(claimUri, claim, { embedPlayer: embedPlayer}); + return insertToHead(html, ogMetadata); + } + + return insertToHead(html); + } + if (!path.includes('$')) { const claimUri = path.slice(1).replace(/:/g, '#'); const claim = await getClaimFromChainquery(claimUri); From 5da80baca1ebb87e9274e6ffa05fd76d522a9738 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Tue, 28 Jan 2020 14:37:03 -0500 Subject: [PATCH 2/4] fix twitter embeds? --- lbrytv/src/html.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lbrytv/src/html.js b/lbrytv/src/html.js index c3ed63345..18383033f 100644 --- a/lbrytv/src/html.js +++ b/lbrytv/src/html.js @@ -94,7 +94,8 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { head += ``; head += ``; head += ``; - head += ``; + head += ``; + head += ``; if (claim.frame_width && claim.frame_height) { head += ``; head += ``; From 6021564af9d2974901b0fd1de9bd74e2e92e6864 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Tue, 28 Jan 2020 14:43:02 -0500 Subject: [PATCH 3/4] remove duplicate rule --- lbrytv/src/html.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lbrytv/src/html.js b/lbrytv/src/html.js index 18383033f..e3e1cb37a 100644 --- a/lbrytv/src/html.js +++ b/lbrytv/src/html.js @@ -78,7 +78,7 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { if (claim.tags) { head += ``; } - head += ``; + head += ``; head += ``; head += ``; @@ -102,6 +102,8 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { head += ``; head += ``; } + } else { + head += ``; } return head; From 067b3eb98fd8853436bf6de031dfc189c495d906 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Tue, 28 Jan 2020 14:45:47 -0500 Subject: [PATCH 4/4] it is always the embed url --- lbrytv/src/html.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lbrytv/src/html.js b/lbrytv/src/html.js index e3e1cb37a..7efc3f9c2 100644 --- a/lbrytv/src/html.js +++ b/lbrytv/src/html.js @@ -1,5 +1,5 @@ const { URL } = require('../../config.js'); -const { generateStreamUrl } = require('../../ui/util/lbrytv'); +const { generateEmbedUrl } = require('../../ui/util/lbrytv'); const PAGES = require('../../ui/constants/pages'); const { getClaim } = require('./chainquery'); const { parseURI } = require('lbry-redux'); @@ -68,7 +68,6 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { // Allow for ovverriding default claim based og metadata const title = overrideOptions.title || claimTitle; const description = overrideOptions.description || claimDescription; - const embedPlayer = overrideOptions.embedPlayer; let head = ''; @@ -90,12 +89,12 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) { head += ``; if (claim.source_media_type && claim.source_media_type.startsWith('video/')) { - const videoUrl = generateStreamUrl(claim.name, claim.claim_id); + const videoUrl = generateEmbedUrl(claim.name, claim.claim_id); head += ``; head += ``; head += ``; head += ``; - head += ``; + head += ``; if (claim.frame_width && claim.frame_height) { head += ``; head += ``; @@ -132,7 +131,6 @@ module.exports.getHtml = async function getHtml(ctx) { const invitePath = `/$/${PAGES.INVITE}/`; const embedPath = `/$/${PAGES.EMBED}/`; - const embedPlayer = URL + path; if (path.includes(invitePath)) { const inviteChannel = path.slice(invitePath.length).replace(/:/g, '#'); @@ -163,7 +161,7 @@ module.exports.getHtml = async function getHtml(ctx) { const claim = await getClaimFromChainquery(claimUri); if (claim) { - const ogMetadata = buildClaimOgMetadata(claimUri, claim, { embedPlayer: embedPlayer}); + const ogMetadata = buildClaimOgMetadata(claimUri, claim); return insertToHead(html, ogMetadata); }