File: edit-this-page.md

package info (click to toggle)
sphinx-basic-ng 1.0.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 504 kB
  • sloc: python: 179; makefile: 5
file content (84 lines) | stat: -rw-r--r-- 2,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# "Edit this page" link

It is fairly common for technical documentation websites to contain a link to
edit the original sources of a page. This makes it easy for a reader to quickly
fix a typo and provides a decent way to navigate to the source repository of the
project.

## Usage

```jinja
{% include "components/edit-this-page.html" with context %}
```

This will add a single `a[href]` tag, with the text "Edit this page".

You also need to declare the following in `theme.conf`'s `options` section:

```ini
source_edit_link =
source_repository =
source_branch =
source_directory =
```

## Configurability

The documentation author can set values in their `conf.py` file using
`html_theme_options`:

```python
html_theme_options = {
    "source_repository": "https://github.com/pradyunsg/sphinx-basic-ng/",
    "source_branch": "main",
    "source_directory": "docs/",
}
```

```python
html_theme_options = {
    "source_edit_link": "https://my.host/project/edit/docs/{filename}",
    "source_repository": "https://my.host/project",
    "source_branch": "main",
    "source_directory": "docs/",
}
```

Those user-provided values are used to determine the link for editing the
generated page on their code hosting platform.

This component can be customised in a theme-specific manner in two ways, both of
which require adding a new template file (typically,
`components/edit-this-page.html` file in the theme).

1. Extending

   This is be done by extending this file and overriding the the
   `link_available` and `link_not_available` blocks, which are used based on
   whether the edit link can be rendered -- i.e. whether the user has provided
   the configuration values noted above.

   ```jinja
   {% extends "basic-ng/components/edit-this-page.html" %}

   {% block link_not_available %}
   {{ warning("Hey user! Provide the repository information!" )}}
   {% endblock link_not_available %}
   ```

2. Overriding

   This can be done by _not_ extending the base template. This allows the theme
   to have complete control over the way the URL provided is used. If a theme
   does this, it is also responsible for presenting warnings to the user when
   the user has not provided all the required configuration variables to the
   theme (see the sources of `edit-this-page.html`, after macros).

   It is possible to use the `determine_page_edit_link` macro, to get the
   relevant URL from the regular configuration (it assumes the user has it set).

   ```jinja
   {% from "basic-ng/components/edit-this-page.html" import determine_page_edit_link with context %}

    <a href="{{ determine_page_edit_link() }}">{{ _("Edit this page") }}</a>
   ```