diff --git a/etc/build.props b/etc/build.props --- a/etc/build.props +++ b/etc/build.props @@ -1,18 +1,19 @@ title = AFP/Tools module = $AFP_BASE/tools/lib/classes/afp_tools.jar requirements = \ env:ISABELLE_SCALA_JAR sources = \ tools/admin/afp_build_hugo.scala \ tools/admin/afp_build_python.scala \ tools/migration/afp_migrate_metadata.scala \ tools/afp_build_site.scala \ tools/afp_check_roots.scala \ tools/afp_dependencies.scala \ tools/afp_structure.scala \ tools/afp_tool.scala \ + tools/hugo.scala \ tools/metadata.scala \ tools/python.scala \ tools/toml.scala \ tools/utils.scala services = afp.Tools diff --git a/tools/hugo.scala b/tools/hugo.scala new file mode 100644 --- /dev/null +++ b/tools/hugo.scala @@ -0,0 +1,49 @@ +package afp + + +import isabelle._ + + +object Hugo +{ + val hugo_home = Isabelle_System.getenv("ISABELLE_HUGO") + val hugo_static = Path.explode("$AFP_BASE") + Path.make(List("admin", "site")) + + class Layout private(src_dir: Path, out_dir: Path) + { + private def write(file: Path, content: JSON.T): Unit = + { + val path = src_dir + file + path.dir.file.mkdirs() + File.write(path, isabelle.JSON.Format(content)) + } + + val data_dir = src_dir + Path.basic("data") + + def write_data(file: Path, content: JSON.T): Unit = + write(Path.basic("data") + file, content) + + val content_dir = src_dir + Path.basic("content") + + def write_content(file: Path, content: JSON.T): Unit = + write(Path.basic("content") + file, content) + + def write_static(): Unit = + Isabelle_System.copy_dir(hugo_static, out_dir) + + def build(): Process_Result = + { + val exec = Path.explode(proper_string(hugo_home).getOrElse(error("No hugo component found"))) + Path.basic("hugo") + Isabelle_System.bash( + exec.implode + " -s " + quote(src_dir.implode) + " -d " + quote(out_dir.implode)) + } + } + + object Layout + { + private val web_dir = Path.explode("$AFP_BASE") + Path.basic("web") + + def apply(src_dir: Path = web_dir + Path.basic("hugo"), out_dir: Path = web_dir): Layout = + new Layout(src_dir.absolute, out_dir.absolute) + } +} \ No newline at end of file