Fix tree and blob URLs for Gitea / Gogs
The directory structure for viewing branches and code on Gitea / Gogs is different from GitHub. This fixes that, so the Source Code link on the gopkg webpage works, as well as the URLs to lines in the source code included in GoDoc.
This commit is contained in:
parent
cd8b76423e
commit
16294edeb5
18
main.go
18
main.go
@ -123,7 +123,7 @@ var gogetTemplate = template.Must(template.New("").Parse(`
|
||||
<html>
|
||||
<head>
|
||||
<meta name="go-import" content="{{.Original.GopkgRoot}} git https://{{.Original.GopkgRoot}}">
|
||||
{{$root := .GitHubRoot}}{{$tree := .GitHubTree}}<meta name="go-source" content="{{.Original.GopkgRoot}} _ https://{{$root}}/tree/{{$tree}}{/dir} https://{{$root}}/blob/{{$tree}}{/dir}/{file}#L{line}">
|
||||
{{$root := .GitHubRoot}}{{$tree := .GitHubTree}}<meta name="go-source" content="{{.Original.GopkgRoot}} _ https://{{$root}}/{{.TreeDir}}/{{$tree}}{/dir} https://{{$root}}/{{.BlobDir}}/{{$tree}}{/dir}/{file}#L{line}">
|
||||
</head>
|
||||
<body>
|
||||
go get {{.GopkgPath}}
|
||||
@ -197,6 +197,22 @@ func (repo *Repo) GitHubRoot() string {
|
||||
return *srcDomainFlag + "/" + repo.User + "/" + repo.Name
|
||||
}
|
||||
|
||||
// TreeDir returns the repository's web tree dir
|
||||
func (repo *Repo) TreeDir() string {
|
||||
if *srcDomainFlag != "github.com" {
|
||||
return "src/branch"
|
||||
}
|
||||
return "tree"
|
||||
}
|
||||
|
||||
// BlobDir returns the repository's dir for source files
|
||||
func (repo *Repo) BlobDir() string {
|
||||
if *srcDomainFlag != "github.com" {
|
||||
return "src/branch"
|
||||
}
|
||||
return "blob"
|
||||
}
|
||||
|
||||
// GitHubTree returns the repository tree name for the selected version.
|
||||
func (repo *Repo) GitHubTree() string {
|
||||
if repo.FullVersion == InvalidVersion {
|
||||
|
2
page.go
2
page.go
@ -131,7 +131,7 @@ const packageTemplateString = `<!DOCTYPE html>
|
||||
{{ end }}
|
||||
<div class="row" >
|
||||
<div class="col-sm-12" >
|
||||
<a class="btn btn-lg btn-info" href="https://{{.Repo.GitHubRoot}}/tree/{{.Repo.GitHubTree}}{{.Repo.SubPath}}" ><i class="fa fa-github"></i> Source Code</a>
|
||||
<a class="btn btn-lg btn-info" href="https://{{.Repo.GitHubRoot}}/{{.Repo.TreeDir}}/{{.Repo.GitHubTree}}{{.Repo.SubPath}}" ><i class="fa fa-github"></i> Source Code</a>
|
||||
<a class="btn btn-lg btn-info" href="http://godoc.org/{{.Repo.GopkgPath}}" ><i class="fa fa-info-circle"></i> API Documentation</a>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user