Optimized version of the build-docs script.