mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-02-03 18:02:27 +02:00
Move JavaScript code to head
template (#1210)
This will simplify our mdbook updates since there will be fewer customizations to copy over when a new mdbook version has changes to the `index.hbs` template.
This commit is contained in:
parent
e3f52b31c8
commit
0d566ce042
37
theme/head.hbs
Normal file
37
theme/head.hbs
Normal file
@ -0,0 +1,37 @@
|
||||
<script async src="https://www.gstatic.com/brandstudio/kato/cookie_choice_component/cookie_consent_bar.v3.js"
|
||||
data-autoload-cookie-consent-bar="true"></script>
|
||||
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ZN78TEJMRW"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'G-ZN78TEJMRW');
|
||||
</script>
|
||||
|
||||
{{! Move to template code after fixing this issue:
|
||||
https://github.com/google/mdbook-i18n-helpers/issues/70 }}
|
||||
<script>
|
||||
(function () {
|
||||
// See these pages for details:
|
||||
// https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
|
||||
// https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics
|
||||
let base = "https://google.github.io/comprehensive-rust";
|
||||
{{#if (eq language "en")}}
|
||||
let canonical_href = `${base}/{{ path }}`;
|
||||
{{else}}
|
||||
let canonical_href = `${base}/{{ language }}/{{ path }}`;
|
||||
{{/if}}
|
||||
|
||||
// mdbook gives us a string ending in ".md", we replace it with ".html":
|
||||
canonical_href = canonical_href.slice(0, -"md".length) + "html";
|
||||
if (canonical_href.endsWith("/index.html")) {
|
||||
canonical_href = canonical_href.slice(0, -"index.html".length);
|
||||
}
|
||||
|
||||
let link = document.createElement("link");
|
||||
link.rel = "canonical";
|
||||
link.href = canonical_href;
|
||||
document.head.appendChild(link);
|
||||
})()
|
||||
</script>
|
@ -11,16 +11,6 @@
|
||||
<base href="{{ base_url }}">
|
||||
{{/if}}
|
||||
|
||||
<script async src="https://www.gstatic.com/brandstudio/kato/cookie_choice_component/cookie_consent_bar.v3.js"
|
||||
data-autoload-cookie-consent-bar="true"></script>
|
||||
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ZN78TEJMRW"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'G-ZN78TEJMRW');
|
||||
</script>
|
||||
|
||||
<!-- Custom HTML head -->
|
||||
{{> head}}
|
||||
@ -147,33 +137,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{{! Move to template code after fixing this issue:
|
||||
https://github.com/google/mdbook-i18n-helpers/issues/70 }}
|
||||
<script>
|
||||
(function () {
|
||||
// See these pages for details:
|
||||
// https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
|
||||
// https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics
|
||||
let base = "https://google.github.io/comprehensive-rust";
|
||||
{{#if (eq language "en")}}
|
||||
let canonical_href = `${base}/{{ path }}`;
|
||||
{{else}}
|
||||
let canonical_href = `${base}/{{ language }}/{{ path }}`;
|
||||
{{/if}}
|
||||
|
||||
// mdbook gives us a string ending in ".md", we replace it with ".html":
|
||||
canonical_href = canonical_href.slice(0, -"md".length) + "html";
|
||||
if (canonical_href.endsWith("/index.html")) {
|
||||
canonical_href = canonical_href.slice(0, -"index.html".length);
|
||||
}
|
||||
|
||||
let link = document.createElement("link");
|
||||
link.rel = "canonical";
|
||||
link.href = canonical_href;
|
||||
document.head.appendChild(link);
|
||||
})()
|
||||
</script>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
||||
<div class="page">
|
||||
|
Loading…
x
Reference in New Issue
Block a user