anchor-compat.js 776 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Anchor compatibility with the old Jekyll (kramdown) site.
  3. *
  4. * Python-Markdown and kramdown agree on 59 of the 61 heading anchors. These
  5. * two differ, so old bookmarks and external deep links are redirected here.
  6. */
  7. var LEGACY_ANCHORS = {
  8. "awesome-django-": "awesome-django",
  9. "templates-1": "templates_1",
  10. };
  11. function resolveLegacyAnchor() {
  12. var hash = decodeURIComponent(window.location.hash.replace(/^#/, ""));
  13. if (!hash) return;
  14. var target = LEGACY_ANCHORS[hash];
  15. if (!target) return;
  16. var el = document.getElementById(target);
  17. if (!el) return;
  18. el.scrollIntoView();
  19. history.replaceState(null, "", "#" + target);
  20. }
  21. window.addEventListener("DOMContentLoaded", resolveLegacyAnchor);
  22. window.addEventListener("hashchange", resolveLegacyAnchor);