CodeOwners
Syntax
PAGE.CodeOwners
Returns
[]string
GitHub 和 GitLab 支持 CODEOWNERS 文件。此文件指定负责开发和维护软件和文档的用户。此定义可以应用于整个存储库、特定目录或单个文件。了解更多信息:
使用 Page
对象上的 CodeOwners
方法来确定给定页面的代码所有者。
要使用 CodeOwners
方法,必须启用对本地 Git 存储库的访问:
hugo.
enableGitInfo: true
enableGitInfo = true
{
"enableGitInfo": true
}
考虑以下项目结构:
my-project/
├── content/
│ ├── books/
│ │ └── les-miserables.md
│ └── films/
│ └── the-hunchback-of-notre-dame.md
└── CODEOWNERS
以及这个 CODEOWNERS 文件:
* @jdoe
/content/books/ @tjones
/content/films/ @mrichards @rsmith
下表显示了为每个文件返回的代码所有者片段:
路径 | 代码所有者 |
---|---|
books/les-miserables.md |
[@tjones] |
films/the-hunchback-of-notre-dame.md |
[@mrichards @rsmith] |
渲染每个内容页面的代码所有者:
{{ range .CodeOwners }}
{{ . }}
{{ end }}
将此方法与 resources.GetRemote
方法结合使用,通过查询其 API 从您的 Git 提供商处检索名称和头像。