創建的Javadoc HTML網頁我想在我的生成的Javadoc HTML的<head>
元素:使用一個圖標
<link rel="shortcut icon" href="my-project-icon.ico" />
請注意,我使用的是Ant任務生成的Javadoc。
我嘗試使用Ant任務的<header>
元素,但放置在那裏的任何標記最終都在<h1>
標記內,因此該標記無效,因此被瀏覽器忽略。
創建的Javadoc HTML網頁我想在我的生成的Javadoc HTML的<head>
元素:使用一個圖標
<link rel="shortcut icon" href="my-project-icon.ico" />
請注意,我使用的是Ant任務生成的Javadoc。
我嘗試使用Ant任務的<header>
元素,但放置在那裏的任何標記最終都在<h1>
標記內,因此該標記無效,因此被瀏覽器忽略。
我一定會修改輸出文件作爲一個簡單的蠻力解決方案。但一個複雜的方法是有一個自定義的doclet。該doclet將是標準doclet的副本(Where can you download the source for the standard JavaDoc doclet for current releases (1.5 or 1.6))。
在HtmlDocletWriter.java
有很多行head.addContent
。您可能會再添加一條這樣的行,可能基於HtmlTree.LINK
。
我們採用以下bash/sed腳本的「蠻力」方法。 (請注意,javadoc在創建的目錄 中創建了一些名爲「* .html」的醜陋文件,當sed試圖處理它們時,會導致錯誤消息我們還沒有想出如何避免這種情況,但它似乎是無害的我們的目的 - !)
當然,一個XSLT腳本會更專業,...
#!/bin/sh
# patch favicon into header of javadoc generated api doc html
#
# assume started with P=`pwd` , then the args must be
# 1 directory to process/full path relative to $P
# 2 favicon filename to insert/full path relative to $P
function patchIt() {
for f in $1/*.html ; do
tmpfile=`mktemp -p . `
sed -e " s%<HEAD>%<HEAD><link rel=\"icon\" href=\"$2\" type=\"image/png\"/>%" \
$f > $tmpfile ; mv $tmpfile $f ;
done ;
for d in $1/* ; do
if [ -d $d ]; then echo "descending to "$d ; patchIt $d ../$2 ; fi ;
done
}
patchIt $1 $2
#eof
Markus的解決方案是一個良好的開端。感謝您提供它!
但是,它也存在一些問題:
*.html
文件 。<head>
而不是<HEAD>
。以下是糾正這些問題的版本。它也可以在plume-lib中be found。如果您發現問題或想要提出改進建議,請在此處發表評論或使用plume-lib 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 <directory> <favicon.png>
# 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%<head>\$%<head><link rel=\"icon\" href=\"$2\" type=\"image/png\"/>%" $f > $tmpfile
mv -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