pull/652/head
Septs 2022-09-21 23:05:55 +08:00
parent 289e923111
commit 0d32150f91
No known key found for this signature in database
GPG Key ID: 65144037AFA516E1
4 changed files with 55 additions and 5 deletions

45
assets/gtag.ts 100644
View File

@ -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);
});
}

View File

@ -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 }}

View File

@ -0,0 +1,8 @@
{{- if ne .Site.BaseURL "https://mtf.wiki" }}
<meta name="robots" content="noindex, nofollow">
{{- end }}
{{- if hugo.IsProduction }}
{{- with resources.Get "gtag.ts" | js.Build | minify | fingerprint }}
<script src="{{ .Permalink }}" async defer></script>
{{- end }}
{{- end }}

View File

@ -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 }}