diff options
| -rw-r--r-- | config.go | 14 | ||||
| -rw-r--r-- | config_test.go | 6 | ||||
| -rw-r--r-- | handler.go | 16 | ||||
| -rw-r--r-- | templates/index.html | 2 | ||||
| -rw-r--r-- | templates/package.html | 2 |
5 files changed, 30 insertions, 10 deletions
@@ -46,6 +46,11 @@ type PackageConfig struct { // Defaults to the URL specified in the top-level config. URL string `yaml:"url"` + // VCS is the version control system of this module. + // + // Defaults to git. + VCS string `yaml:"vcs"` + // Desc is a plain text description of this module. Desc string `yaml:"description"` } @@ -73,5 +78,14 @@ func Parse(path string) (*Config, error) { c.Godoc.Host = host } + // Set default values for the packages. + for name, pkg := range c.Packages { + if pkg.VCS == "" { + pkg.VCS = "git" + } + + c.Packages[name] = pkg + } + return &c, err } diff --git a/config_test.go b/config_test.go index 0eb93e2..e7ac247 100644 --- a/config_test.go +++ b/config_test.go @@ -16,6 +16,7 @@ packages: grpc: repo: github.com/grpc/grpc-go branch: main + vcs: svn `) defer clean() @@ -28,8 +29,7 @@ packages: pkg, ok := config.Packages["grpc"] assert.True(t, ok) - - assert.Equal(t, pkg, PackageConfig{Repo: "github.com/grpc/grpc-go"}) + assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go", VCS: "svn"}, pkg) } func TestParsePackageLevelURL(t *testing.T) { @@ -83,7 +83,7 @@ packages: pkg, ok := config.Packages["grpc"] assert.True(t, ok) - assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go"}, pkg) + assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go", VCS: "git"}, pkg) }) } } @@ -49,7 +49,8 @@ func CreateHandler(config *Config) http.Handler { Desc: pkg.Desc, ModulePath: modulePath, DocURL: docURL, - GitURL: pkg.Repo, + VCS: pkg.VCS, + RepoURL: pkg.Repo, } pkgs = append(pkgs, pkg) @@ -90,8 +91,11 @@ type sallyPackage struct { // URL at which documentation for the package can be found. DocURL string - // URL at which the Git repository is hosted. - GitURL string + // Version control system used by the package. + VCS string + + // URL at which the repository is hosted. + RepoURL string } type indexHandler struct { @@ -169,11 +173,13 @@ func (h *packageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { err := packageTemplate.Execute(w, struct { ModulePath string - GitURL string + VCS string + RepoURL string DocURL string }{ ModulePath: h.Pkg.ModulePath, - GitURL: h.Pkg.GitURL, + VCS: h.Pkg.VCS, + RepoURL: h.Pkg.RepoURL, DocURL: h.Pkg.DocURL + relPath, }) if err != nil { diff --git a/templates/index.html b/templates/index.html index 7353742..8014921 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,7 +33,7 @@ </div> <div class="five columns"> <span class="inline-header">Source:</span> - <a href="//{{ .GitURL }}">{{ .GitURL }}</a> + <a href="//{{ .RepoURL }}">{{ .RepoURL }}</a> </div> <div class="two columns"> <a href="{{ .DocURL }}"> diff --git a/templates/package.html b/templates/package.html index bd56c38..6183c51 100644 --- a/templates/package.html +++ b/templates/package.html @@ -1,7 +1,7 @@ <!DOCTYPE html> <html> <head> - <meta name="go-import" content="{{ .ModulePath }} git https://{{ .GitURL }}"> + <meta name="go-import" content="{{ .ModulePath }} {{ .VCS }} https://{{ .RepoURL }}"> <meta http-equiv="refresh" content="0; url={{ .DocURL }}"> </head> <body> |