Explorar el Código

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.
master
Matt Baer hace 2 años
padre
commit
16294edeb5
Se han modificado 2 ficheros con 18 adiciones y 2 borrados
  1. +17
    -1
      main.go
  2. +1
    -1
      page.go

+ 17
- 1
main.go Ver fichero

@@ -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 {


+ 1
- 1
page.go Ver fichero

@@ -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>


Cargando…
Cancelar
Guardar