Skip to content

Commit ec3cb53

Browse files
authored
Provide more examples around source options (#2109)
1 parent 8552c49 commit ec3cb53

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

Diff for: lib/mix/tasks/docs.ex

+33-2
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ defmodule Mix.Tasks.Docs do
198198
* `%{path}`: the path of a file in the repo
199199
* `%{line}`: the line number in the file
200200
201-
For GitLab/GitHub:
201+
For self-hosted GitLab/GitHub:
202202
203203
```text
204204
https://mydomain.org/user_or_team/repo_name/blob/main/%{path}#L%{line}
205205
```
206206
207-
For Bitbucket:
207+
For self-hosted Bitbucket:
208208
209209
```text
210210
https://mydomain.org/user_or_team/repo_name/src/main/%{path}#cl-%{line}
@@ -214,6 +214,37 @@ defmodule Mix.Tasks.Docs do
214214
where path is either an relative path from the cwd, or an absolute path. The function
215215
must return the full URI as it should be placed in the documentation.
216216
217+
### Using `:source_url` and `:source_ref` together
218+
219+
A common setup for a project or library is to set both `:source_url` and `:source_ref`. Setting
220+
both of them will allow ExDoc to link to specific version of the code for a function or module
221+
that matches the version of the docs. So if the docs have been generated for version 1.0.5 then
222+
clicking on the source link in the docs will take the browser to the source code for the 1.0.5
223+
version of the code instead of only the primary ref (e.g. `main`).
224+
225+
A example setup looks like:
226+
227+
@version "0.30.10"
228+
def project do
229+
[
230+
...
231+
version: @version,
232+
docs: docs(),
233+
...
234+
]
235+
end
236+
237+
def docs do
238+
...
239+
source_ref: "v#{@version}",
240+
source_url: @source_url,
241+
...
242+
end
243+
244+
If you use `source_ref: "v#{@version}"` then when publishing a new version of your package you
245+
should run `git tag vVERSION` and push the tag. This way, ExDoc will generate links to the
246+
specific version the docs were generated for.
247+
217248
## Groups
218249
219250
ExDoc content can be organized in groups. This is done via the `:groups_for_extras`

0 commit comments

Comments
 (0)