gohan exposes the GitHub URL of each article's source Markdown file so that themes can render an "Edit this page on GitHub" (or "View source") link. The feature is entirely config-driven — no Go code is required from theme authors.
Add github_repo (and optionally github_branch) to the site block in config.yaml:
site:
title: "My Blog"
base_url: "https://example.com"
github_repo: "https://github.com/owner/repo" # required to enable the feature
github_branch: "main" # optional, defaults to "main"| Field | Type | Default | Description |
|---|---|---|---|
github_repo |
string | "" (disabled) |
Base URL of the GitHub repository |
github_branch |
string | "main" |
Branch to link to |
When github_repo is empty the feature is effectively disabled; the {{with}} guard in the template snippet below handles this automatically.
SiteConfig gains two new exported fields:
// SiteConfig holds site-wide metadata.
type SiteConfig struct {
// ...existing fields...
// GitHubRepo is the base URL of the GitHub repository hosting this site's
// content (e.g. "https://github.com/owner/repo"). When set, templates can
// render an "Edit this page" link using .ContentPath.
GitHubRepo string `yaml:"github_repo"`
// GitHubBranch is the branch used to build the edit URL. Defaults to "main".
GitHubBranch string `yaml:"github_branch"`
}ProcessedArticle gains one new field:
// ProcessedArticle holds derived data generated by the renderer.
type ProcessedArticle struct {
// ...existing fields...
// ContentPath is the content-dir-relative path to the source Markdown file
// (e.g. "posts/hello-world.md"). Used to generate GitHub edit/view links.
ContentPath string
}The simplest article template snippet:
{{with .Config.Site.GitHubRepo}}
<a href="{{.}}/blob/{{$.Config.Site.GitHubBranch}}/content/{{$.Article.ContentPath}}"
target="_blank" rel="noopener noreferrer">
Edit this page on GitHub
</a>
{{end}}Note: The
content/prefix inside the URL path assumes the source Markdown files live incontent/relative to the repository root. Adjust the literal prefix to match your repository layout if different.
ContentPathis computed ininternal/processor/processor_impl.gobycomputeContentPath, which callsfilepath.Rel(contentDir, article.FilePath)and normalises the result to forward slashes viafilepath.ToSlash.- The
GitHubBranchdefault ("main") is applied ininternal/config/config.go'sapplyDefaultsfunction. - No additional build step or plugin is required.