Source Links Plugin
The source_links plugin generates canonical source links for every documentation page, allowing readers to view the source file or submit edits directly on GitHub, GitLab, or custom git services.
Overview & Features
- Automatic Git Detection: Auto-detects the remote repository URL (
origin) and active default branch from local.gitmetadata if not explicitly specified. - Multi-Provider Support: Pre-configured URL schemas for GitHub and GitLab, with fully customizable formatting templates for Gitea, Bitbucket, or self-hosted servers.
- Seamless Template Integration: Automatically enriches the Chameleon template context with ready-to-render URLs utilized by Golem's default
skeleton.ptfooter.
Enabling the Plugin
Add "source_links" to your plugins array in golem.toml:
[plugins]
plugins = [
"source_links",
]
Or in pyproject.toml:
[tool.golem.plugins]
plugins = [
"source_links",
]
Configuration Reference
Configure the plugin in the [plugins.source_links] table in golem.toml:
[plugins.source_links]
repo_url = "https://github.com/webmaven/golem"
branch = "main"
docs_dir = "docs"
provider = "github"
Option | Type | Default | Description |
|
| Auto-detected | Web URL of the git repository (e.g. |
|
| Auto-detected | Default git branch to target for viewing and editing. If omitted, Golem inspects the current HEAD or default branch, falling back to |
|
|
| Subdirectory within the repository where documentation files reside (e.g. |
|
| Auto-detected | Git host provider: |
|
| Provider default | Custom Python format string for constructing edit URLs. Available placeholder tokens: |
|
| Provider default | Custom Python format string for constructing view URLs. Available placeholder tokens: |
Git Remote Auto-Detection
When repo_url is omitted, source_links executes git config --get remote.origin.url (falling back to direct inspection of .git/config).
It automatically converts common SSH clone URLs to HTTPS browser URLs:
git@github.com:webmaven/golem.git->https://github.com/webmaven/golemssh://git@gitlab.com/group/project.git->https://gitlab.com/group/project
Custom Git Providers
For self-hosted instances (such as Gitea or Bitbucket), set provider = "custom" and supply custom URL templates:
[plugins.source_links]
repo_url = "https://gitea.example.com/team/docs"
branch = "master"
docs_dir = "docs"
provider = "custom"
edit_url_template = "{repo_url}/_edit/{branch}/{doc_path}"
view_url_template = "{repo_url}/src/branch/{branch}/{doc_path}"
Template Context Variables
When active, source_links injects the following variables into every page's template rendering scope:
Variable | Type | Description |
|
| Web URL to edit the source document directly in the git provider's web editor. |
|
| Web URL to view the raw source document on the git hosting platform. |
|
| Normalized root URL of the git repository. |
|
| Identified git provider identifier ( |
Chameleon Template Integration
In custom themes or overrides, you can render edit buttons and repository links using Chameleon TAL:
<!-- Edit this page link -->
<div tal:condition="source_edit_url | nothing" class="edit-page-container">
<a href="${source_edit_url}" class="edit-link" target="_blank" rel="noopener noreferrer">
<svg class="icon-pencil" width="16" height="16" viewBox="0 0 24 24">...</svg>
<span>Edit this page on ${source_provider.capitalize()}</span>
</a>
</div>
<!-- Header repository link -->
<header>
<a href="${source_repo_url}" tal:condition="source_repo_url | nothing" class="repo-badge">
View Repository
</a>
</header>
API Reference
class SourceLinksPlugin
class SourceLinksPlugin(GolemPlugin):
Golem plugin providing canonical repository view and edit links in page template contexts.
Injects source_repo_url, source_edit_url, source_view_url, source_url, and source_provider
into the Chameleon template context for each rendered document.
repo_url(str | None, optional)Canonical repository web URL. Auto-detected from git remote if None.
branch(str | None, optional)Git branch name to link against. Auto-detected if None.
docs_dir(str | None, optional)Path prefix for documentation files inside the repository.
provider(str | None, optional)Git provider (
"github","gitlab", or"custom").edit_url_template(str | None, optional)Custom format string for edit links.
view_url_template(str | None, optional)Custom format string for view links.
root_dir(Path | None, optional)Base directory used for local git repository discovery.
Attributes
nameDefault value:
'source_links'root_dirDefault value:
root_dir.resolve() if root_dir else Path.cwd().resolve()repo_url(str | None)
Default value: normalize_repo_url(repo_url)
branchDefault value:
branchproviderDefault value:
providerdocs_dirDefault value:
docs_dir.strip('/') if docs_dir else Noneedit_url_templateDefault value:
edit_url_templateview_url_templateDefault value:
view_url_template
init
def __init__(self, repo_url: str | None = None, branch: str | None = None, docs_dir: str | None = None, provider: str | None = None, edit_url_template: str | None = None, view_url_template: str | None = None, root_dir: Path | None = None, **extra: Any) -> None:
from_config
@classmethod
def from_config(cls, config: Any = None) -> SourceLinksPlugin:
Construct a SourceLinksPlugin instance from GolemConfig or a configuration dictionary.
config(Any, optional)GolemConfig instance or dictionary of site/plugin options.
SourceLinksPluginConfigured plugin instance.
on_template_context
@hookimpl
def on_template_context(self, context: PageContext, doc_path: Path) -> PageContext:
Inject repository, file edit, and file view URLs into template context.
context(PageContext)Chameleon template context dictionary.
doc_path(Path)Path to the documentation source file being processed.
PageContextEnriched template context containing source URL keys.