diff --git a/assets/gtag.ts b/assets/gtag.ts new file mode 100644 index 00000000..895ddec6 --- /dev/null +++ b/assets/gtag.ts @@ -0,0 +1,45 @@ +export {}; + +declare global { + interface Window { + dataLayer: IArguments[]; + } +} + +const IDENTIFY = "G-N24RP9JT2Q"; + +self.dataLayer = self.dataLayer || []; + +gtag("js", new Date()); +gtag("config", IDENTIFY); +restoreClientID(); + +loadScript("https://www.googletagmanager.com/gtag/js?id=" + IDENTIFY); + +function gtag(method: string, ...params: unknown[]): void { + self.dataLayer.push(arguments); +} + +function restoreClientID() { + const KEY = "GA:CLIENT-ID"; + const clientId = sessionStorage.getItem(KEY); + if (clientId) { + gtag("set", "client_id", clientId); + } else { + gtag("get", IDENTIFY, "client_id", (client_id: string) => { + sessionStorage.setItem(KEY, client_id); + }); + } +} + +function loadScript(src: string) { + return new Promise((resolve, reject) => { + const element = document.createElement("script"); + element.src = src; + element.async = true; + element.defer = true; + element.addEventListener("load", resolve); + element.addEventListener("error", reject); + document.head.appendChild(element); + }); +} diff --git a/layouts/_default/section.html b/layouts/_default/section.html index 89892b90..764e27ad 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -2,6 +2,5 @@ {{ partial "main/header.html" . }} {{ end }} {{ define "main" }} - {{ $section_to_display := .Pages }} - {{ partial "main/list.html" (dict "context" . "section_to_display" $section_to_display) }} + {{ partial "main/list.html" (dict "context" . "section_to_display" .Pages) }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/head/services.html b/layouts/partials/head/services.html new file mode 100644 index 00000000..fa388fe1 --- /dev/null +++ b/layouts/partials/head/services.html @@ -0,0 +1,8 @@ +{{- if ne .Site.BaseURL "https://mtf.wiki" }} + +{{- end }} +{{- if hugo.IsProduction }} +{{- with resources.Get "gtag.ts" | js.Build | minify | fingerprint }} + +{{- end }} +{{- end }} \ No newline at end of file diff --git a/layouts/robots.txt b/layouts/robots.txt index 7a49e882..f1146a8e 100644 --- a/layouts/robots.txt +++ b/layouts/robots.txt @@ -1,8 +1,6 @@ User-agent: * {{- if eq .Site.BaseURL "https://mtf.wiki" }} -{{- range $.Site.Home.AllTranslations }} -Sitemap: {{ .RelPermalink }}sitemap.xml -{{- end }} +Sitemap: {{ absURL "sitemap.xml" }} {{- else }} Disallow: / {{- end }} \ No newline at end of file