Improve anchor_links.html

I will rebase this as soon as https://github.com/jekyll/jekyll/pull/2367 is merged.

* fix `TypeError` when we are in home
* remove default type and encoding
* reformat the code
* move JS before `</body>`