Merge pull request #132 from lbryio/open-graph

Open graph
This commit is contained in:
Bill Bittner 2017-08-07 22:09:35 -07:00 committed by GitHub
commit d3f1e2d3f8
10 changed files with 110 additions and 20 deletions

View file

@ -60,6 +60,15 @@ function checkLocalDbForClaims (name, shortUrl) {
});
}
function createOpenGraphInfo ({ fileType, claimId, name, fileName, fileExt }) {
return {
twitterPlayerUrl: `https://spee.ch/twitterPlayer/${claimId}/${name}`,
showUrl : `https://spee.ch/${claimId}/${name}`,
source : `https://spee.ch/${claimId}/${name}${fileExt}`,
directFileUrl : `https://spee.ch/media/${fileName}`,
};
}
module.exports = {
serveFile ({ fileName, fileType, filePath }, res) {
logger.info(`serving file ${fileName}`);
@ -86,11 +95,12 @@ module.exports = {
res.status(200).sendFile(filePath, options);
},
showFile (fileInfo, res) {
res.status(200).render('show', { layout: 'show', fileInfo });
const openGraphInfo = createOpenGraphInfo(fileInfo);
res.status(200).render('show', { layout: 'show', fileInfo, openGraphInfo });
},
showFileLite (fileInfo, res) {
logger.debug('showing file lite');
res.status(200).render('showLite', { layout: 'show', fileInfo });
const openGraphInfo = createOpenGraphInfo(fileInfo);
res.status(200).render('showLite', { layout: 'show', fileInfo, openGraphInfo });
},
getClaimIdFromShortUrl (shortUrl, name) {
return new Promise((resolve, reject) => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -36,6 +36,14 @@ module.exports = (app) => {
});
});
// route to display all free public claims at a given name
app.get('/twitterPlayer/:claimId/:fileName', ({ params }, res) => {
const claimId = params.claimId;
const fileName = params.fileName;
const fileExtension = '.mp4';
// get and render the content
res.status(200).render('twitterPlayer', { layout: 'twitterPlayer', claimId, fileName, fileExtension });
});
// route to display all free public claims at a given name
app.get('/:name/all', ({ ip, originalUrl, params }, res) => {
// get and render the content
getAllFreePublicClaims(params.name)

View file

@ -92,13 +92,9 @@ module.exports = (app) => {
} else {
method = SERVE;
}
} else {
if (headers['accept'] && !headers['accept'].split(',').includes('text/html')) {
method = SERVE;
} else {
method = SHOW;
}
}
/* start: temporary patch for backwards compatability spee.ch/name/claim_id */
if (isValidShortUrlOrClaimId(name) && !isValidShortUrlOrClaimId(identifier)) {
let tempName = name;

View file

@ -48,6 +48,58 @@ const hbs = expressHandlebars.create({
</script>`
);
},
addOpenGraph (title, mimeType, showUrl, source) {
let basicTags = `<meta property="og:title" content="${title}"/>
<meta property="og:url" content="${showUrl}" />
<meta property="og:site_name" content="Spee.ch" />
<meta property="og:description" content="View or download ${title} from spee.ch: the open-source, decentralized content host." />`;
if (mimeType === 'video/mp4') {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="https://spee.ch/assets/img/content-freedom-large.png" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="315" />
<meta property="og:type" content="video" />
<meta property="og:video" content="${source}" />
<meta property="og:video:secure_url" content="${source}" />
<meta property="og:video:type" content="${mimeType}" />`
);
} else if (mimeType === 'image/gif') {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="${source}" />
<meta property="og:image:type" content="${mimeType}" />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="315" />
<meta property="og:type" content="video.other" />`
);
} else {
return new Handlebars.SafeString(
`${basicTags} <meta property="og:image" content="${source}" />
<meta property="og:image:type" content="${mimeType}" />
<meta property="og:image:width" content="600" />
<meta property="og:image:height" content="315" />
<meta property="og:type" content="article" />`
);
}
},
addTwitterCard (mimeType, source, twitterPlayerUrl, directFileUrl) {
let basicTwitterTags = `<meta name="twitter:site" content="@lbryio" />`;
if (mimeType === 'video/mp4') {
return new Handlebars.SafeString(
`${basicTwitterTags} <meta name="twitter:card" content="player" />
<meta name="twitter:player" content="${twitterPlayerUrl}>
<meta name="twitter:player:width" content="480" />
<meta name="twitter:player:height" content="480" />
<meta name="twitter:player:stream" content="${directFileUrl}" />
<meta name="twitter:player:stream:content_type" content="video/mp4" />
`
);
} else {
return new Handlebars.SafeString(
`${basicTwitterTags} <meta name="twitter:card" content="summary_large_image" />`
);
}
},
ifConditional (varOne, operator, varTwo, options) {
switch (operator) {
case '===':

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
@ -7,7 +7,14 @@
<title>Spee.ch</title>
<link rel="stylesheet" href="/assets/css/generalStyle.css" type="text/css">
<link rel="stylesheet" href="/assets/css/componentStyle.css" type="text/css">
{{ twitterCard }}
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@lbryio" />
<meta property="og:title" content="spee.ch">
<meta property="og:site_name" content="spee.ch">
<meta property="og:type" content="website">
<meta property="og:image" content="https://spee.ch/assets/img/content-freedom-64px.png">
<meta property="og:url" content="http://spee.ch/">
<meta property="og:description" content="Open-source, decentralized image and video hosting.">
</head>
<body>
{{{ body }}}

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
@ -7,13 +7,9 @@
<title>Spee.ch</title>
<link rel="stylesheet" href="/assets/css/generalStyle.css" type="text/css">
<link rel="stylesheet" href="/assets/css/componentStyle.css" type="text/css">
<!-- twitter card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@spee.ch">
<meta name="twitter:creator" content="@spee.ch">
<meta name="twitter:title" content="{{fileInfo.name}}">
<meta name="twitter:description" content="An image hosted via Spee.ch">
<meta name="twitter:image" content="https://spee.ch/media/{{fileInfo.fileName}}">
<meta property="fb:app_id" content="1371961932852223">
{{{addTwitterCard fileInfo.fileType openGraphInfo.source openGraphInfo.twitterPlayerUrl openGraphInfo.directFileUrl}}}
{{{addOpenGraph fileInfo.name fileInfo.fileType openGraphInfo.showUrl openGraphInfo.source}}}
</head>
<body>
{{{ body }}}
@ -21,3 +17,7 @@
{{ googleAnalytics }}
</body>
</html>
<script>
</script>

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body>
<style type="text/css">
video {
width:100%;
max-width:600px;
height:auto;
}
</style>
{{{body}}}
</body>
</html>

View file

@ -0,0 +1 @@
<video id="video" width="100%" controls src="https://spee.ch/{{claimId}}/{{fileName}}{{fileExtension}}" type="video/mp4"></video>