Add more languages for code syntax highlighting

This commit is contained in:
Seednode 2023-09-14 21:02:48 -05:00
parent 8923a4c14d
commit 28bc560098
4 changed files with 104 additions and 20 deletions

View File

@ -11,7 +11,7 @@ import (
) )
const ( const (
ReleaseVersion string = "0.84.1" ReleaseVersion string = "0.84.2"
) )
var ( var (
@ -21,6 +21,7 @@ var (
Cache bool Cache bool
CacheFile string CacheFile string
Code bool Code bool
Debug bool
Filtering bool Filtering bool
Flash bool Flash bool
Handlers bool Handlers bool
@ -70,6 +71,7 @@ func init() {
rootCmd.Flags().BoolVarP(&Cache, "cache", "c", false, "generate directory cache at startup") 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().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(&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().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(&Flash, "flash", false, "enable support for shockwave flash files (via ruffle.rs)")
rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)") rootCmd.Flags().BoolVar(&Handlers, "handlers", false, "display registered handlers (for debugging)")

View File

@ -49,6 +49,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
if Debug {
fmt.Printf("Call to stripQueryParams(%v) failed inside serveStaticFile()\n", path)
}
serverError(w, r, nil) serverError(w, r, nil)
return return
@ -58,6 +61,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
if Debug {
fmt.Printf("Call to filepath.EvalSymlinks(%v) failed inside serveStaticFile()\n", strings.TrimPrefix(prefixedFilePath, prefix))
}
serverError(w, r, nil) serverError(w, r, nil)
return return
@ -71,8 +77,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
exists, err := fileExists(filePath) exists, err := fileExists(filePath)
if err != nil { if err != nil {
fmt.Println(err) if Debug {
fmt.Printf("Call to fileExists(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil) serverError(w, r, nil)
return return
@ -88,8 +95,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
buf, err := os.ReadFile(filePath) buf, err := os.ReadFile(filePath)
if err != nil { if err != nil {
fmt.Println(err) if Debug {
fmt.Printf("Call to os.ReadFile(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil) serverError(w, r, nil)
return return
@ -102,7 +110,9 @@ func serveStaticFile(paths []string, cache *fileCache) httprouter.Handle {
if Russian { if Russian {
err = os.Remove(filePath) err = os.Remove(filePath)
if err != nil { if err != nil {
fmt.Println(err) if Debug {
fmt.Printf("Call to os.Remove(%v) failed inside serveStaticFile()\n", filePath)
}
serverError(w, r, nil) serverError(w, r, nil)

View File

@ -123,8 +123,90 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string)
func (t Format) Extensions() map[string]string { func (t Format) Extensions() map[string]string {
return map[string]string{ return map[string]string{
`.go`: `text/plain`, `.4th`: ``,
`.sh`: `application/x-sh`, `.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`: ``,
} }
} }

View File

@ -44,18 +44,8 @@ func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime string)
func (t Format) Extensions() map[string]string { func (t Format) Extensions() map[string]string {
return map[string]string{ return map[string]string{
`.css`: `text/css`, `.csv`: `text/csv`,
`.csv`: `text/csv`, `.txt`: `text/plain`,
`.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`,
} }
} }