Add images to URL previews
This commit is contained in:
parent
bf8040f48e
commit
d37fc5779f
Binary file not shown.
After Width: | Height: | Size: 234 KiB |
Binary file not shown.
After Width: | Height: | Size: 392 KiB |
|
@ -45,6 +45,11 @@ function renderPageHtml({
|
|||
maybeAdultMeta = `<meta name="rating" content="adult">`;
|
||||
}
|
||||
|
||||
let metaImageUrl = 'TODO';
|
||||
if (pageOptions.imageUrl) {
|
||||
metaImageUrl = pageOptions.imageUrl;
|
||||
}
|
||||
|
||||
const faviconMap = getFaviconAssetUrls();
|
||||
const pageHtml = `
|
||||
<!doctype html>
|
||||
|
@ -55,6 +60,7 @@ function renderPageHtml({
|
|||
${maybeAdultMeta}
|
||||
${sanitizeHtml(`<title>${pageOptions.title}</title>`)}
|
||||
${sanitizeHtml(`<meta name="description" content="${pageOptions.description}">`)}
|
||||
${sanitizeHtml(`<meta property="og:image" content="${metaImageUrl}">`)}
|
||||
<link rel="icon" href="${faviconMap.ico}" sizes="any">
|
||||
<link rel="icon" href="${faviconMap.svg}" type="image/svg+xml">
|
||||
${styles
|
||||
|
|
|
@ -26,6 +26,7 @@ const renderHydrogenVmRenderScriptToPageHtml = require('../hydrogen-render/rende
|
|||
const setHeadersToPreloadAssets = require('../lib/set-headers-to-preload-assets');
|
||||
const setHeadersForDateTemporalContext = require('../lib/set-headers-for-date-temporal-context');
|
||||
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
|
||||
const { mxcUrlToHttpThumbnail } = require('matrix-public-archive-shared/lib/mxc-url-to-http');
|
||||
const checkTextForNsfw = require('matrix-public-archive-shared/lib/check-text-for-nsfw');
|
||||
const {
|
||||
MS_LOOKUP,
|
||||
|
@ -906,6 +907,11 @@ router.get(
|
|||
const pageOptions = {
|
||||
title: `${roomData.name} - Matrix Public Archive`,
|
||||
description: `View the history of ${roomData.name} in the Matrix Public Archive`,
|
||||
imageUrl: mxcUrlToHttpThumbnail({
|
||||
mxcUrl: roomData.avatarUrl,
|
||||
homeserverUrl: matrixServerUrl,
|
||||
size: 256,
|
||||
}),
|
||||
blockedBySafeSearch: isNsfw,
|
||||
entryPoint: 'client/js/entry-client-hydrogen.js',
|
||||
locationHref: urlJoin(basePath, req.originalUrl),
|
||||
|
|
|
@ -13,15 +13,21 @@ function mxcUrlToHttp({ mxcUrl, homeserverUrl }) {
|
|||
)}`;
|
||||
}
|
||||
|
||||
function mxcUrlToHttpThumbnail({ mxcUrl, homeserverUrl, size }) {
|
||||
const ALLOWED_RESIZE_METHODS = ['scale', 'crop'];
|
||||
function mxcUrlToHttpThumbnail({ mxcUrl, homeserverUrl, size, resizeMethod = 'scale' }) {
|
||||
assert(mxcUrl, '`mxcUrl` must be provided to `mxcUrlToHttp(...)`');
|
||||
assert(homeserverUrl, '`homeserverUrl` must be provided to `mxcUrlToHttp(...)`');
|
||||
assert(size, '`size` must be provided to `mxcUrlToHttp(...)`');
|
||||
assert(
|
||||
ALLOWED_RESIZE_METHODS.includes(resizeMethod),
|
||||
`\`resizeMethod\` must be ${JSON.stringify(ALLOWED_RESIZE_METHODS)}`
|
||||
);
|
||||
const [serverName, mediaId] = mxcUrl.substr('mxc://'.length).split('/');
|
||||
|
||||
let qs = new URLSearchParams();
|
||||
qs.append('width', Math.round(size));
|
||||
qs.append('height', Math.round(size));
|
||||
qs.append('method', resizeMethod);
|
||||
|
||||
const url = homeserverUrl.replace(/\/$/, '');
|
||||
return `${url}/_matrix/media/r0/thumbnail/${encodeURIComponent(serverName)}/${encodeURIComponent(
|
||||
|
|
Loading…
Reference in New Issue