Use `rel=canonical` link to de-duplicate event permalinks
Fix https://github.com/matrix-org/matrix-public-archive/issues/251
This commit is contained in:
parent
3414fcf7b2
commit
fdfea1155c
|
@ -71,6 +71,11 @@ function renderPageHtml({
|
||||||
metaImageUrl = pageOptions.imageUrl;
|
metaImageUrl = pageOptions.imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let maybeRelCanonical = '';
|
||||||
|
if (pageOptions.canonicalUrl) {
|
||||||
|
maybeRelCanonical = sanitizeHtml(`<link rel="canonical" href="${pageOptions.canonicalUrl}">`);
|
||||||
|
}
|
||||||
|
|
||||||
const pageHtml = `
|
const pageHtml = `
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -83,6 +88,7 @@ function renderPageHtml({
|
||||||
${sanitizeHtml(`<meta property="og:image" content="${metaImageUrl}">`)}
|
${sanitizeHtml(`<meta property="og:image" content="${metaImageUrl}">`)}
|
||||||
<link rel="icon" href="${pageAssetUrls.faviconIco}" sizes="any">
|
<link rel="icon" href="${pageAssetUrls.faviconIco}" sizes="any">
|
||||||
<link rel="icon" href="${pageAssetUrls.faviconSvg}" type="image/svg+xml">
|
<link rel="icon" href="${pageAssetUrls.faviconSvg}" type="image/svg+xml">
|
||||||
|
${maybeRelCanonical}
|
||||||
${styles
|
${styles
|
||||||
.map(
|
.map(
|
||||||
(styleUrl) =>
|
(styleUrl) =>
|
||||||
|
|
|
@ -917,6 +917,18 @@ router.get(
|
||||||
blockedBySafeSearch: isNsfw,
|
blockedBySafeSearch: isNsfw,
|
||||||
entryPoint: 'client/js/entry-client-hydrogen.js',
|
entryPoint: 'client/js/entry-client-hydrogen.js',
|
||||||
locationHref: urlJoin(basePath, req.originalUrl),
|
locationHref: urlJoin(basePath, req.originalUrl),
|
||||||
|
canonicalUrl: matrixPublicArchiveURLCreator.archiveUrlForDate(
|
||||||
|
roomIdOrAlias,
|
||||||
|
new Date(toTimestamp),
|
||||||
|
{
|
||||||
|
preferredPrecision: precisionFromUrl,
|
||||||
|
// We purposely omit `scrollStartEventId` here because the canonical location
|
||||||
|
// for any given event ID is the page it resides on.
|
||||||
|
//
|
||||||
|
// We can avoid passing along the `viaServers` because we already joined the
|
||||||
|
// room above (see `ensureRoomJoined`).
|
||||||
|
}
|
||||||
|
),
|
||||||
shouldIndex,
|
shouldIndex,
|
||||||
cspNonce: res.locals.cspNonce,
|
cspNonce: res.locals.cspNonce,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue