Last active
May 18, 2020 08:30
-
-
Save neelsmith/dd106a891143ffdc2ac9dd2b0abde39c to your computer and use it in GitHub Desktop.
A scala script (using ammonite shell imports) to write a facsimile edition of a codex from a CEX source file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* An Ammonite script to create a simple facsimile of a codex. | |
* | |
* The fax function loads a CITE Object repository from a CEX file. | |
* The repository should include a collection implementing | |
* the illustrated codex model from a CEX source file, and a collection of | |
* documentary images. The fax function writes out to a local | |
* directory a facsimile view as a series of markdown files with yaml headers suitable | |
* for dropping into a jekyll installation. | |
*/ | |
// Configure ammonite with necessary repository and libraries | |
val myBT = coursierapi.MavenRepository.of("https://dl.bintray.com/neelsmith/maven") | |
interp.repositories() ++= Seq(myBT) | |
import $ivy.`edu.holycross.shot::codexfax:2.0.0` | |
import $ivy.`edu.holycross.shot::citeobj:7.4.0` | |
import $ivy.`edu.holycross.shot.cite::xcite:4.2.1` | |
// Generic scala: | |
import edu.holycross.shot.codexfax._ | |
import edu.holycross.shot.citeobj._ | |
import edu.holycross.shot.cite.Cite2Urn | |
import java.io.File | |
/** Read a CEX file with a CITE Object Collection implementing the | |
* illustrated codex model, write to a local directory a facsimile edition | |
* in markdown format for the first collection found in the CEX data. | |
* | |
* @param cex Name of CEX source file. | |
* @param codexUrn URN of collection implementing the codex model. | |
* @param outputDirName Name of directory where facsimile files should be written. | |
* If it does not exist, a directory is created. | |
*/ | |
def fax(cex: String, codexUrn: Cite2Urn, outputDirName: String = "facsimile") : Unit = { | |
val outputDir = new java.io.File(outputDirName) | |
if (outputDir.isFile()) { | |
println("Refusing to overwrite existing file " + outputDirName) | |
} else { | |
if (! outputDir.exists()) { | |
outputDir.mkdirs | |
} | |
val repo = CiteRepositorySource.fromFile(cex) | |
val pages = repo.objectsForCollection(codexUrn) | |
val collectionLabel = repo.catalog.collection(codexUrn).get.collectionLabel | |
val facsimile = Facsimile(repo, codexUrn) | |
facsimile.edition(outputDirName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment