avoid search engines following 404ing internal links from descriptions
This commit is contained in:
parent
906acde9bd
commit
478b760af1
|
|
@ -55,6 +55,34 @@ app.get('/watch', async ({ query: { v }, set, redirect, error }) => {
|
|||
.execute()
|
||||
}
|
||||
|
||||
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
|
||||
if (node.tagName === 'A') {
|
||||
const disallowedPatterns: RegExp[] = [
|
||||
/\/playlist/i,
|
||||
/\/hashtag\//i,
|
||||
/\/live\//i,
|
||||
/\/user\//i,
|
||||
/\/shorts\//i,
|
||||
/\/c\//i,
|
||||
/\/@[^\/]/i
|
||||
];
|
||||
const href = node.getAttribute('href') || '';
|
||||
|
||||
const shouldConvertToSpan = disallowedPatterns.some(pattern =>
|
||||
pattern.test(href)
|
||||
);
|
||||
|
||||
if (shouldConvertToSpan) {
|
||||
const span = node.ownerDocument.createElement('span');
|
||||
span.innerHTML = node.innerHTML;
|
||||
if (node.className) span.className = node.className;
|
||||
node.parentNode?.replaceChild(span, node);
|
||||
} else {
|
||||
node.setAttribute('rel', 'nofollow noopener noreferrer');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const html = await m(eta.render('./watch', {
|
||||
transparency,
|
||||
...json,
|
||||
|
|
|
|||
Loading…
Reference in New Issue