Skip to content

Commit

Permalink
_content/blog: don't load godocs.js (and other scripts) more than once
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Oct 17, 2024
1 parent 4e362b4 commit 2da4c89
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 0 additions & 3 deletions _content/blog/default.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
Expand Down
2 changes: 1 addition & 1 deletion _content/js/godocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _content/js/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ function initPlayground(transport) {
}
}

$(function() { playStart() });
window.initFuncs.push(playStart);
5 changes: 5 additions & 0 deletions cmd/golangorg/testdata/blog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ body contains Go 1.16

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}

0 comments on commit 2da4c89

Please sign in to comment.