man2html 使用的是CGI语言,我将其转嫁到 php 页面上面,使得它可以直接导向静态页面,并使用了 URL Rewriting ,感觉还不错。
动态页面:http://www.kreny.com/man2html/man.cgi
静态页面:http://www.kreny.com/man2html/index.php
具体代码请看全文
由于是在 cgi-bin 的 scriptalias 下面做 URL rewrite,所以在写rules的时候有点变化,必须声明这个是 cgi-bin 脚本。如果不声明,可以将 cgi-bin目录下面的文档当做一般文档来处理,各有所用。
# Rewrite Rules for man2html
RewriteRule ^/man2html/commands.php$ /man2html/commands.php
RewriteRule ^/man2html/index.php$ /man2html/index.php
RewriteRule ^/man2html/commands/([a-z]+).php$ /man2html/commands.php?title=$1
RewriteRule ^/man2html/commands/(.*)\.html$ /man2html/man.cgi?section=all&topic=$1 [T=application/x-httpd-cgi]
index.php就简单了,只是做了一个
<?php
if (isset($_POST["topic"]) && $_POST["topic"] <> "")
header('Location: '.$_POST["topic"].'.html');
?>
if (isset($_POST["topic"]) && $_POST["topic"] <> "")
header('Location: '.$_POST["topic"].'.html');
?>
当然,进一步做的话,你可以用 shell 命令到各个 bin 目录收集命令,做一个类似于sitemap之类的导航页面
ls -l | awk '{print $9}'>> command.txt
在CU上面问了问大伙儿,用一下办法把命令按照字母排序到各个文件里面:
awk '{print "echo",$0," >> "substr($0,1,1)".txt"}' command.txt | sh
增强一点功能
awk '{print "echo \"<a href="$0".html>"$0"</a><br>\" >> "substr($0,1,1)".txt"}' command.txt | sh
这样就可以得到诸如 a.txt b.txt c.txt 之类的命令文件了,为我们分类命令行做准备。
如果要把.txt 文件改成 .html 文件:
$ rename .txt .html *.txt
(END)