diff --git a/README.rst b/README.rst index db98df6..27b06cc 100644 --- a/README.rst +++ b/README.rst @@ -79,16 +79,6 @@ fancyindex_header If set to an empty string, the default header supplied by the module will be sent. -fancyindex_header_pre -~~~~~~~~~~~~~~~~~~~~~ -:Syntax: *fancyindex_header_pre* [*on* | *off*] -:Default: fancyindex_header_pre on -:Context: http, server, location -:Description: - Wrap contents of the file being sent as header in a ``
`` element, - after the module's own header. This is suitable for including - preformatting text. - fancyindex_footer ~~~~~~~~~~~~~~~~~ :Syntax: *fancyindex_footer path* @@ -99,15 +89,40 @@ fancyindex_footer If set to an empty string, the default footer supplied by the module will be sent. -fancyindex_footer_pre -~~~~~~~~~~~~~~~~~~~~~ -:Syntax: *fancyindex_footer_pre* [*on* | *off*] -:Default: fancyindex_footer_pre on +fancyindex_readme +~~~~~~~~~~~~~~~~~ +:Syntax: *fancyindex_readme path* +:Default: fancyindex_readme "" :Context: http, server, location :Description: - Wrap contents of the file being sent as footer in a ```` element, - after the module's own header. This is suitable for including - preformatting text. + Specifies which file should be inserted alongside with directory listings. + If set to an empty string, no extra textual content is included. See + `fancyindex_readme_options` in order to learn more about how the readme + file may be included. + +fancyindex_readme_options +~~~~~~~~~~~~~~~~~~~~~~~~~ +:Syntax: + *fancyindex_readme_options* *pre* | *asis* | *top* | *bottom* | *div* ... +:Default: fancyindex_readme_options top pre +:Context: http, server, location + Controls how to include the readme file specified by `fancyindex_readme`. + Available options are: + + pre + Send included readme file inside a preformatted text block (i.e. an + HTML ```` element. + asis + Send included readme file “as-is”, i.e. without altering its contents. + This is useful to include raw HTML snippets in the generated listings. + top + Place readme file contents at the top, before the listings. + bottom + Place readme file contents at the bottom, after the listings. + div + Wrap up all the text generated for the readme (including the enclosing + ```` element, if configured) inside a ```` element. The + layer will have the ``readme`` CSS class set. .. _nginx: http://nginx.net diff --git a/ngx_http_fancyindex_module.c b/ngx_http_fancyindex_module.c index 06a0854..f001db4 100644 --- a/ngx_http_fancyindex_module.c +++ b/ngx_http_fancyindex_module.c @@ -36,6 +36,13 @@ typedef struct { #endif +#define NGX_HTTP_FANCYINDEX_README_PRE 0x00 +#define NGX_HTTP_FANCYINDEX_README_ASIS 0x01 +#define NGX_HTTP_FANCYINDEX_README_TOP 0x00 +#define NGX_HTTP_FANCYINDEX_README_BOTTOM 0x02 +#define NGX_HTTP_FANCYINDEX_README_DIV 0x03 + + typedef struct { ngx_str_t name; size_t utf_len; @@ -52,10 +59,10 @@ typedef struct { ngx_flag_t exact_size; ngx_str_t header; - ngx_flag_t header_pre; - ngx_str_t footer; - ngx_flag_t footer_pre; + ngx_str_t readme; + + ngx_uint_t readme_flags; } ngx_http_fancyindex_loc_conf_t; @@ -73,6 +80,17 @@ static char *ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); + +static ngx_conf_bitmask_t ngx_http_fancyindex_readme_flags[] = { + { ngx_string("pre"), NGX_HTTP_FANCYINDEX_README_PRE }, + { ngx_string("asis"), NGX_HTTP_FANCYINDEX_README_ASIS }, + { ngx_string("top"), NGX_HTTP_FANCYINDEX_README_TOP }, + { ngx_string("bottom"), NGX_HTTP_FANCYINDEX_README_BOTTOM }, + { ngx_string("div"), NGX_HTTP_FANCYINDEX_README_DIV }, + { ngx_null_string, 0 }, +}; + + static ngx_command_t ngx_http_fancyindex_commands[] = { { ngx_string("fancyindex"), @@ -103,13 +121,6 @@ static ngx_command_t ngx_http_fancyindex_commands[] = { offsetof(ngx_http_fancyindex_loc_conf_t, header), NULL }, - { ngx_string("fancyindex_header_pre"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_fancyindex_loc_conf_t, header_pre), - NULL }, - { ngx_string("fancyindex_footer"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_slot, @@ -117,13 +128,20 @@ static ngx_command_t ngx_http_fancyindex_commands[] = { offsetof(ngx_http_fancyindex_loc_conf_t, footer), NULL }, - { ngx_string("fancyindex_footer_pre"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, + { ngx_string("fancyindex_readme"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_fancyindex_loc_conf_t, footer_pre), + offsetof(ngx_http_fancyindex_loc_conf_t, readme), NULL }, + { ngx_string("fancyindex_readme_options"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_bitmask_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_fancyindex_loc_conf_t, readme_flags), + &ngx_http_fancyindex_readme_flags }, + ngx_null_command }; @@ -667,11 +685,12 @@ ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_value(conf->localtime, prev->localtime, 0); ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1); - ngx_conf_merge_value(conf->footer_pre, prev->footer_pre, 1); - ngx_conf_merge_value(conf->header_pre, prev->header_pre, 1); - ngx_conf_merge_str_value(conf->header, prev->header, ""); ngx_conf_merge_str_value(conf->footer, prev->footer, ""); + ngx_conf_merge_str_value(conf->readme, prev->readme, ""); + + ngx_conf_merge_bitmask_value(conf->readme_flags, prev->readme_flags, + (NGX_HTTP_FANCYINDEX_README_TOP | NGX_HTTP_FANCYINDEX_README_PRE)); return NGX_CONF_OK; }