routes: add raw file view
Sun, 25 Feb 2024
3 files changed,
19 insertions(+),
2 deletions(-)
M
routes/routes.go
@@ -8,6 +8,7 @@ "net/http"
"os" "path/filepath" "sort" + "strconv" "time" "git.icyphox.sh/legit/config"@@ -199,6 +200,11 @@ return
} func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
… preview truncated
M
routes/template.go
@@ -95,3 +95,10 @@ log.Println(err)
return } } + +func (d *deps) showRaw(content string, w http.ResponseWriter) { + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "text/plain") + w.Write([]byte(content)) + return +}
M
templates/file.html
@@ -5,7 +5,7 @@ {{ template "repoheader" . }}
<body> {{ template "nav" . }} <main> - <p>{{ .path }}</p> + <p>{{ .path }} (<a style="color: gray" href="?raw=true">view raw</a>)</p> <div class="file-wrapper"> <table > <tbody><tr>