马库斯的解决方案是一个良好的开端。谢谢你提供它!
然而,它有一些问题:
如果目录不包含任何.html文件,则会创建一个文件
名为*.html。
它不会向JDK 8版本的javadoc生成的HTML文件添加favicon,该版本使用
而不是。如果多次运行,它会多次插入favicon。
mktemp命令不可移植(例如,在Mac OS上不起作用)。
它不保留文件权限。
这是一个纠正这些问题的版本。可以在expanded version存储库中找到html-tools。如果您发现问题或想提出改进建议,请在此处发表评论或使用html-tools issue tracker。
#!/bin/sh
# Add favicon to header of HTML files.
# One use case is for javadoc-generated API documentation.
#
# Run like this:
# add-favicon
# The arguments should be paths relative to the current working directory.
# Once this has been run, running it another time has no effect.
patchIt () {
for f in $1/*.html ; do
if [ -f "$f" ]; then # if no .html files exist, f is literal "*.html"
tmpfile=`mktemp patch_favicon_XXXXX`
# This creates tmpfile, with the same permissions as $f.
# The next command will overwrite it but preserve the permissions.
# Hat tip to http://superuser.com/questions/170226/standard-way-to-duplicate-a-files-permissions for this trick.
\cp -p $f $tmpfile
sed -e " s%
\$%%" $f > $tmpfilemv -f $tmpfile $f
fi;
done ;
for d in $1/* ; do
if [ -d $d ]; then echo "descending to "$d ; patchIt $d ../$2 ; fi ;
done
}
patchIt $1 $2
#eof