robotstxt/v1
The app's /robots.txt: which paths crawlers may fetch. The contract owns
three things every crawler-facing extension needs, whoever provides the file:
- Rules.
Disallow,AllowandSitemaplines, per user agent. - Private paths. Prefixes kept out of search: a
Disallowline, left out of the sitemap and llms.txt, and sent withX-Robots-Tag: noindex. Pages'+configprivate:and Settings add them. - Indexable. Whether the app may be indexed at all (off in dev mode and on staging apps). The sitemap is empty when it isn't.
Anyone can read robots.txt. It keeps polite crawlers out; it protects nothing.
A service (robotstxt.go).
Use
Add a rule, in Register or later:
robotstxtv1.Add(app, robotstxtv1.Rule{Disallow: "/mcp", Source: Name})
robotstxtv1.Add(app, robotstxtv1.Rule{UserAgent: "Googlebot", Allow: "/api/files/", Source: Name})
robotstxtv1.Private(app, "/account", Name) // Disallow + left out of the sitemap and llms.txt + noindex
Rules that change at run time come from a function, called each time the file or the private list is read (keep it cheap):
robotstxtv1.AddFunc(app, func(app core.App) []robotstxtv1.Rule {
return []robotstxtv1.Rule{{Disallow: "/drafts", Private: true, Source: Name}}
})
Anything that lists the app's URLs (a sitemap, llms.txt) leaves private paths out:
private := robotstxtv1.PrivatePrefixes(app)
if robotstxtv1.Under(path, private) { /* skip it */ }
if !robotstxtv1.Indexable(app) { /* list nothing */ }
Under matches whole segments: /account covers /account and /account/x, not /accounts. CleanPrefix turns
user input into a prefix (adds the leading /, rejects whitespace).
Declare WorksWith: extkit.IDs("robotstxt/v1"). pb_hooks add rules with $robotsTxt.add({...}) and
$robotsTxt.private(prefix) (see robots.txt).
Provide
Implement robotstxtv1.Builder: Build returns the whole file for a request from robotstxtv1.Rules(app), and
Indexable says whether the app may be indexed. Serve it at /robots.txt only when the app has none of its own: a
pb_pages or pb_public file, or a route, always wins. With no provider, Indexable(app) is true.
Extensions
| Extension | |
|---|---|
| robots-txt | provides (default) |
| mcp | works with |
| pages | works with |
| sitemap-xml | works with |
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.