diff --git a/README.md b/README.md index 451b1d3..16e5b9e 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ To run Vanity in config-only mode for packages, set `--service` to `off`. To run Vanity without automatic updating, use `--manual`. +When running with manual-mode, the provided button or `/_/update` endpoint can be used once every `--interval`. + ## Topic Lists By setting `--topics`, anyone visiting the index page will see packages grouped by their topics. diff --git a/router/cache.go b/router/cache.go index c8ce8a0..88e37d9 100644 --- a/router/cache.go +++ b/router/cache.go @@ -29,6 +29,13 @@ func (p packageList) Names() []string { func (p packageList) Topics() map[string][]*api.Package { topics := make(map[string][]*api.Package, 0) for _, pkg := range p { + if len(pkg.Topics) == 0 { + if tt, ok := topics["other"]; ok { + topics["other"] = append(tt, pkg) + } else { + topics["other"] = []*api.Package{pkg} + } + } for _, t := range pkg.Topics { if tt, ok := topics[t]; ok { topics[t] = append(tt, pkg) diff --git a/router/router.go b/router/router.go index 14d2321..1b742b8 100644 --- a/router/router.go +++ b/router/router.go @@ -27,7 +27,7 @@ func Init() (*chi.Mux, error) { r := chi.NewRouter() r.Use(middleware.RedirectSlashes) r.Use(middleware.Recoverer) - r.Use(middleware.Timeout(30 * time.Second)) + r.Use(middleware.Timeout(60 * time.Second)) r.Get("/", doIndex) r.Get("/*", doVanity) @@ -71,12 +71,22 @@ func doVanity(res http.ResponseWriter, req *http.Request) { return } - if err := tmpl.Lookup("vanity.tmpl").Execute(res, map[string]interface{}{ + ctx := map[string]interface{}{ "Package": pkg, "Module": pkg.Module(flags.Domain), "GoSource": fmt.Sprintf("%s %s %s %s", pkg.Module(flags.Domain), pkg.CloneHTTP, svc.GoDir(pkg), svc.GoFile(pkg)), "Index": false, - }); err != nil { + } + + q := req.URL.Query() + if q.Get("go-get") != "" || q.Get("git-import") != "" { + if err := tmpl.Lookup("import.tmpl").Execute(res, ctx); err != nil { + beaver.Errorf("could not write response: %v", err) + } + return + } + + if err := tmpl.Lookup("vanity.tmpl").Execute(res, ctx); err != nil { beaver.Errorf("could not write response: %v", err) } } diff --git a/router/templates/foot.tmpl b/router/templates/foot.tmpl index a2279a2..4cf7348 100644 --- a/router/templates/foot.tmpl +++ b/router/templates/foot.tmpl @@ -12,7 +12,7 @@ updateImports.addEventListener('click', () => { updateImports.disabled = true; updateImports.innerHTML = 'Updating...'; - fetch('{{if .Index}}.{{else}}../{{end}}_/update', { + fetch('{{if .Index}}{{else}}../{{end}}_/update', { method: 'GET' }).then(() => { location.reload(); diff --git a/router/templates/import.tmpl b/router/templates/import.tmpl new file mode 100644 index 0000000..c883b67 --- /dev/null +++ b/router/templates/import.tmpl @@ -0,0 +1,20 @@ + + + + + + + + + + + + + {{.Module}} + + +go get {{.Module}} +
+git-import {{.Module}} + + \ No newline at end of file diff --git a/router/templates/index.tmpl b/router/templates/index.tmpl index 53be474..604c6e5 100644 --- a/router/templates/index.tmpl +++ b/router/templates/index.tmpl @@ -1,5 +1,5 @@ {{template "head.tmpl" .}} -

Imports:

+

{{if eq .Format "list"}}Imports{{else}}Topics{{end}}:

{{if eq .Format "list"}}