Skip to content

Commit 3eb4b80

Browse files
committed
Include a description in llms.txt
1 parent 6e90bc5 commit 3eb4b80

9 files changed

Lines changed: 69 additions & 242 deletions

File tree

lib/ex_doc.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ defmodule ExDoc do
7575
ExDoc will by default include all dependencies and assume they are hosted on
7676
HexDocs. This can be overridden by your own values. Example: `[plug: "https://myserver/plug/"]`
7777
78+
* `:description` - A brief description of the project, currently included in Hex.pm and the generated
79+
`llms.txt` file
80+
7881
* `:extra_section` - String that defines the section title of the additional
7982
Markdown and plain text pages; default: "Pages". Example: "Guides"
8083

lib/ex_doc/formatter/config.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ defmodule ExDoc.Formatter.Config do
3939
authors: nil,
4040
package: nil,
4141
title: nil,
42+
description: nil,
4243
nest_modules_by_prefix: [],
4344
before_closing_head_tag: &__MODULE__.before_closing_head_tag/1,
4445
before_closing_body_tag: &__MODULE__.before_closing_body_tag/1,
@@ -72,6 +73,7 @@ defmodule ExDoc.Formatter.Config do
7273
authors: nil | [String.t()],
7374
package: :atom | nil,
7475
title: nil | String.t(),
76+
description: nil | String.t(),
7577
nest_modules_by_prefix: [String.t()],
7678
before_closing_head_tag: (atom() -> String.t()) | mfa() | map(),
7779
before_closing_body_tag: (atom() -> String.t()) | mfa() | map(),
@@ -144,6 +146,7 @@ defmodule ExDoc.Formatter.Config do
144146
:authors,
145147
:package,
146148
:title,
149+
:description,
147150
:apps,
148151
:deps
149152
])

lib/ex_doc/formatter/markdown.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule ExDoc.Formatter.MARKDOWN do
3434
extras = group_by_group(extras)
3535

3636
content =
37-
Templates.nav_template(config, modules, mix_tasks, extras, "Table of Contents")
37+
Templates.llms_txt_template(config, modules, mix_tasks, extras)
3838
|> normalize_output()
3939

4040
filename = "llms.txt"
@@ -51,7 +51,7 @@ defmodule ExDoc.Formatter.MARKDOWN do
5151
mix_tasks = group_by_group(tasks)
5252

5353
content =
54-
Templates.nav_template(config, modules, mix_tasks, [], "API Reference")
54+
Templates.api_reference_template(config, modules, mix_tasks)
5555
|> normalize_output()
5656

5757
filename = "api-reference.md"

lib/ex_doc/formatter/markdown/templates.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ defmodule ExDoc.Formatter.MARKDOWN.Templates do
3333

3434
EEx.function_from_file(
3535
:def,
36-
:nav_template,
37-
Path.expand("templates/nav_template.eex", __DIR__),
38-
[:config, :modules, :mix_tasks, :extras, :title],
36+
:api_reference_template,
37+
Path.expand("templates/api_reference_template.eex", __DIR__),
38+
[:config, :modules, :mix_tasks],
39+
trim: true
40+
)
41+
42+
EEx.function_from_file(
43+
:def,
44+
:llms_txt_template,
45+
Path.expand("templates/llms_txt_template.eex", __DIR__),
46+
[:config, :modules, :mix_tasks, :extras],
3947
trim: true
4048
)
4149

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# <%= config.project %> v<%= config.version %> - API Reference
2+
<%= nav_group_template "Modules", modules %>
3+
<%= nav_group_template "Mix Tasks", mix_tasks %>

lib/ex_doc/formatter/markdown/templates/nav_template.eex renamed to lib/ex_doc/formatter/markdown/templates/llms_txt_template.eex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# <%= config.project %> v<%= config.version %> - <%= title %>
1+
# <%= config.project %> v<%= config.version %> - Table of Contents
2+
<%= if config.description do %>
3+
<%= config.description %>
4+
5+
<% end %>
26
<%= nav_group_template config.extra_section, extras %>
37
<%= nav_group_template "Modules", modules %>
48
<%= nav_group_template "Mix Tasks", mix_tasks %>

lib/mix/tasks/docs.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ defmodule Mix.Tasks.Docs do
135135
|> normalize_source_url(config)
136136
# accepted at root level config
137137
|> normalize_homepage_url(config)
138+
# accepted at root level config
139+
|> normalize_description(config)
138140
|> normalize_apps(config)
139141
|> normalize_main()
140142
|> normalize_deps()
@@ -228,6 +230,14 @@ defmodule Mix.Tasks.Docs do
228230
end
229231
end
230232

233+
defp normalize_description(options, config) do
234+
if description = config[:description] do
235+
Keyword.put(options, :description, description)
236+
else
237+
options
238+
end
239+
end
240+
231241
defp source_beams(options, config) do
232242
if Mix.Project.umbrella?(config) do
233243
umbrella_compile_paths(Keyword.get(options, :ignore_apps, []))

test/ex_doc/formatter/markdown_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ defmodule ExDoc.Formatter.MarkdownTest do
215215
refute content =~ "## Pages"
216216
refute content =~ "## Guides"
217217
end
218+
219+
test "includes description when provided", %{tmp_dir: tmp_dir} = context do
220+
config =
221+
config(context,
222+
extras: ["test/fixtures/README.md"],
223+
description: "A documentation generation tool for Elixir"
224+
)
225+
226+
generate(config)
227+
content = File.read!(tmp_dir <> "/llms.txt")
228+
229+
assert content =~ "# Elixir v1.0.1 - Table of Contents"
230+
assert content =~ "A documentation generation tool for Elixir"
231+
232+
# Description should not appear in api-reference.md
233+
api_content = File.read!(tmp_dir <> "/api-reference.md")
234+
assert api_content =~ "# Elixir v1.0.1 - API Reference"
235+
refute api_content =~ "A documentation generation tool for Elixir"
236+
end
218237
end
219238

220239
describe "api_reference" do

0 commit comments

Comments
 (0)