[PATCH] autoindex : Add viewport meta tag for responsive scaling to narrow screen devices

Maxim Dounin mdounin at mdounin.ru
Tue Nov 10 19:25:58 UTC 2020


Hello!

On Sat, Nov 07, 2020 at 01:35:34PM +0530, vbt at anche.no wrote:

> # HG changeset patch
> # User Var Bhat <vbt at anche.no>
> # Date 1604734673 -19800
> #      Sat Nov 07 13:07:53 2020 +0530
> # Node ID 703eb6ae6cbf2ad87620d8ca4e0788be7e121538
> # Parent  554c6ae25ffc634e29adae8b51bef6ddabebea39
> ngx_http_autoindex_module: Added viewport meta tag to autoindex html 
> rendering
> 
> Previously , Auto Indexing Directory didn't include viewport meta tag 
> which caused html not to scale to the screen width .
> This caused Narrow screen devices (e.g. mobiles) render pages in a 
> virtual window or viewport,
> which is usually wider than the screen, and then shrink the rendered 
> result down so it can all be seen at once.
> This required frequent zooming and scrolling as things looked small.
> This made autoindexing unresponsive on mobile and other narrow screen 
> devices.
> 
> This patch makes autoindexing mobile responsive.
> 
> diff -r 554c6ae25ffc -r 703eb6ae6cbf 
> src/http/modules/ngx_http_autoindex_module.c
> --- a/src/http/modules/ngx_http_autoindex_module.c	Fri Nov 06 23:44:54 
> 2020 +0300
> +++ b/src/http/modules/ngx_http_autoindex_module.c	Sat Nov 07 13:07:53 
> 2020 +0530
> @@ -445,7 +445,8 @@
> 
>       static u_char  title[] =
>           "<html>" CRLF
> -        "<head><title>Index of "
> +        "<head><meta name=\"viewport\" content=\"width=device-width, 
> initial-scale=1.0\">" CRLF
> +        "<title>Index of "
>       ;
> 
>       static u_char  header[] =

Thank you for the patch.

I don't think it is a good idea to hardcode non-standard meta 
tags.  Also, I'm not really sure the result looks better on mobile 
devices, since it essentially hides the size and modification 
time from the listing.

To make arbitrary design changes to autoindex output, consider 
using autoindex_format xml coupled with XSLT processing, see 
http://nginx.org/r/autoindex_format.  Also, quick-and-dirty 
approach might be to use sub_filter 
(http//nginx.org/r/sub_filiter), for example:

    sub_filter '<head>' '<head><meta name="viewport" content="width=device-width, initial-scale=1.0">';

If there is a need for some easier means to make autoidex more 
flexible, we can consider introducing something like 
"autoindex_head" to make it possible to add arbitrary code to 
autoindex html output.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list