Edit page
The edit-page shortcode renders a link to the GitHub editor for the source file of the current page. It is the “Improve this page on GitHub” link that documentation sites often put at the foot of a page.
The link uses GitHub’s /edit/ address. Readers with write access open the file in the editor. GitHub offers all other readers its “fork this repository and propose changes” flow, so outside contributors need no extra setup.
To show the link below every page without the shortcode, see Add an edit link below every page.
Syntax #
{{< edit-page >}}
{{< edit-page "development" >}}
{{< edit-page branch="development" >}}Use positional or named arguments. Hugo stops the build if one call mixes both.
Arguments #
Configuration #
The repository and the defaults are site parameters under [params.ananke.shortcodes.edit_page]. The edit-page partial uses the same settings.
# config/_default/params.toml
[ananke.shortcodes.edit_page]
repo_url = "https://github.com/owner/repo"
branch = "main"
content_dir = "content"Link address #
The shortcode builds the address from the configuration and the source file of the page:
{repo_url}/edit/{branch}/{content_dir}/{path of the file in the content directory}With the configuration above, the file content/posts/my-first-post.md gets this address:
https://github.com/owner/repo/edit/main/content/posts/my-first-post.mdOutput #
The shortcode renders one <a> element in a badge style. The link text is the editPage translation string. The default target is _blank; when the target is not _self or false, the link also has rel="noopener".
The shortcode calls the shared partial edit-page.html. You can call this partial from your own templates and hooks with a page, or with a map that contains page and, optionally, branch:
{{ partials.Include "edit-page.html" . }}
{{ partials.Include "edit-page.html" (dict "page" . "branch" "development") }}Translation strings #
| Key | Default English value | Used for |
|---|---|---|
editPage | Improve this page on GitHub | The link text. |
To change the text, override the string in your project’s i18n/<language>.toml. See Overriding theme interface strings.
Build messages #
| Message | Cause |
|---|---|
the 'edit-page' partial in "<path>" needs params.ananke.shortcodes.edit_page.repo_url to be set | repo_url is not set. Nothing renders. |
the 'edit-page' shortcode was used on a page without a source file | The page has no file, for example a generated page. Nothing renders. |
If the link returns “404 Not Found”, check that repo_url, branch, and content_dir match the repository.
Accessibility #
The link is a real anchor with descriptive text. It opens in a new tab by default; set target = false to keep readers in the same window.
Related pages #
- Since: marks the release that introduced a feature. It also reads its settings from
params.ananke.shortcodes. - Configuration reference: all shortcode parameters.