new templates are arriving

pull/4/head
Adrian Perez 2007-08-22 21:27:11 +02:00
parent 6aab314f67
commit 27a0fbf338
26 changed files with 135 additions and 40 deletions

44
HACKING.rst Normal file
View File

@ -0,0 +1,44 @@
===================================
Fancy Index module Hacking HOW-TO
===================================
.. contents::
How to modify templates
=======================
Templates are in the ``templates/`` subdirectory of the source distribution.
They are included both as regular HTML text snippets (files ending in ``.t``)
and ready for inclusion in a C program (files ending in ``.inc``). Also
there is a small C program
Template order
~~~~~~~~~~~~~~
01-head1
Outputs the HTML header and must end with something like
``<title>Index of``, because the code inserts the path of the URI just
after this piece.
02-head2
Outputs the rest of the header, usually will close the ``</title>`` tag
opened in the previous template and add further output until the closing
``</head>`` tag.
03-body1
-
04-body2
-
05-list1
-
06-list2
-
07-body3
-
08-body4
-
09-foot1
-
.. vim: spell spelllang=en expandtab

20
LICENSE Normal file
View File

@ -0,0 +1,20 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

View File

@ -1,6 +1,6 @@
/*
* ngx_http_fancyindex_module.c
* Copyright (C) 2007 Adrian Perez <adrianperez@udc.es>
* Copyright © 2007 Adrian Perez <adrianperez@udc.es>
*
* Module used for fancy indexing of directories. Features and differences
* with the stock nginx autoindex module:
@ -13,9 +13,10 @@
* - Proper HTML is generated: it should validate both as XHTML 1.0 Strict
* and HTML 4.01.
*
* Base functionality heavy based upon the stock nginx autoindex module.
* Base functionality heavy based upon the stock nginx autoindex module,
* which in turn was made by Igor Sysoev, like the majority of nginx.
*
* Distributed under terms of the MIT license.
* Distributed under terms of the BSD license.
*/
#include <ngx_config.h>
@ -178,22 +179,7 @@ ngx_module_t ngx_http_fancyindex_module = {
};
static u_char title[] =
"<html>" CRLF
"<head><title>Index of "
;
static u_char header[] =
"</title></head>" CRLF
"<body bgcolor=\"white\">" CRLF
"<h1>Index of "
;
static u_char tail[] =
"</body>" CRLF
"</html>" CRLF
;
#include "templates/templates.inc"
static ngx_int_t
@ -402,14 +388,12 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
ngx_close_dir_n " \"%s\" failed", &path);
}
len = sizeof(title) - 1
len = NGX_HTTP_FANCYINDEX_TEMPLATE_SIZE
+ r->uri.len
+ sizeof(header) - 1
+ r->uri.len
+ sizeof("</h1>") - 1
+ sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1
+ sizeof("</pre><hr>") - 1
+ sizeof(tail) - 1;
+ sizeof("</pre><hr>") - 1;
entry = entries.elts;
for (i = 0; i < entries.nelts; i++) {
@ -436,10 +420,13 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
ngx_http_fancyindex_cmp_entries);
}
b->last = ngx_cpymem(b->last, title, sizeof(title) - 1);
b->last = ngx_cpymem(b->last, t01_head1, sizeof(t01_head1) - 1);
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len);
b->last = ngx_cpymem(b->last, header, sizeof(header) - 1);
b->last = ngx_cpymem(b->last, t02_head2, sizeof(t02_head2) - 1);
b->last = ngx_cpymem(b->last, t03_body1, sizeof(t03_body1) - 1);
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len);
b->last = ngx_cpymem(b->last, t03_body1, sizeof(t03_body1) - 1);
b->last = ngx_cpymem(b->last, "</h1>", sizeof("</h1>") - 1);
b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
@ -573,7 +560,7 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
b->last = ngx_cpymem(b->last, "</pre><hr>", sizeof("</pre><hr>") - 1);
b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);
b->last = ngx_cpymem(b->last, t09_foot1, sizeof(t09_foot1) - 1);
if (r == r->main) {
b->last_buf = 1;

View File

@ -3,4 +3,4 @@
"99/xhtml\"><head><style type=\"text/css\">body, html {background: #fff;}tr"
".o {background: #eee;}th {font-weight: bold;background: #ddd;}</style><"
"meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><tit"
"le>"
"le>Index of "

View File

@ -15,4 +15,4 @@
}
</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
<title>Index of

