From a443bc5c27c5fa9ca0b8674f017fd37da06c50e5 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Sun, 11 Sep 2022 23:46:01 -0700 Subject: [PATCH] Fix double slashes in single module deployment (#18) * Add test for a single module deployment * Fix double slashes in single module deployment --- config.go | 8 +++++-- generate_package.go | 2 +- generate_package_test.go | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 598685e..bea57c7 100644 --- a/config.go +++ b/config.go @@ -28,12 +28,16 @@ type repository struct { func (r repository) Packages() []string { pkgs := []string{r.Prefix} - for _, s := range r.Subs { - pkgs = append(pkgs, path.Join(r.Prefix, s.Name)) + for i := range r.Subs { + pkgs = append(pkgs, r.SubPath(i)) } return pkgs } +func (r repository) SubPath(i int) string { + return path.Join(r.Prefix, r.Subs[i].Name) +} + type sub struct { Name string Hidden bool diff --git a/generate_package.go b/generate_package.go index 85e7ae8..3e0d77e 100644 --- a/generate_package.go +++ b/generate_package.go @@ -31,7 +31,7 @@ ul { margin-top: 16px; margin-bottom: 16px; } Home: {{.HomeURL}}
Source: {{.Repository.URL}}
{{if .Repository.Subs -}}Sub-packages:{{end -}} diff --git a/generate_package_test.go b/generate_package_test.go index 17067cc..a2d8508 100644 --- a/generate_package_test.go +++ b/generate_package_test.go @@ -421,6 +421,52 @@ Home: https://www.example.com
Source: https://github.com/example/go-pkg1
Sub-packages: +`, + expectedErr: nil, + }, + { + description: "single module deployment that has no 'prefix'", + domain: "example.com", + docsDomain: "", + pkg: "", + r: repository{ + Prefix: "", + Subs: []sub{{Name: "subpkg1"}, {Name: "subpkg2"}}, + Type: "git", + URL: "https://github.com/example/go-pkg1", + SourceURLs: sourceURLs{ + Home: "https://github.com/example/go-pkg1", + Dir: "https://github.com/example/go-pkg1/tree/branch{/dir}", + File: "https://github.com/example/go-pkg1/blob/branch{/dir}/{file}#L{line}", + }, + Website: website{ + URL: "https://www.example.com", + }, + }, + expectedOut: ` + + + +example.com/ + + + + + +
+

example.com/

+go get example.com/ +import "example.com/" +Home: https://www.example.com
+Source: https://github.com/example/go-pkg1
+Sub-packages:
+ `, expectedErr: nil, },