Entry Points in ConstexprJS

Top

constexprjs executable requires three mandatory arguments, --input, --output, and --entry. --entry option can be used multiple times in an invocation. Its values must be paths of HTML files relative to the input root:

constexprjs --input=. --output=../deployment --entry /index.html --entry /subsite/index.html

This is the sequence of operations constexprjs performs when it is invoked:

  1. Render all the pages. For each page:
    1. Figure out its dependencies (css, images, etc).
    2. Snapshot the DOM state when the page finishes rendering.
    3. Close the page.
  2. Write the DOM snapshots of each page as HTML files.
  3. Combine the dependency lists of all the pages into a single list.
  4. Copy dependencies to the output directory.

It maintains a list of pages that it needs to process. In the beginning, this list contains only the pages specified as entry points (/index.html and /subsite/index.html in the above example). The constexpr code inside these entry points is supposed to use the addPaths api hook to notify the compiler about other pages that it needs to render. The argument of this function must be an object with two keys, generator and output:

window._ConstexprJS_.addPath( { generator: "/about.html", output: "/about.html" } ) window._ConstexprJS_.addPath( { generator: "/posts/generator_from_date.html?2023-jan", output: "/posts/2023-jan.html" } )

These invocations will append /about.html and /posts/generator_from_date.html?2023-jan to the list of pages that the compiler needs to process. The compilation results of these pages will be written to /about.html and /posts/2023-jan.html respectively.

Think of the generator page as a function that takes input in url query string/hash and produces the intended page as output.

Every page except the entry points will have a parent page which queued it for compilation. The queueing relationship between the pages will form a tree:

%0 a /index.html b /about.html a--b c /tags.html a--c d /tags/javascript.html c--d e /tags/webdev.html c--e f /tags/clojure.html c--f