-
-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add robots.txt setting. #5584
base: main
Are you sure you want to change the base?
Add robots.txt setting. #5584
Changes from 3 commits
7ba54b3
e4a3767
442520b
ad3d9e1
7a30c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Expose robots.txt setting in Volto control panel, and render robots.txt based on REST API call. @robgietema | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
/** | ||
* Sitemap helper. | ||
* @module helpers/Sitemap | ||
* Robots helper. | ||
* @module helpers/Robots | ||
*/ | ||
|
||
import superagent from 'superagent'; | ||
|
||
import config from '@plone/volto/registry'; | ||
import { formatUrl } from '@plone/volto/helpers/Api/Api'; | ||
import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy'; | ||
|
||
/** | ||
|
@@ -15,41 +17,23 @@ import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy'; | |
*/ | ||
export const generateRobots = (req) => | ||
new Promise((resolve) => { | ||
const internalUrl = | ||
sneridagh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config.settings.internalApiPath ?? config.settings.apiPath; | ||
const request = superagent.get(`${internalUrl}/robots.txt`); | ||
request.set('Accept', 'text/plain'); | ||
const request = superagent.get(formatUrl('@site')); | ||
request.set('Accept', 'application/json'); | ||
const authToken = req.universalCookies.get('auth_token'); | ||
if (authToken) { | ||
request.set('Authorization', `Bearer ${authToken}`); | ||
} | ||
request.use(addHeadersFactory(req)); | ||
request.end((error, { text }) => { | ||
request.end((error, { text, body }) => { | ||
if (error) { | ||
resolve(text || error); | ||
} else { | ||
// It appears that express does not take the x-forwarded headers into | ||
sneridagh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// consideration, so we do it ourselves. | ||
const { | ||
'x-forwarded-proto': forwardedProto, | ||
'x-forwarded-host': forwardedHost, | ||
'x-forwarded-port': forwardedPort, | ||
} = req.headers; | ||
const proto = forwardedProto ?? req.protocol; | ||
const host = forwardedHost ?? req.get('Host'); | ||
const portNum = forwardedPort ?? req.get('Port'); | ||
const port = | ||
(proto === 'https' && '' + portNum === '443') || | ||
(proto === 'http' && '' + portNum === '80') | ||
? '' | ||
: `:${portNum}`; | ||
// Plone has probably returned the sitemap link with the internal url. | ||
// If so, let's replace it with the current one. | ||
const url = `${proto}://${host}${port}`; | ||
text = text.replace(internalUrl, url); | ||
// Replace the sitemap with the sitemap index. | ||
text = text.replace('sitemap.xml.gz', 'sitemap-index.xml'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sneridagh @ericof Removing this replacement is a breaking change. We should keep it here, or handle it instead in plone/plone.volto#183 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, however I think it has to go to plone.volto too. Although that can be a breaking change, since it can mean an action needed in Google Search Consoles of people. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sneridagh No, it's not a breaking change. It was getting replaced before, and it still will be. |
||
resolve(text); | ||
resolve( | ||
body['plone.robots_txt'].replace( | ||
'{portal_url}', | ||
config.settings.publicURL, | ||
), | ||
davisagli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it exposed in the Volto control panel? I don't see it there. I expect it needs to be removed from
volto/packages/volto/src/config/ControlPanels.js
Line 79 in 5c88b0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but related to the other comment:
The backend answer with the .gz, which we will override it afterwards in a shady way in code (btw, we are doing it right now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sneridagh @ericof Let's change the sitemap to use sitemap-index.xml in the backend setting in plone/plone.volto#183