summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@google.com>2026-07-23 16:23:52 -0700
committerRose Hogenson <rhogenson@google.com>2026-07-23 16:23:52 -0700
commita6563b31cd342334fe7a8b22b410d359adf3bfbb (patch)
treee723a457c3dbaa12b594b885a82413389f8b2420 /roseh.moe.go
parent8f036c1780ebc2d07d3043f8d805e1dde0725669 (diff)
downloadroseh.moe-a6563b31cd342334fe7a8b22b410d359adf3bfbb.tar.zst
Add a command index
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 407d112..84f3abf 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -824,7 +824,7 @@ func cmd(w http.ResponseWriter, r *http.Request) {
return
}
if r.FormValue("go-get") == "1" {
- fmt.Fprintf(w, `<meta name="go-import" content="roseh.moe/cmd/%s %s">`, r.PathValue("cmd"), source)
+ fmt.Fprintf(w, `<meta name="go-import" content="roseh.moe/cmd/%s %s">`, r.PathValue("cmd"), source.url)
} else {
http.Redirect(w, r, "https://pkg.go.dev/roseh.moe/cmd/"+r.PathValue("cmd"), http.StatusFound)
}
@@ -869,6 +869,48 @@ func pkgIndex(w http.ResponseWriter, r *http.Request) {
}
}
+var (
+ //go:embed templates/cmd-index.html.template
+ cmdIndexString string
+ cmdIndexTemplate = template.Must(outlinedTemplate(cmdIndexString))
+)
+
+type cmdIndexTemplateCommand struct {
+ Name string
+ Description string
+ Multi bool
+}
+
+type cmdIndexTemplateArgs struct {
+ Commands []cmdIndexTemplateCommand
+}
+
+func cmdIndex(w http.ResponseWriter, r *http.Request) {
+ serviceConfig, err := loadConfig()
+ if err != nil {
+ log.Printf("Warning: failed to load config: %s", err)
+ http.Error(w, "Failed to load config", http.StatusInternalServerError)
+ return
+ }
+ commands := make([]string, 0, len(serviceConfig.commandRedirects))
+ for cmd := range serviceConfig.commandRedirects {
+ commands = append(commands, cmd)
+ }
+ slices.Sort(commands)
+ templateCommands := make([]cmdIndexTemplateCommand, len(commands))
+ for i, name := range commands {
+ cmd := serviceConfig.commandRedirects[name]
+ templateCommands[i] = cmdIndexTemplateCommand{
+ Name: name,
+ Description: cmd.description,
+ Multi: cmd.multi,
+ }
+ }
+ if err := cmdIndexTemplate.Execute(w, cmdIndexTemplateArgs{Commands: templateCommands}); err != nil {
+ log.Printf("Warning: pkgIndex: %s", err)
+ }
+}
+
func pkg(w http.ResponseWriter, r *http.Request) {
serviceConfig, err := loadConfig()
if err != nil {
@@ -882,7 +924,7 @@ func pkg(w http.ResponseWriter, r *http.Request) {
return
}
if r.FormValue("go-get") == "1" {
- fmt.Fprintf(w, `<meta name="go-import" content="roseh.moe/pkg/%s %s">`, r.PathValue("pkg"), source)
+ fmt.Fprintf(w, `<meta name="go-import" content="roseh.moe/pkg/%s %s">`, r.PathValue("pkg"), source.url)
} else {
http.Redirect(w, r, "https://pkg.go.dev/roseh.moe/pkg/"+r.PathValue("pkg"), http.StatusFound)
}
@@ -926,6 +968,7 @@ func main() {
mux.HandleFunc("POST /login", login)
mux.HandleFunc("GET /notepad", notepad)
mux.HandleFunc("POST /notepad", autosave)
+ mux.HandleFunc("GET /cmd", cmdIndex)
mux.HandleFunc("GET /cmd/{cmd}", cmd)
mux.HandleFunc("GET /pkg", pkgIndex)
mux.HandleFunc("GET /pkg/{pkg}", pkg)