1
templates/02-head2.inc Normal file
View File

@ -0,0 +1 @@
"</title></head>"

View File

@ -1,4 +1,2 @@
</title>
</head>
<body>
<h1>

1
templates/03-body1.inc Normal file
View File

@ -0,0 +1 @@
"<body><h1>"

2
templates/03-body1.t Normal file
View File

@ -0,0 +1,2 @@
<body>
<h1>

1
templates/04-body2.inc Normal file
View File

@ -0,0 +1 @@
"</h1>"

1
templates/04-body2.t Normal file
View File

@ -0,0 +1 @@
</h1>

4
templates/05-list1.inc Normal file
View File

@ -0,0 +1,4 @@
"<table><colgroup><col width=\"55%\"/><col width=\"20%\" style=\"text-align:"
" right\"/><col width=\"25%\"/></colgroup><thead><tr><th>File Name</th><th>"
"File Size</th><th>Date</th></tr></thead><tbody><tr><td colspan=\"3\"><a h"
"ref=\"../\">Parent Directory</a></td></tr>"

View File

@ -1,4 +1,3 @@
</h1>
<table>
<colgroup>
<col width="55%"/>
@ -13,3 +12,6 @@
</tr>
</thead>
<tbody>
<tr>
<td colspan="3"><a href="../">Parent Directory</a></td>
</tr>

1
templates/06-list2.inc Normal file
View File

@ -0,0 +1 @@
"</tbody></table>"

2
templates/06-list2.t Normal file
View File

@ -0,0 +1,2 @@
</tbody>
</table>

1
templates/07-body3.inc Normal file
View File

@ -0,0 +1 @@
""

1
templates/07-body3.t Normal file
View File

@ -0,0 +1 @@

1
templates/08-body4.inc Normal file
View File

@ -0,0 +1 @@
""

1
templates/08-body4.t Normal file
View File

@ -0,0 +1 @@

1
templates/09-foot1.inc Normal file
View File

@ -0,0 +1 @@
"</body></html>"

2
templates/09-foot1.t Normal file
View File

@ -0,0 +1,2 @@
</body>
</html>

View File

@ -1 +0,0 @@
"</tbody></table></body></html>"

View File

@ -1,4 +0,0 @@
</tbody>
</table>
</body>
</html>

View File

@ -1 +0,0 @@
"</title></head><body><h1>"

View File

@ -1,3 +0,0 @@
"</h1><table><colgroup><col width=\"55%\"/><col width=\"20%\" style=\"text-a"
"lign: right\"/><col width=\"25%\"/></colgroup><thead><tr><th>File Name</th"
"><th>File Size</th><th>Date</th></tr></thead><tbody>"

33
templates/templates.inc Normal file
View File

@ -0,0 +1,33 @@
#ifndef __templates_inc__
#define __templates_inc__
static const u_char t01_head1[] =
#include "01-head1.inc"
;
static const u_char t02_head2[] =
#include "02-head2.inc"
;
static const u_char t03_body1[] =
#include "03-body1.inc"
;
static const u_char t04_body2[] =
#include "04-body2.inc"
;
static const u_char t09_foot1[] =
#include "09-foot1.inc"
;
#define NGX_HTTP_FANCYINDEX_TEMPLATE_SIZE \
( (sizeof(t01_head1) - 1) \
+ (sizeof(t02_head2) - 1) \
+ (sizeof(t03_body1) - 1) \
+ (sizeof(t04_body2) - 1) \
\
+ (sizeof(t09_foot1) - 1) )
#endif /* !__templates_inc__ */
/* vim:ft=c
*/