Digital-Humanities-Quarterly / dhq-journal

DHQ is an open-access, peer-reviewed journal of digital humanities.
http://www.digitalhumanities.org/dhq/
10 stars 5 forks source link

Static site generation: Ant task for previewing articles #38

Open amclark42 opened 1 year ago

amclark42 commented 1 year ago

First steps to creating a static site generator using Apache Ant. The build file has several stub Ant tasks, but the only one that works is the previewArticle task, which is also the default. This task prompts for an article ID (e.g. "000612"), then runs the XSLT to create an HTML preview of that article. To test, run ant -lib common/lib or ant -lib common/lib previewArticle from the repository main directory, and fill in an article identifier when prompted. An alternative is to set the article.id property when calling Ant, e.g. ant -lib common/lib -Darticle.id=000612. The HTML will be saved to dhq-journal/dhq-preview/ARTICLE-ID.html.

Changes:

Possible issues:

amclark42 commented 1 year ago

Thanks to @joelsjlee, we discovered that Saxon HE requires that the xmlresolver JAR be available in the Java environment, or the Ant transformation fails with an ambiguous

[xslt] Caught an error during transformation: java.lang.reflect.InvocationTargetException

While Ant provides two methods for setting the classpath for an <xslt> task, neither actually pulls in the xmlresolver JAR. Saxon's documentation says that these methods are "unreliable", stating "the safest approach is to ensure that the Jar files needed to run Saxon are present on the externally-specified classpath (the classpath at the point where Ant is invoked), rather than relying on the task-specific classpath." Getting access to the JAR therefore requires user intervention at a technical level, such as by placing the JAR in ~/.ant/lib.

This Ant build file is intended for use by people who may not have a lot of confidence with the command line or Java's complex needs, and so I added a check for the Java class org.xmlresolver.Resolver. If the class is available, transformation can occur. If not, the new checkXmlResolver task describes how to run Ant with the -lib option, e.g. ant -lib common/lib. (On Windows machines, the forward slash will display as a backward slash.)