У меня есть папка (ResultsDir) с html reseults files (results1.html, results2.html...). Я хочу подготовить один файл index.html со ссылками на все файлы результатов из ResultsDir.
Для файла списка в ResultsDir я использую:
<fileset id="myfileset" dir="ResultsDir">
<include name="*.html" />
</fileset>
<pathconvert pathsep="<BR>" property="htmls" refid="myfileset" targetos="windows"/>
<echo file="ResultsDir/index.html_temp" append="false" >${htmls} </echo>
<replace file="ResultsDir/index.html_temp" token="${basedir}\" value="" />
в результате у меня есть часть тела (index.html_temp) индекса html со списком файлов в папке. Но сейчас я не горячо копировать каждую строку и добавлять теги html (href) для каждой строки.
Верхняя и нижняя страница index.html Я добавляю только concat.
<concat destfile = "ResultsDir/index.html" >
<filelist dir = "ResultsDir " >
<file name="top.html_temp" />
<file name="index.html_temp" />
<file name="bottom.html_temp" />
</filelist>
</concat>
привет Крис
Для этого используйте язык сценариев. Я рекомендую groovy:
├── build.xml
└── ResultsDir
├── data1.html
├── data2.html
├── data3.html
├── data4.html
├── data5.html
└── index.html
<project name="demo" default="build-index">
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.7/groovy-all-2.1.7.jar"/>
</target>
<target name="build-index">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<fileset id="myfileset" dir="ResultsDir" includes="*.html" excludes="index.html"/>
<groovy>
import groovy.xml.MarkupBuilder
new File("ResultsDir/index.html").withWriter { writer ->
new MarkupBuilder(writer).html {
head {
title("Results index")
}
body {
ul {
project.references.myfileset.each {
def file = new File(it.toString())
li {
a(href: file.toURI(), file.name)
}
}
}
}
}
}
</groovy>
</target>
</project>
<html>
<head>
<title>Results index</title>
</head>
<body>
<ul>
<li>
<a href='file:/home/mark/ResultsDir/data1.html'>data1.html</a>
</li>
<li>
<a href='file:/home/mark/ResultsDir/data2.html'>data2.html</a>
</li>
<li>
<a href='file:/home/mark/ResultsDir/data3.html'>data3.html</a>
</li>
<li>
<a href='file:/home/mark/ResultsDir/data4.html'>data4.html</a>
</li>
<li>
<a href='file:/home/mark/ResultsDir/data5.html'>data5.html</a>
</li>
</ul>
</body>
</html>