我使用Template Toolkit (Perl) 并有一个从模板生成静态文件的简单脚本。这非常适合您所处的情况(常用导航等)。
它带有一个ttree
命令,该命令将处理目录树并将结果放入另一个目录树中。
这是我使用的 tt.rc 文件:
# ignore these files (regular expressions)
ignore = \.svn
ignore = ^#
ignore = ~$
ignore = .DS_Store
ignore = \.tt$
# if these template files change, reprocess everything
depend *=tpl/wrapper,tpl/defaults,style/default.html
# just copy these files, don't process as templates
copy = \.(gif|png|pdf|jpg)$
# verbose output
verbose
# recurse into subdirectories
recurse
# setup some defaults from tpl/defaults
pre_process = tpl/defaults
# process this file instead of the real file (see below how this is used)
process = tpl/wrapper
# process files from src/, output to html/
# extra templates in lib/ (tpl/wrapper for example).
src = src
dest = html
lib = lib
几个特殊文件,tpl/defaults
是
[%- page = {
title = template.title,
style = template.style or 'default.html'
};
base = INCLUDE tpl/base_uri;
# don't include any whitespace from here...
RETURN;
-%]
并且tpl/wrapper
是
[%- content = PROCESS $template;
IF !template.name.search('.html') OR page.style == 'none';
content;
ELSE;
default_style_template = "style/" _ page.style;
PROCESS $default_style_template;
END;
%]
这将处理真正的模板;将结果放入content
变量中,然后处理style
模板(用page.style
in设置tpl/defaults
;默认为defaults.html
)。
样式lib/style/default.html
文件只需要有
[% content %]
包含真实模板的地方;在此之前和之后,您可以拥有标准的页脚和页眉。
您可以在tt2.org阅读有关模板工具包的更多信息。
另一种选择是wget
在递归模式下使用(或类似的)在开发服务器上“镜像”由 PHP 生成的页面;但我不建议这样做。