Skip to content

Commit 75d051f

Browse files
Script: add html-incremental target
1 parent 3be64ff commit 75d051f

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

pretext/lib/pretext.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4822,6 +4822,41 @@ def html(xml, pub_file, stringparams, xmlid_root, file_format, extra_xsl, out_fi
48224822
time_logger.log("build completed")
48234823

48244824

4825+
def html_incremental(xml, pub_file, stringparams, xmlid_root, extra_xsl, dest_dir):
4826+
"""Update an HTML incrementally in place.
4827+
Depends on _static and generated files already being in the destination directory.
4828+
Caller must supply:
4829+
* stringparams supplemented with:
4830+
* rs-js, rs-css, and rs-version (can use _set_runestone_stringparams to set)
4831+
* publisher: path to publisher file for use by xsltproc
4832+
"""
4833+
if not "rs-js" in stringparams:
4834+
log.error("Incremental build missing needed stringparam(s). Unable to complete build.")
4835+
return False
4836+
4837+
# to ensure provided stringparams aren't mutated unintentionally
4838+
stringparams = stringparams.copy()
4839+
4840+
log_time_info = stringparams.get("profile-py", False) == "yes"
4841+
time_logger = Stopwatch("html_incremental()", log_time_info)
4842+
4843+
# support publisher file, and subtree argument
4844+
if pub_file:
4845+
stringparams["publisher"] = pub_file
4846+
if xmlid_root:
4847+
stringparams["subtree"] = xmlid_root
4848+
4849+
# Optional extra XSL could be None, or sanitized full filename
4850+
if extra_xsl:
4851+
extraction_xslt = extra_xsl
4852+
else:
4853+
extraction_xslt = os.path.join(get_ptx_xsl_path(), "pretext-html.xsl")
4854+
4855+
log.info("incremental convertsion of {} to HTML in {}".format(xml, dest_dir))
4856+
xsltproc(extraction_xslt, xml, None, dest_dir, stringparams)
4857+
time_logger.log("xsltproc complete")
4858+
4859+
48254860
def revealjs(
48264861
xml, pub_file, stringparams, xmlid_root, file_format, extra_xsl, out_file, dest_dir
48274862
):

pretext/pretext

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,37 @@ def main():
783783
dest_dir,
784784
None
785785
)
786+
elif args.format == "html-incremental":
787+
# -----------------------------------------
788+
# Setup - this work could be done one time in a frontend that is monitoring changes
789+
# Force incremental build flag
790+
stringparams["html.build-incremental"] = "yes"
791+
792+
log_time_info = stringparams.get("profile-py", False) == "yes"
793+
time_logger = ptx.Stopwatch("pretext:html-incremental", log_time_info)
794+
795+
# attempt to reuse RS services
796+
if "debug.rs.dev" in stringparams:
797+
rs_js, rs_css, rs_cdn_url, rs_version, services_xml = ptx._runestone_debug_service_info()
798+
else:
799+
rs_js, rs_css, rs_cdn_url, rs_version = ptx.query_existing_runestone_services(
800+
dest_dir=dest_dir,
801+
stringparams=stringparams
802+
)
803+
ptx._set_runestone_stringparams(stringparams, rs_js, rs_css, rs_version)
804+
time_logger.log("runestone stringparams set")
805+
806+
# -----------------------------------------
807+
# Actual incremental build, this is the only work done on each change
808+
ptx.html_incremental(
809+
xml=xml_source,
810+
pub_file=publication_file,
811+
stringparams=stringparams,
812+
xmlid_root=args.xmlid,
813+
extra_xsl=extra_stylesheet,
814+
dest_dir=dest_dir,
815+
)
816+
time_logger.log("complete incremental build")
786817
elif args.format == "html-zip":
787818
# no "subtree root" build is possible
788819
ptx.html(

0 commit comments

Comments
 (0)