Pull banner into og:image

This commit is contained in:
Eric Eastwood 2023-05-09 22:24:57 -05:00
parent d37fc5779f
commit e7023012cc
6 changed files with 50 additions and 35 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

@ -8,3 +8,4 @@ import '../css/room-directory.css';
// over for all
import '../img/favicon.ico';
import '../img/favicon.svg';
import '../img/matrix-public-archive-opengraph.png';

View File

@ -1,12 +1,32 @@
'use strict';
const assert = require('assert');
const urlJoin = require('url-join');
const { getSerializableSpans } = require('../tracing/tracing-middleware');
const sanitizeHtml = require('../lib/sanitize-html');
const safeJson = require('../lib/safe-json');
const getDependenciesForEntryPointName = require('../lib/get-dependencies-for-entry-point-name');
const getFaviconAssetUrls = require('../lib/get-favicon-asset-urls');
const getAssetUrl = require('../lib/get-asset-url');
const config = require('../lib/config');
const basePath = config.get('basePath');
assert(basePath);
let _assetUrls;
function getAssetUrls() {
// Probably not that much overhead but only calculate this once
if (_assetUrls) {
return _assetUrls;
}
_assetUrls = {
faviconIco: getAssetUrl('client/img/favicon.ico'),
faviconSvg: getAssetUrl('client/img/favicon.svg'),
opengraphImage: getAssetUrl('client/img/matrix-public-archive-opengraph.png'),
};
return _assetUrls;
}
function renderPageHtml({
pageOptions,
@ -45,12 +65,12 @@ function renderPageHtml({
maybeAdultMeta = `<meta name="rating" content="adult">`;
}
let metaImageUrl = 'TODO';
const pageAssetUrls = getAssetUrls();
let metaImageUrl = urlJoin(basePath, pageAssetUrls.opengraphImage);
if (pageOptions.imageUrl) {
metaImageUrl = pageOptions.imageUrl;
}
const faviconMap = getFaviconAssetUrls();
const pageHtml = `
<!doctype html>
<html lang="en">
@ -61,8 +81,8 @@ function renderPageHtml({
${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">
<link rel="icon" href="${pageAssetUrls.faviconIco}" sizes="any">
<link rel="icon" href="${pageAssetUrls.faviconSvg}" type="image/svg+xml">
${styles
.map(
(styleUrl) =>

View File

@ -0,0 +1,24 @@
'use strict';
const path = require('path').posix;
function getAssetUrl(inputAssetPath) {
// Lazy-load the manifest so we only require it on first call hopefully after the Vite
// client build completes. `require(...)` calls are cached so it should be fine to
// look this up over and over.
//
// We have to disable the `no-missing-require` because the file is built via the Vite client build.
// eslint-disable-next-line n/no-missing-require, n/no-unpublished-require
const manfiest = require('../../dist/manifest.json');
const assetEntry = manfiest[inputAssetPath];
if (!assetEntry) {
throw new Error(`Could not find asset with path "${inputAssetPath}" in \`dist/manifest.json\``);
}
const outputAssetPath = path.join('/', assetEntry.file);
return outputAssetPath;
}
module.exports = getAssetUrl;

View File

@ -1,30 +0,0 @@
'use strict';
const path = require('path').posix;
let _faviconAssetUrls;
function getFaviconAssetUrls() {
// Probably not that much overhead but only calculate this once
if (_faviconAssetUrls) {
return _faviconAssetUrls;
}
// Lazy-load the manifest so we only require it on first call hopefully after the Vite
// client build completes. `require(...)` calls are cached so it should be fine to
// look this up over and over.
//
// We have to disable this because it's built via the Vite client build.
// eslint-disable-next-line n/no-missing-require, n/no-unpublished-require
const manifest = require('../../dist/manifest.json');
const icoAssetPath = path.join('/', manifest['client/img/favicon.ico'].file);
const svgAssetFile = path.join('/', manifest['client/img/favicon.svg'].file);
_faviconAssetUrls = {
ico: icoAssetPath,
svg: svgAssetFile,
};
return _faviconAssetUrls;
}
module.exports = getFaviconAssetUrls;