From 352819ef921e45381b3fbb17072926103b320e73 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 5 Aug 2021 13:29:10 +0200 Subject: [PATCH] Do not index remote actors --- server/lib/client-html.ts | 11 +++++++++-- server/tests/client.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index a557c090f..e093d35f7 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -44,6 +44,8 @@ type Tags = { originUrl: string description: string + disallowIndexation?: boolean + embed?: { url: string createdAt: string @@ -285,7 +287,8 @@ class ClientHtml { image, ogType, twitterCard, - schemaType + schemaType, + disallowIndexation: !entity.Actor.isOwned() }) return customHtml @@ -488,7 +491,7 @@ class ClientHtml { const twitterCardMetaTags = this.generateTwitterCardMetaTags(tagsValues) const schemaTags = this.generateSchemaTags(tagsValues) - const { url, title, embed, originUrl } = tagsValues + const { url, title, embed, originUrl, disallowIndexation } = tagsValues const oembedLinkTags: { type: string, href: string, title: string }[] = [] @@ -536,6 +539,10 @@ class ClientHtml { // SEO, use origin URL tagsString += `` + if (disallowIndexation) { + tagsString += `` + } + return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsString) } } diff --git a/server/tests/client.ts b/server/tests/client.ts index 4cbdb2cb3..4f0d052c8 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -445,6 +445,40 @@ describe('Test a client controllers', function () { } } }) + + it('Should add noindex meta tag for remote accounts', async function () { + const handle = 'root@' + servers[0].host + const paths = [ '/accounts/', '/a/', '/@' ] + + for (const path of paths) { + { + const { text } = await makeHTMLRequest(servers[1].url, path + handle) + expect(text).to.contain('') + } + + { + const { text } = await makeHTMLRequest(servers[0].url, path + handle) + expect(text).to.not.contain('') + } + } + }) + + it('Should add noindex meta tag for remote accounts', async function () { + const handle = 'root_channel@' + servers[0].host + const paths = [ '/video-channels/', '/c/', '/@' ] + + for (const path of paths) { + { + const { text } = await makeHTMLRequest(servers[1].url, path + handle) + expect(text).to.contain('') + } + + { + const { text } = await makeHTMLRequest(servers[0].url, path + handle) + expect(text).to.not.contain('') + } + } + }) }) describe('Embed HTML', function () {