diff options
-rw-r--r-- | routes/routes.go | 12 | ||||
-rw-r--r-- | routes/template.go | 7 | ||||
-rw-r--r-- | templates/file.html | 2 |
3 files changed, 19 insertions, 2 deletions
diff --git a/routes/routes.go b/routes/routes.go index 0499a9e..2989752 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "sort" + "strconv" "time" "git.icyphox.sh/legit/config" @@ -199,6 +200,11 @@ func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) { } func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) { + var raw bool + if rawParam, err := strconv.ParseBool(r.URL.Query().Get("raw")); err == nil { + raw = rawParam + } + name := flow.Param(r.Context(), "name") if d.isIgnored(name) { d.Write404(w) @@ -222,7 +228,11 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) { data["desc"] = getDescription(path) data["path"] = treePath - d.showFile(contents, data, w) + if raw { + d.showRaw(contents, w) + } else { + d.showFile(contents, data, w) + } return } diff --git a/routes/template.go b/routes/template.go index 20d678b..0b03015 100644 --- a/routes/template.go +++ b/routes/template.go @@ -95,3 +95,10 @@ func (d *deps) showFile(content string, data map[string]any, w http.ResponseWrit 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 +} diff --git a/templates/file.html b/templates/file.html index 49bc19b..23187ec 100644 --- a/templates/file.html +++ b/templates/file.html @@ -5,7 +5,7 @@ <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> |