How to Auto-Refresh with Baseprinter
This guide explains how to automatically reload previews of Baseprint document snapshots in your web browser when you save a change to a source text file.
Prerequisites
Either
- a setup to run Baseprinter in containers (recommended)
OR
Stages
The automatic reloading of a Baseprint preview web page occurs in three stages.
Stage 1: Save Source File Changes from a Text Editor
You can use any text editor to save changes to your source files.
The next stage will be triggered when you save a text file that is being
monitored by baseprinter
.
Warning
Some editors, like vim
on Linux, by default change files in a way that
prevents the proper functioning of file monitoring.
Either stick to monitoring a folder or, in the case of vim
, use set backupcopy=yes
.
Stage 2: Generate New HTML Preview Folder
With the -m
/--monitor
option of baseprinter
,
folders or files will be continuously monitored for changes.
Upon a folder or file change,
the outputs (for Baseprint snapshot, HTML, and/or PDF) will be automatically regenerated.
Press CTRL-C
to stop baseprinter
when running with the -m
/--monitor
option.
Stage 3: Preview Web Page Automatically Reloaded
Baseprinter will generate a folder containing a web page preview. The last stage is a local web server that can automatically trigger the reloading of preview web pages viewed in a web browser.
Locally Installed Utility
If you have installed Baseprinter locally, you will need to run a local web server with an automatic reload capability. One such utility is the NPM package live-server.
Using the Container
If you are running Baseprinter via containers,
the Baseprinter container image includes a web server that can trigger reloads.
It can be used by setting up a second shell function similar to the baseprinter
function in step two.
live-baseprinter() {
podman run --rm -v=.:/mnt -w=/mnt -p=8080:8080 -it --init \
registry.gitlab.com/perm.pub/dock/baseprinter bash -c "live-server --no-css-inject site & baseprinter -o=site $*"
}
Once the live-baseprinter
shell function is defined, you can run the shell command:
live-baseprinter --defaults mydoc/pandocin.yaml --monitor mydoc -b=baseprint --skip-pdf
This command operates similarly to baseprinter
,
but an -o=site
output option is automatically added.
After running this command,
you can navigate to http://localhost:8080
to view
an HTML preview of the baseprint that reloads automatically.