feat: site endpoint, llms.txt and the sitemap index in robots.txt

- GET /_seo/api/v1/site (public, noindex): site_url, default_locale,
  locales, unprefixed_locale, links.new_tab, html_sitemap (from the
  sitemap plugin's Listing), routes of every content type, root_files
  (verification files and the IndexNow key file) and llms
- GET /llms.txt: with llms_enabled (robots.txt screen, AI bots tab, off by
  default) and in production, the indexable pages from the sitemaps per
  group under the site name and llms_intro (else the default
  description); otherwise 404; seo_update_robots takes both fields
- robots.txt names the sitemap plugin's index unless
  golem15.seo.robots_sitemaps is set; the config default is now a comment
This commit is contained in:
Jakub Zych
2026-11-04 13:32:12 +01:00
parent 49d3879954
commit 742a5b930b
16 changed files with 645 additions and 29 deletions

View File

@@ -11,8 +11,8 @@ import (
)
// RobotsSitemapsConfigKey lists the sitemap addresses robots.txt names,
// one Sitemap line each, absolute on the site URL (P-23); default
// ["/sitemap.xml"].
// one Sitemap line each, absolute on the site URL (P-23). Unset, robots.txt
// names the sitemap plugin's index (D-22, SitemapLines).
const RobotsSitemapsConfigKey = "golem15.seo.robots_sitemaps"
// MaxRobotsBytes is the largest robots.txt the editor stores: Google
@@ -29,8 +29,49 @@ const (
FallbackRobots = "User-agent: *\nDisallow:\n"
)
// SitemapLines are the addresses of robots.txt's Sitemap lines (D-22):
// golem15.seo.robots_sitemaps when it is set, else the sitemap index of
// the sitemap plugin's contract.Listing (its IndexURL), else /sitemap.xml
// on the site URL. The per-type files are never listed: the index names
// them.
func (s *Service) SitemapLines(ctx context.Context) []string {
if s.robotsSitemapsSet() {
return s.RobotsSitemaps()
}
if l := s.listing(); l != nil {
if st, err := l.Settings(ctx); err == nil && strings.TrimSpace(st.IndexURL) != "" {
return []string{strings.TrimSpace(st.IndexURL)}
} else if err != nil {
log.Warn("golem15.seo: sitemap index address", "error", err)
}
}
return s.RobotsSitemaps()
}
// robotsSitemapsSet reports whether golem15.seo.robots_sitemaps is set to
// a non-empty list.
func (s *Service) robotsSitemapsSet() bool {
cfg := s.Config()
if cfg == nil {
return false
}
raw, ok := cfg.Lookup(RobotsSitemapsConfigKey)
if !ok || raw == nil {
return false
}
switch v := raw.(type) {
case []any:
return len(v) > 0
case []string:
return len(v) > 0
case string:
return strings.TrimSpace(v) != ""
}
return false
}
// RobotsSitemaps returns the configured sitemap addresses, absolute on
// the site URL.
// the site URL; /sitemap.xml when none is configured.
func (s *Service) RobotsSitemaps() []string {
var list []string
if cfg := s.Config(); cfg != nil {
@@ -128,7 +169,7 @@ func (s *Service) ServedFile(ctx context.Context, production bool) (string, erro
if err != nil {
return "", err
}
body := ComposeRobots(row.Content, row.Bots, s.RobotsSitemaps())
body := ComposeRobots(row.Content, row.Bots, s.SitemapLines(ctx))
if s != nil {
s.robots.Store(&body)
}
@@ -164,7 +205,7 @@ type RobotsTest struct {
// grobotstxt, Google's matcher (D-22, D-99): longest match, Allow wins a
// tie, * and $.
func (s *Service) TestRobots(content string, bots models.BotSwitches, agent, path string) RobotsTest {
file := ComposeRobots(content, bots, s.RobotsSitemaps())
file := ComposeRobots(content, bots, s.SitemapLines(context.Background()))
uri := AbsoluteURL(s.SiteURL(), path)
if s.SiteURL() == "" {
uri = "http://localhost" + path