docs: Return 404 for bad paths

Requires Caddy compiled with Go 1.17 or newer.
This commit is contained in:
Matthew Holt 2021-09-15 11:57:02 -06:00
parent 578394fc5f
commit 28eac39c29
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -1,6 +1,7 @@
{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
{{$markdownFilename := default "index" (slice $pathParts 2 | join "/")}}
{{$markdownFilePath := printf "/docs/markdown/%s.md" $markdownFilename}}
{{if not (fileExists $markdownFilePath)}}{{httpError 404}}{{end}}
{{$markdownFile := (include $markdownFilePath | splitFrontMatter)}}
{{$title := default $markdownFilename $markdownFile.Meta.title}}
<!DOCTYPE html>