Refactor sphinx build logic into utils module.
Attempt to use globaltoc then fall back to local.