MathJax is shutting down its CDN, as officially announced on the MathJax website and on StackExchange's Meta. The official announcement recommends several alternatives, including using an alternative CDN and self-hosting. What is the best way to accomplish this process for a site with a large number of references to the MathJax CDN?
On my tiny little website, for example, I can count the number of files that I have that point to the MathJax CDN using the following unix command:
grep -rl 'cdn\.mathjax\.org/mathjax/latest/MathJax\.js' . | grep '\.html$' | wc -l
I find that I have 382 such files. What's the best (safest) way to go automate the process of going through these files and modifying the source to point to the new CDN, rather than the old CDN?
Note: I can use Python to traverse the directory tree and do search and replace pretty easily. I'm interested in robust techniques. In fact, I've already post a self-answer that uses BeautifulSoup to find and replace MathJax src links. This is the way that I usually use MathJax, but there are other ways, of course.