@@ -198,13 +198,13 @@ defmodule Mix.Tasks.Docs do
198
198
* `%{path}`: the path of a file in the repo
199
199
* `%{line}`: the line number in the file
200
200
201
- For GitLab/GitHub:
201
+ For self-hosted GitLab/GitHub:
202
202
203
203
```text
204
204
https://mydomain.org/user_or_team/repo_name/blob/main/%{path}#L%{line}
205
205
```
206
206
207
- For Bitbucket:
207
+ For self-hosted Bitbucket:
208
208
209
209
```text
210
210
https://mydomain.org/user_or_team/repo_name/src/main/%{path}#cl-%{line}
@@ -214,6 +214,37 @@ defmodule Mix.Tasks.Docs do
214
214
where path is either an relative path from the cwd, or an absolute path. The function
215
215
must return the full URI as it should be placed in the documentation.
216
216
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
+
217
248
## Groups
218
249
219
250
ExDoc content can be organized in groups. This is done via the `:groups_for_extras`
0 commit comments