Skip to content

Commit

Permalink
Allow hiding files in markdown mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Feb 2, 2025
1 parent 2c2591c commit 66cc688
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/server/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ nav ul li a {
}

#directory-listing {
margin-top: 10px;
margin-top: 30px;
}

.files {
Expand Down
3 changes: 2 additions & 1 deletion internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 10 additions & 9 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions internal/server/templates/listing.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<section id="directory-listing">
<div class="container">
{{- if .MarkdownBeforeDir }}{{- with .MarkdownContent }}
<div class="card-large">
<div class="markdown-body">{{- . | unsafeHTML }}</div>
</div>
{{ template "markdown" . }}
{{- end }}{{- end }}

{{- if .ShouldRenderFiles }}
<div class="card-large">
<ul class="files">
<li>
Expand Down Expand Up @@ -44,13 +43,19 @@
{{- end }}
</ul>
</div>
{{- end }}

{{- if not .MarkdownBeforeDir }}{{- with .MarkdownContent }}
<div class="card-large">
<div class="markdown-body">{{- . | unsafeHTML }}</div>
</div>
{{ template "markdown" . }}
{{- end }}{{- end }}
</div>
</section>

{{- end }}


{{- define "markdown" }}
<div class="card-large">
<div class="markdown-body">{{- . | unsafeHTML }}</div>
</div>
{{- end }}

0 comments on commit 66cc688

Please sign in to comment.