Skip to content

Commit d3d5150

Browse files
authored
Add "Content-Signal" to robots.txt (#4202)
1 parent a17ab65 commit d3d5150

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

.changeset/honest-parts-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": minor
3+
---
4+
5+
Add "Content-Signal" to "robots.txt"

packages/gitbook/src/routes/robots.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function serveRobotsTxt(context: GitBookSiteContext) {
1616
const lines = isIndexable
1717
? [
1818
'User-agent: *',
19+
'Content-Signal: ai-train=yes, search=yes, ai-input=yes',
1920
// Disallow only internal search
2021
'Disallow: /*?*q=*',
2122
'Disallow: /*?*ask=*',
@@ -26,7 +27,7 @@ export async function serveRobotsTxt(context: GitBookSiteContext) {
2627
'Allow: /',
2728
`Sitemap: ${sitemapUrl}`,
2829
]
29-
: ['User-agent: *', 'Disallow: /'];
30+
: ['User-agent: *', 'Content-Signal: ai-train=no, search=no, ai-input=no', 'Disallow: /'];
3031

31-
return new Response(lines.join('\n'), { headers: { 'Content-Type': 'text/plain' } });
32+
return new Response(`${lines.join('\n')}\n`, { headers: { 'Content-Type': 'text/plain' } });
3233
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from 'bun:test';
2+
import { getContentTestURL } from './utils';
3+
4+
describe('robots.txt', () => {
5+
it('declares allow content signals for public sites', async () => {
6+
const response = await fetch(
7+
getContentTestURL(
8+
'https://gitbook.gitbook.io/test-gitbook-open/robots.txt?x-gitbook-search-indexation=1'
9+
)
10+
);
11+
12+
expect(response.status).toBe(200);
13+
expect(response.headers.get('content-type')).toContain('text/plain');
14+
const content = await response.text();
15+
expect(content).toContain('Allow: /\n');
16+
expect(content).toContain('Content-Signal: ai-train=yes, search=yes, ai-input=yes');
17+
});
18+
19+
it('declares deny content signals for share link sites', async () => {
20+
const response = await fetch(
21+
getContentTestURL(
22+
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-share-links/8tNo6MeXg7CkFMzSSz81/robots.txt?x-gitbook-search-indexation=1'
23+
)
24+
);
25+
26+
expect(response.status).toBe(200);
27+
expect(response.headers.get('content-type')).toContain('text/plain');
28+
const content = await response.text();
29+
expect(content).toContain('Disallow: /\n');
30+
expect(content).toContain('Content-Signal: ai-train=no, search=no, ai-input=no');
31+
});
32+
});

0 commit comments

Comments
 (0)