diff --git a/README.md b/README.md index ac5fab0..2b62af6 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,9 @@ If the `--stats` flag is passed, an additional endpoint, `/_/stats`, is register When accessed, this endpoint returns a JSON document listing every file served, along with the number of times it has been served, its filesize, and timestamps of when it was served. ## Debug -If the `-d|--debug` flag is passed, an additional endpoint, `/_/debug`, is registered. +If the `-d|--debug` flag is passed, two additional endpoints—`/_/html` and `/_/json`—are registered. -When accessed, this endpoint returns a sorted JSON document listing every file currently in the index. This can prove useful when confirming whether the index is generated successfully, or whether a given file is in the index. +When accessed, these endpoints return the contents of the index, in HTML and JSON formats respectively. This can prove useful when confirming whether the index is generated successfully, or whether a given file is in the index. ## Usage output ``` diff --git a/cmd/version.go b/cmd/version.go index e0b91d7..60240f3 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.42.0" +var Version = "0.43.0" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 1e795a1..537777f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -646,7 +646,46 @@ func serveStatsHandler(args []string, stats *ServeStats) http.HandlerFunc { } } -func serveDebugHandler(args []string, index *Index) http.HandlerFunc { +func serveHtmlDebugHandler(args []string, index *Index) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "text/html") + + startTime := time.Now() + + indexDump := index.Index() + + sort.SliceStable(indexDump, func(p, q int) bool { + return indexDump[p] < indexDump[q] + }) + + var htmlBody strings.Builder + + htmlBody.WriteString(`
`) + htmlBody.WriteString(``) + htmlBody.WriteString(`