From e9427e0eb0f7e7f19eae94522cde84b90063097b Mon Sep 17 00:00:00 2001 From: Patrick D'appollonio <930925+patrickdappollonio@users.noreply.github.com> Date: Sun, 2 Feb 2025 03:19:12 -0500 Subject: [PATCH] Allow hiding files in markdown mode. (#149) --- app.go | 1 + internal/server/assets/style.css | 2 +- internal/server/handlers.go | 3 ++- internal/server/server.go | 19 ++++++++++--------- internal/server/templates/listing.tmpl | 17 +++++++++++------ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app.go b/app.go index b6a2ac9..e90075d 100644 --- a/app.go +++ b/app.go @@ -123,6 +123,7 @@ func run() error { flags.BoolVar(&srv.DisableDirectoryList, "disable-directory-listing", false, "disable the directory listing feature and return 404s for directories without index") flags.StringVar(&srv.CustomNotFoundPage, "custom-404", "", "custom \"page not found\" to serve") flags.IntVar(&srv.CustomNotFoundStatusCode, "custom-404-code", 0, "custtom status code for pages not found") + flags.BoolVar(&srv.HideFilesInMarkdown, "hide-files-in-markdown", false, "hide file and directory listing in markdown rendering") //nolint:wrapcheck // no need to wrap this error return rootCmd.Execute() diff --git a/internal/server/assets/style.css b/internal/server/assets/style.css index d4d89f1..0acb0f5 100644 --- a/internal/server/assets/style.css +++ b/internal/server/assets/style.css @@ -191,7 +191,7 @@ nav ul li a { } #directory-listing { - margin-top: 10px; + margin-top: 30px; } .files { diff --git a/internal/server/handlers.go b/internal/server/handlers.go index 0c62aea..c6c1550 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -163,10 +163,11 @@ func (s *Server) walk(requestedPath string, w http.ResponseWriter, r *http.Reque "PageTitle": s.PageTitle, "CurrentPath": r.URL.Path, "CacheBuster": s.cacheBuster, - "Files": files, "RequestedPath": requestedPath, "IsRoot": s.PathPrefix == r.URL.Path, "UpDirectory": parent, + "Files": files, + "ShouldRenderFiles": !s.HideFilesInMarkdown, "HideLinks": s.HideLinks, "MarkdownContent": markdownContent.String(), "MarkdownBeforeDir": s.MarkdownBeforeDir, diff --git a/internal/server/server.go b/internal/server/server.go index 4a65800..427831d 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -30,15 +30,16 @@ type Server struct { Password string `flagName:"password" validate:"omitempty,alphanum,excluded_with=JWTSigningKey"` // Boolean specific settings - CorsEnabled bool - HideLinks bool - ETagDisabled bool - ETagMaxSize string - etagMaxSizeBytes int64 - GzipEnabled bool - DisableCacheBuster bool - DisableMarkdown bool - MarkdownBeforeDir bool + CorsEnabled bool + HideLinks bool + ETagDisabled bool + ETagMaxSize string + etagMaxSizeBytes int64 + GzipEnabled bool + DisableCacheBuster bool + DisableMarkdown bool + MarkdownBeforeDir bool + HideFilesInMarkdown bool // Redirection handling DisableRedirects bool diff --git a/internal/server/templates/listing.tmpl b/internal/server/templates/listing.tmpl index dd05b97..d2ad207 100644 --- a/internal/server/templates/listing.tmpl +++ b/internal/server/templates/listing.tmpl @@ -4,11 +4,10 @@
{{- if .MarkdownBeforeDir }}{{- with .MarkdownContent }} -
-
{{- . | unsafeHTML }}
-
+ {{ template "markdown" . }} {{- end }}{{- end }} + {{- if .ShouldRenderFiles }}
  • @@ -44,13 +43,19 @@ {{- end }}
+ {{- end }} {{- if not .MarkdownBeforeDir }}{{- with .MarkdownContent }} -
-
{{- . | unsafeHTML }}
-
+ {{ template "markdown" . }} {{- end }}{{- end }}
{{- end }} + + +{{- define "markdown" }} +
+
{{- . | unsafeHTML }}
+
+{{- end }}