Documentation
¶
Overview ¶
Package markdownintercept provides a Caddy HTTP middleware that intercepts requests with an Accept header requesting markdown (text/markdown) and serves a precomputed .md file located alongside the originally requested resource.
For example:
- GET /docs/page.html with Accept: text/markdown → serves /docs/page.md
- GET /docs/ with Accept: text/markdown → serves /docs/index.md
- GET /about with Accept: text/markdown → serves /about.md
Index ¶
- type MarkdownIntercept
- func (MarkdownIntercept) CaddyModule() caddy.ModuleInfo
- func (m *MarkdownIntercept) Provision(ctx caddy.Context) error
- func (m MarkdownIntercept) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (m *MarkdownIntercept) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (m *MarkdownIntercept) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MarkdownIntercept ¶
type MarkdownIntercept struct {
// Root is the filesystem path from which to look for .md files.
// Defaults to the current working directory or Caddy's configured root.
Root string `json:"root,omitempty"`
// IndexNames is the list of default index filenames to try when the
// request path ends with "/". Defaults to ["index.html", "index.htm", "index.php"].
IndexNames []string `json:"index_names,omitempty"`
// Extensions is the list of file extensions to consider when rewriting
// to .md. Defaults to [".html", ".htm", ".php", ".txt"].
Extensions []string `json:"extensions,omitempty"`
// ExperimentalRangeRequests enables support for the non-standard
// Range: x-frontmatter request unit, which returns only the YAML/TOML
// frontmatter block of a markdown file (206 Partial Content).
// Disabled by default.
ExperimentalRangeRequests bool `json:"experimental_range_requests,omitempty"`
// StrictMode, when enabled, enforces strict content-type negotiation:
// - Requests whose Accept header contains no type compatible with
// text/* or */* are rejected with 406 Not Acceptable.
// - Requests that explicitly ask for text/markdown but have no
// corresponding .md file are also rejected with 406.
// Disabled by default.
StrictMode bool `json:"strict_mode,omitempty"`
// contains filtered or unexported fields
}
MarkdownIntercept is a Caddy middleware that checks if the client accepts text/markdown. If so, it looks for a .md file corresponding to the requested path and serves it instead of delegating to the next handler.
func (MarkdownIntercept) CaddyModule ¶
func (MarkdownIntercept) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*MarkdownIntercept) Provision ¶
func (m *MarkdownIntercept) Provision(ctx caddy.Context) error
Provision sets up the module.
func (MarkdownIntercept) ServeHTTP ¶
func (m MarkdownIntercept) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP implements caddyhttp.MiddlewareHandler.
func (*MarkdownIntercept) UnmarshalCaddyfile ¶
func (m *MarkdownIntercept) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile sets up the module from Caddyfile tokens.
Syntax:
markdown_intercept {
root <path>
index_names <name1> <name2> ...
extensions <.ext1> <.ext2> ...
experimental_range_requests
strict_mode
}
func (*MarkdownIntercept) Validate ¶
func (m *MarkdownIntercept) Validate() error
Validate ensures the module configuration is valid.