_content/blog: don't load godocs.js (and other scripts) more than once

By now, the /js/godocs.js and /js/playground.js scripts are already
loaded on all go.dev pages because they're included at the bottom of
the root site.tmpl template. The layout template for blog pages also
loads those scripts.

That means /js/godocs.js runs twice, and that causes duplicate anchor
links to be added to article headings.

Remove the duplicate scripts, keeping only play.js which isn't already
present in site.html. Update it to reuse the existing window.initFuncs
mechanism.

For golang/go#68596.
For golang/go#69816.

Change-Id: I709f4b8df30500bddbbf16f4ddd95f266f290472
Reviewed-on: https://go-review.googlesource.com/c/website/+/619015
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/_content/blog/default.tmpl b/_content/blog/default.tmpl
index b4de71b..130cb6e 100644
--- a/_content/blog/default.tmpl
+++ b/_content/blog/default.tmpl
@@ -42,10 +42,7 @@
   </div><!-- #content -->
 </div>
 
-<script src="/js/jquery.js"></script>
-<script src="/js/playground.js"></script>
 <script src="/js/play.js"></script>
-<script src="/js/godocs.js"></script>
 {{end}}
 
 {{define "by list" -}}
diff --git a/_content/js/godocs.js b/_content/js/godocs.js
index 433096a..8b69dfd 100644
--- a/_content/js/godocs.js
+++ b/_content/js/godocs.js
@@ -380,7 +380,7 @@
     personalizeInstallInstructions();
     updateVersionTags();
 
-    // site.js defines window.initFuncs in the global scope, and root.html and
+    // site.js defines window.initFuncs in the global scope, and play.js and
     // codewalk.js push their on-page-ready functions to the list.
     // We execute those functions here, to avoid loading jQuery until the page
     // content is loaded.
diff --git a/_content/js/play.js b/_content/js/play.js
index eae69eb..982d8b3 100644
--- a/_content/js/play.js
+++ b/_content/js/play.js
@@ -141,4 +141,4 @@
   }
 }
 
-$(function() { playStart() });
+window.initFuncs.push(playStart);
diff --git a/cmd/golangorg/testdata/blog.txt b/cmd/golangorg/testdata/blog.txt
index aea168d..2b17d9a 100644
--- a/cmd/golangorg/testdata/blog.txt
+++ b/cmd/golangorg/testdata/blog.txt
@@ -75,3 +75,8 @@
 
 GET https://blog.golang.org/?googlecn=1
 redirect == https://golang.google.cn/?googlecn=1
+
+GET https://go.dev/blog/alias-names
+hint the godocs.js script should be loaded once, and no more
+body ~ (<script src="/js/godocs\.js"></script>(.|\n)+){1}
+body !~ (<script src="/js/godocs\.js"></script>(.|\n)+){2}