Skip to content

Commit

Permalink
Fix double slashes in single module deployment (#18)
Browse files Browse the repository at this point in the history
* Add test for a single module deployment

* Fix double slashes in single module deployment
  • Loading branch information
leighmcculloch authored Sep 12, 2022
1 parent 89c43c7 commit a443bc5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
8 changes: 6 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion generate_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ul { margin-top: 16px; margin-bottom: 16px; }
Home: <a href="{{.HomeURL}}">{{.HomeURL}}</a><br/>
Source: <a href="{{.Repository.URL}}">{{.Repository.URL}}</a><br/>
{{if .Repository.Subs -}}Sub-packages:<ul>{{end -}}
{{range $_, $s := .Repository.Subs -}}{{if not $s.Hidden -}}<li><a href="/{{$.Repository.Prefix}}/{{$s.Name}}">{{$.Domain}}/{{$.Repository.Prefix}}/{{$s.Name}}</a></li>{{end -}}{{end -}}
{{range $i, $s := .Repository.Subs -}}{{if not $s.Hidden -}}<li><a href="/{{$.Repository.SubPath $i}}">{{$.Domain}}/{{$.Repository.SubPath $i}}</a></li>{{end -}}{{end -}}
{{if .Repository.Subs -}}</ul>{{end -}}
</div>
</body>
Expand Down
46 changes: 46 additions & 0 deletions generate_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,52 @@ Home: <a href="https://www.example.com">https://www.example.com</a><br/>
Source: <a href="https://github.com/example/go-pkg1">https://github.com/example/go-pkg1</a><br/>
Sub-packages:<ul><li><a href="/pkg1/subpkg1">example.com/pkg1/subpkg1</a></li><li><a href="/pkg1/subpkg2">example.com/pkg1/subpkg2</a></li></ul></div>
</body>
</html>`,
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: `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>example.com/</title>
<meta name="go-import" content="example.com/ git https://github.com/example/go-pkg1">
<meta name="go-source" content="example.com/ https://github.com/example/go-pkg1 https://github.com/example/go-pkg1/tree/branch{/dir} https://github.com/example/go-pkg1/blob/branch{/dir}/{file}#L{line}">
<style>
* { font-family: sans-serif; }
body { margin-top: 0; }
.content { display: inline-block; }
code { display: block; font-family: monospace; font-size: 1em; background-color: #d5d5d5; padding: 1em; margin-bottom: 16px; }
ul { margin-top: 16px; margin-bottom: 16px; }
</style>
</head>
<body>
<div class="content">
<h2>example.com/</h2>
<code>go get example.com/</code>
<code>import "example.com/"</code>
Home: <a href="https://www.example.com">https://www.example.com</a><br/>
Source: <a href="https://github.com/example/go-pkg1">https://github.com/example/go-pkg1</a><br/>
Sub-packages:<ul><li><a href="/subpkg1">example.com/subpkg1</a></li><li><a href="/subpkg2">example.com/subpkg2</a></li></ul></div>
</body>
</html>`,
expectedErr: nil,
},
Expand Down

0 comments on commit a443bc5

Please sign in to comment.