Skip to content

Commit 0c4aec5

Browse files
committed
Fix robots.txt to contain a public link
Replace http://backend from the robots.txt provided by the backend with the public facing url. Also, publish the index file instead of the single file that would be rejected by Google.
1 parent 2a2cf11 commit 0c4aec5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/helpers/Robots/Robots.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
1515
*/
1616
export const generateRobots = (req) =>
1717
new Promise((resolve) => {
18-
//const url = `${req.protocol}://${req.get('Host')}`;
19-
const request = superagent.get(
20-
`${
21-
config.settings.internalApiPath ?? config.settings.apiPath
22-
}/robots.txt`,
23-
);
18+
const internalUrl =
19+
config.settings.internalApiPath ?? config.settings.apiPath;
20+
const request = superagent.get(`${internalUrl}/robots.txt`);
2421
request.set('Accept', 'text/plain');
2522
const authToken = req.universalCookies.get('auth_token');
2623
if (authToken) {
@@ -31,6 +28,12 @@ export const generateRobots = (req) =>
3128
if (error) {
3229
resolve(text || error);
3330
} else {
31+
// Plone has probably returned the sitemap link with the internal url.
32+
// If so, let's replace it with the current one.
33+
const url = `${req.protocol}://${req.get('Host')}`;
34+
text = text.replace(internalUrl, url);
35+
// Replace the sitemap with the sitemap index.
36+
text = text.replace('sitemap.xml.gz', 'sitemap-index.xml');
3437
resolve(text);
3538
}
3639
});

0 commit comments

Comments
 (0)