From 28bc560098a0bcb122e82b6b7ef0dddd89ed4194 Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 14 Sep 2023 21:02:48 -0500 Subject: [PATCH] Add more languages for code syntax highlighting --- cmd/root.go | 4 ++- cmd/web.go | 20 ++++++++--- types/code/code.go | 86 ++++++++++++++++++++++++++++++++++++++++++++-- types/text/text.go | 14 ++------ 4 files changed, 104 insertions(+), 20 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 3d234a7..949ca08 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,7 +11,7 @@ import ( ) const ( - ReleaseVersion string = "0.84.1" + ReleaseVersion string = "0.84.2" ) var ( @@ -21,6 +21,7 @@ var ( Cache bool CacheFile string Code bool + Debug bool Filtering bool Flash bool Handlers bool @@ -70,6 +71,7 @@ func init() { rootCmd.Flags().BoolVarP(&Cache, "cache", "c", false, "generate directory cache at startup") rootCmd.Flags().StringVar(&CacheFile, "cache-file", "", "path to optional persistent cache file") rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files") + rootCmd.Flags().BoolVar(&Debug, "debug", false, "display debug information") rootCmd.Flags().BoolVarP(&Filtering, "filter", "f", false, "enable filtering") rootCmd.Flags().BoolVar(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)") rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)") diff --git a/cmd/web.go b/cmd/web.go index cc236ba..726fd52 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -49,6 +49,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle { if err != nil { fmt.Println(err) + if Debug { + fmt.Printf("Call to stripQueryParams(%v) failed inside serveStaticFile()\n", path) + } serverError(w, r, nil) return @@ -58,6 +61,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle { if err != nil { fmt.Println(err) + if Debug { + fmt.Printf("Call to filepath.EvalSymlinks(%v) failed inside serveStaticFile()\n", strings.TrimPrefix(prefixedFilePath, prefix)) + } serverError(w, r, nil) return @@ -71,8 +77,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle { exists, err := fileExists(filePath) if err != nil { - fmt.Println(err) - + if Debug { + fmt.Printf("Call to fileExists(%v) failed inside serveStaticFile()\n", filePath) + } serverError(w, r, nil) return @@ -88,8 +95,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle { buf, err := os.ReadFile(filePath) if err != nil { - fmt.Println(err) - + if Debug { + fmt.Printf("Call to os.ReadFile(%v) failed inside serveStaticFile()\n", filePath) + } serverError(w, r, nil) return @@ -102,7 +110,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle { if Russian { err = os.Remove(filePath) if err != nil { - fmt.Println(err) + if Debug { + fmt.Printf("Call to os.Remove(%v) failed inside serveStaticFile()\n", filePath) + } serverError(w, r, nil) diff --git a/types/code/code.go b/types/code/code.go index 3cc844f..d9ddbe8 100644 --- a/types/code/code.go +++ b/types/code/code.go @@ -123,8 +123,90 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string) func (t Format) Extensions() map[string]string { return map[string]string{ - `.go`: `text/plain`, - `.sh`: `application/x-sh`, + `.4th`: ``, + `.abap`: ``, + `.ada`: ``, + `.ahk`: ``, + `.as`: ``, + `.awk`: ``, + `.bat`: ``, + `.bib`: ``, + `.bibtex`: ``, + `.c`: ``, + `.clj`: ``, + `.cljc`: ``, + `.cljs`: ``, + `.coffee`: ``, + `.conf`: ``, + `.cpp`: ``, + `.cr`: ``, + `.cs`: ``, + `.css`: ``, + `.d`: ``, + `.elm`: ``, + `.erl`: ``, + `.ex`: ``, + `.exs`: ``, + `.f03`: ``, + `.f90`: ``, + `.f95`: ``, + `.fs`: ``, + `.go`: ``, + `.graphql`: ``, + `.groovy`: ``, + `.gsh`: ``, + `.gvy`: ``, + `.gy`: ``, + `.hc`: ``, + `.hcl`: ``, + `.hs`: ``, + `.java`: ``, + `.jinja`: ``, + `.jl`: ``, + `.js`: ``, + `.json`: ``, + `.kt`: ``, + `.lisp`: ``, + `.lsp`: ``, + `.lua`: ``, + `.m`: ``, + `.md`: ``, + `.ml`: ``, + `.nb`: ``, + `.nim`: ``, + `.nix`: ``, + `.php`: ``, + `.pl`: ``, + `.pp`: ``, + `.proto`: ``, + `.ps`: ``, + `.ps1`: ``, + `.psl`: ``, + `.py`: ``, + `.r`: ``, + `.raku`: ``, + `.rb`: ``, + `.rs`: ``, + `.sass`: ``, + `.sc`: ``, + `.scm`: ``, + `.scss`: ``, + `.scpt`: ``, + `.sh`: ``, + `.sql`: ``, + `.swift`: ``, + `.tcl`: ``, + `.tex`: ``, + `.tf`: ``, + `.toml`: ``, + `.ts`: ``, + `.unit`: ``, + `.v`: ``, + `.vb`: ``, + `.xml`: ``, + `.yaml`: ``, + `.yml`: ``, + `.zig`: ``, } } diff --git a/types/text/text.go b/types/text/text.go index 672ac7f..7096860 100644 --- a/types/text/text.go +++ b/types/text/text.go @@ -44,18 +44,8 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string) func (t Format) Extensions() map[string]string { return map[string]string{ - `.css`: `text/css`, - `.csv`: `text/csv`, - `.js`: `text/javascript`, - `.json`: `application/json`, - `.md`: `text/markdown`, - `.ps1`: `text/plain`, - `.sh`: `application./x-sh`, - `.toml`: `application/toml`, - `.txt`: `text/plain`, - `.xml`: `application/xml`, - `.yml`: `application/yaml`, - `.yaml`: `application/yaml`, + `.csv`: `text/csv`, + `.txt`: `text/plain`, } }