Class: DocsKit::LlmsController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Scoping
Defined in:
app/controllers/docs_kit/llms_controller.rb

Overview

Serves the two AI-readable artifacts (llmstxt.org) from the registry, with zero authoring — the host app wires the routes (the engine is glue-only, no routes of its own), so a site keeps full control over path, auth, and omission:

# config/routes.rb
get "/llms.txt"      => "docs_kit/llms#index"
get "/llms-full.txt" => "docs_kit/llms#full"

#index → the llms.txt index (brand, tagline, nav-grouped links to each page's .md twin). #full → llms-full.txt (every page's Markdown concatenated). Both are text/plain and HTTP-cached: the response revalidates on the registry's own content plus DocsKit::VERSION, so a page/gem change busts the cache while an unchanged registry serves a 304.

All the text shaping lives in DocsKit::LlmsText (pure, Rails-free). This controller only threads the Rails view context: #full renders each page to Markdown via DocsKit::MarkdownExport (which needs url helpers/CSRF), then hands the [title, markdown] pairs to LlmsText.full.

Constant Summary collapse

LLMS_MAX_AGE =

Freshness lifetime for a shared cache (dash-proxy, a CDN). public on its own is not storable under RFC 9111 — without a max-age the proxy cache skips the response. 300s matches the proxy.cache.max_ttl docs-kit scaffolds; the etag below still revalidates within that window.

300

Instance Method Summary collapse

Methods included from Scoping

included

Instance Method Details

#fullObject



42
43
44
45
46
47
48
# File 'app/controllers/docs_kit/llms_controller.rb', line 42

def full
  pairs = DocsKit::LlmsText.pages(docs_config).map do |page|
    [page.title, render_page_markdown(page)]
  end
  body = DocsKit::LlmsText.full(docs_config, pairs)
  render_text(body) if stale_llms?(body)
end

#indexObject



37
38
39
40
# File 'app/controllers/docs_kit/llms_controller.rb', line 37

def index
  body = DocsKit::LlmsText.index(docs_config, base_url: request.base_url)
  render_text(body) if stale_llms?(body)
end