Better TOC generation workflow.

About my only gripes are the underscored vars instead of camelCase, but we can refactor these later.