Skip to content

Commit 5285518

Browse files
authored
feat: defaults to noindex nofollow (#11623)
We now have the ability to define all page metadata for the admin panel via the Payload Config as a result of #11593. This means we can now set sensible defaults for additional properties, e.g. `noindex` and `nofollow` on the `robots` property. Setting this will prevent these pages from being indexed and appearing in search results. Note that setting this property prevents _indexing_ these pages, but does not prevent them from being _crawled_. To prevent crawling as well, you must add a standalone `robots.txt` file to your root directory.
1 parent 243cdb1 commit 5285518

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

docs/admin/metadata.mdx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ The following options are available for Root Metadata:
5353
| Key | Type | Description |
5454
| --- | --- | --- |
5555
| `defaultOGImageType` | `dynamic` (default), `static`, or `off` | The type of default OG image to use. If set to `dynamic`, Payload will use Next.js image generation to create an image with the title of the page. If set to `static`, Payload will use the `defaultOGImage` URL. If set to `off`, Payload will not generate an OG image. |
56-
| `icons` | `IconConfig[]` | An array of icon objects. [More details](#icons). |
5756
| `titleSuffix` | `string` | A suffix to append to the end of the title of every page. Defaults to "- Payload". |
5857
| `[keyof Metadata]` | `unknown` | Any other properties that Next.js supports within the `generateMetadata` function. [More details](https://nextjs.org/docs/app/api-reference/functions/generate-metadata). |
5958

@@ -68,7 +67,7 @@ The Icons Config corresponds to the `<link>` tags that are used to specify icons
6867

6968
The most common icon type is the favicon, which is displayed in the browser tab. This is specified by the `rel` attribute `icon`. Other common icon types include `apple-touch-icon`, which is used by Apple devices when the Admin Panel is saved to the home screen, and `mask-icon`, which is used by Safari to mask the Admin Panel icon.
7069

71-
To customize icons, use the `icons` key within the `admin.meta` object in your Payload Config:
70+
To customize icons, use the `admin.meta.icons` property in your Payload Config:
7271

7372
```ts
7473
{
@@ -100,7 +99,7 @@ For a full list of all available Icon options, see the [Next.js documentation](h
10099

101100
Open Graph metadata is a set of tags that are used to control how URLs are displayed when shared on social media platforms. Open Graph metadata is automatically generated by Payload, but can be customized at the Root level.
102101

103-
To customize Open Graph metadata, use the `openGraph` key within the `admin.meta` object in your Payload Config:
102+
To customize Open Graph metadata, use the `admin.meta.openGraph` property in your Payload Config:
104103

105104
```ts
106105
{
@@ -128,6 +127,45 @@ To customize Open Graph metadata, use the `openGraph` key within the `admin.meta
128127

129128
For a full list of all available Open Graph options, see the [Next.js documentation](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#opengraph).
130129

130+
### Robots
131+
132+
Setting the `robots` property will allow you to control the `robots` meta tag that is rendered within the `<head>` of the Admin Panel. This can be used to control how search engines index pages and displays them in search results.
133+
134+
By default, the Admin Panel is set to prevent search engines from indexing pages within the Admin Panel.
135+
136+
To customize the Robots Config, use the `admin.meta.robots` property in your Payload Config:
137+
138+
```ts
139+
{
140+
// ...
141+
admin: {
142+
meta: {
143+
// highlight-start
144+
robots: 'noindex, nofollow',
145+
// highlight-end
146+
},
147+
},
148+
}
149+
```
150+
151+
For a full list of all available Robots options, see the [Next.js documentation](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#robots).
152+
153+
##### Prevent Crawling
154+
155+
While setting meta tags via `admin.meta.robots` can prevent search engines from _indexing_ web pages, it does not prevent them from being _crawled_.
156+
157+
To prevent your pages from being crawled altogether, add a `robots.txt` file to your root directory.
158+
159+
```txt
160+
User-agent: *
161+
Disallow: /admin/
162+
```
163+
164+
<Banner type="info">
165+
**Note:**
166+
If you've customized the path to your Admin Panel via `config.routes`, be sure to update the `Disallow` directive to match your custom path.
167+
</Banner>
168+
131169
## Collection Metadata
132170

133171
Collection Metadata is the metadata that is applied to all pages within any given Collection within the Admin Panel. This metadata is used to customize the title and description of all views within any given Collection, unless overridden by the view itself.

packages/payload/src/config/defaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const defaults: Omit<Config, 'db' | 'editor' | 'secret'> = {
1818
},
1919
meta: {
2020
defaultOGImageType: 'dynamic',
21+
robots: 'noindex, nofollow',
2122
titleSuffix: '- Payload',
2223
},
2324
routes: {
@@ -91,6 +92,7 @@ export const addDefaultsToConfig = (config: Config): Config => {
9192
},
9293
meta: {
9394
defaultOGImageType: 'dynamic',
95+
robots: 'noindex, nofollow',
9496
titleSuffix: '- Payload',
9597
...(config?.admin?.meta || {}),
9698
},

test/admin/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export default buildConfigWithDefaults({
129129
description: 'This is a custom OG description',
130130
title: 'This is a custom OG title',
131131
},
132-
robots: 'nofollow noindex',
133132
titleSuffix: '- Custom Title Suffix',
134133
},
135134
routes: customAdminRoutes,

test/admin/e2e/general/e2e.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ describe('General', () => {
158158
})
159159
})
160160

161+
describe('robots', () => {
162+
test('should apply default robots meta tag', async () => {
163+
await page.goto(`${serverURL}/admin`)
164+
await expect(page.locator('meta[name="robots"]')).toHaveAttribute(
165+
'content',
166+
/noindex, nofollow/,
167+
)
168+
})
169+
})
170+
161171
describe('favicons', () => {
162172
test('should render custom favicons', async () => {
163173
await page.goto(postsUrl.admin)

0 commit comments

Comments
 (0)