Skip to content

Allow subscribers to set a custom robots.txt#945

Draft
lylo wants to merge 4 commits into
mainfrom
custom-robots-txt
Draft

Allow subscribers to set a custom robots.txt#945
lylo wants to merge 4 commits into
mainfrom
custom-robots-txt

Conversation

@lylo

@lylo lylo commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Subscribed blogs can now override the generated robots.txt via Settings → Blog → Discoverability
  • /robots.txt serves the custom value when present and the owner is subscribed; non-subscribers and lapsed users get the generated default
  • Lapsed users keep a "Reset to Pagecord default" button so they can remove a previously-saved override even though editing requires an active subscription

Implementation

  • New Blog::RobotsTxt concern owns generation, normalisation, and validation. Validates UTF-8, 10 KB max, control chars, and the supported directives (User-agent / Allow / Disallow / Sitemap / Crawl-delay)
  • Blogs::RobotsController#show renders directly from the model (deletes app/views/blogs/robots/show.text.erb)
  • New App::Settings::RobotsController exposes PATCH (subscribers only) and DELETE (any owner) on /app/settings/robots
  • Inline form section uses a small Stimulus controller and detached form_with shells via HTML5 form="…" association so the controls live inside the existing blog settings form

Test plan

  • bin/rails test test/models/concerns/blog/robots_txt_test.rb test/controllers/blogs/robots_controller_test.rb test/controllers/app/settings/robots_controller_test.rb test/controllers/app/settings/blogs_controller_test.rb
  • Manual: subscriber enables custom robots.txt → saved value served at /robots.txt
  • Manual: subscriber unchecks "Use custom robots.txt" → only Reset button visible; clicking it clears the override
  • Manual: free / free-trial user sees disabled controls and the subscription placeholder
  • Manual: lapsed subscriber with a saved override sees their content (read-only) and a working Reset button; /robots.txt falls back to the default
  • Manual: discoverability off + no custom override still serves User-agent: *\nDisallow: /
  • Manual: invalid input (e.g. Host:, Bad Bot, oversized) is rejected with a field error

Subscribed blogs can override the generated robots.txt via Settings →
Blog. The override is served from /robots.txt when present and the
owner is subscribed; non-subscribers fall back to the generated
default.

The settings UI uses a "Use custom robots.txt" checkbox and a textarea
inside the existing Blog Settings form — saving and clearing both go
through the page-level Update button. Validation covers UTF-8, size,
control chars, and the supported directives (User-agent, Allow,
Disallow, Sitemap, Crawl-delay).
@lylo lylo force-pushed the custom-robots-txt branch from a74fb1d to 838bcd3 Compare May 5, 2026 16:38
lylo added 3 commits May 5, 2026 17:51
- Drop bespoke Stimulus controller; use Tailwind group-has-[input:checked]
  to drive editor visibility from the checkbox state
- Fold the use_custom_robots_txt clearing into the existing subscribed?
  block in blog_params; check params[:use_custom_robots_txt].present?
  rather than == "1"
- Revert unrelated language_select / form render path qualifications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant