<head>
<title>{{.Title}}</title>

{{ $description := .Params.description}}
{{if .IsHome}}
  {{ $description = .Site.Params.description}}
{{end}}

<meta charset="utf-8">
<meta name="X-UA-Compatible" content="IE=edge">
<meta name="google-site-verification" content="{{ .Site.Params.googleSiteVerification }}">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="telephone=no" name="format-detection">
<meta name="description" content="{{ $description }}">
<meta name="renderer" content="webkit">
<meta name="theme-color" content="#ffffff">

<!-- open-graph -->
{{if .Site.Params.enableOpenGraph}}
{{ template "_internal/opengraph.html" . }}
{{end}}

<!-- twitter-cards -->
{{if .Site.Params.enableTwitterCards}}
{{ template "_internal/twitter_cards.html" . }}
{{end}}

<!-- metadata -->

{{ if .Site.GoogleAnalytics }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}

<!-- https://clarity.microsoft.com for detail -->
{{ if .Site.Params.Clarity }}
<script type="text/javascript">
  (function(c,l,a,r,i,t,y){
      c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
      t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
      y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
  })(window, document, "clarity", "script", "{{.Site.Params.Clarity}}");
</script>
{{ end }}

{{if .Site.Params.manifest}}
<link rel="manifest" href="{{.Site.Params.manifest}}">
{{end}}
  
{{if .Params.canonicalUrl}}
<link rel="canonical" href="{{.Params.canonicalUrl}}" />
{{end}}

<!-- favicon -->
{{ if .Site.Params.favicon }}
<link rel="icon" href="{{ .Site.Params.favicon | absURL }}">
{{ end }}

<!-- For compatibility. View https://github.com/AmazingRise/hugo-theme-diary/pull/135 for details.-->
{{- $hugoVersion := split (replaceRE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "$1 $2 $3" hugo.Version) " " -}}
{{- if and (eq (int (index $hugoVersion 0)) 0) (ge (int (index $hugoVersion 1)) 101) -}}
    {{- /* no leading slash */ -}}
    {{ if and (not (.Params.disableToC) ) (.IsPage) }}
      <script src="{{"js/toc.js" | relURL}}"></script>
    {{ end }}
    <link type="text/css" rel="stylesheet" href="{{"vendor/css/bootstrap.min.css" | relURL}}">
{{- else -}}
    {{- /* with leading slash */ -}}
    {{ if and (not (.Params.disableToC) ) (.IsPage) }}
      <script src="{{"/js/toc.js" | relURL}}"></script>
    {{ end }}
    <link type="text/css" rel="stylesheet" href="{{"/vendor/css/bootstrap.min.css" | relURL}}">
{{- end -}}

{{ if not .Site.Params.disableDarkmode }}
{{ $darkmode := resources.Get "scss/dark-mode.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $darkmode.RelPermalink }}" integrity="{{ $darkmode.Data.Integrity }}" media="screen">
{{ else }}
{{ $styles := resources.Get "scss/journal.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Integrity }}" media="screen">
{{ end }}

<link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Material+Icons">

{{ if .Site.Params.cloudflareToken }}
<!-- Cloudflare Web Analytics -->
<script defer
	src='https://static.cloudflareinsights.com/beacon.min.js'
	data-cf-beacon='{"token": "{{ .Site.Params.cloudflareToken }}"}'>
</script>
<!-- End Cloudflare Web Analytics -->
{{ end }}

{{ if or (.Params.enableLaTeX) (.Site.Params.enableLaTeX) }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/katex.min.css" integrity="sha384-RZU/ijkSsFbcmivfdRBQDtwuwVqK7GMOw6IMvKyeWL2K5UAlyp6WonmB8m7Jd0Hn" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/katex.min.js" integrity="sha384-pK1WpvzWVBQiP0/GjnvRxV4mOb0oxFuyRxJlk6vVw146n3egcN5C925NCP7a7BY8" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"></script>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        renderMathInElement(document.body, {
          // customised options
          // • auto-render specific keys, e.g.:
          delimiters: [
              {left: '$$', right: '$$', display: true},
              {left: '$', right: '$', display: false},
              {left: '\\(', right: '\\)', display: false},
              {left: '\\[', right: '\\]', display: true}
          ],
          // • rendering keys, e.g.:
          throwOnError : false
        });
    });
</script>
{{ end }}



{{ if and ( and ( .Site.Params.enableGitalk ) ( .IsPage ) ) ( or ( not ( isset .Params "comment" ) ) ( eq .Params.comment true ) ) }}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<!-- For compatibility. View https://github.com/AmazingRise/hugo-theme-diary/pull/135 for details.-->
{{- $hugoVersion := split (replaceRE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "$1 $2 $3" hugo.Version) " " -}}
{{- if and (eq (int (index $hugoVersion 0)) 0) (ge (int (index $hugoVersion 1)) 101) -}}
    {{- /* no leading slash */ -}}
    <script src="{{"vendor/js/md5.min.js" | relURL}}"></script>
{{- else -}}
    {{- /* with leading slash */ -}}
    <script src="{{"/vendor/js/md5.min.js" | relURL}}"></script>
{{- end -}}
<script>
  var gitalk = new Gitalk({
  clientID: '{{ .Site.Params.Gitalk.client_id }}',
  clientSecret: '{{ .Site.Params.Gitalk.client_secret }}',
  repo: '{{ .Site.Params.Gitalk.repo }}',
  owner: '{{ .Site.Params.Gitalk.owner }}',
  admin: ['{{ .Site.Params.Gitalk.owner }}'],
  id: md5(location.pathname),
  distractionFreeMode: 'false'
  });
  window.onload = function () {
        gitalk.render('gitalk-container')
  }
</script>
{{ end }}

{{ if and (.Site.Params.livereId) (.IsPage) }}
<script type="text/javascript">
</script>
{{ end }}

{{ if and (.Site.Params.disqusShortname) (.IsPage) }}
<script src="https://cdn.jsdelivr.net/npm/vue-disqus@3/dist/vue-disqus.js"></script>
{{ end }}

{{ if and (.Site.Params.enableTwikoo) (.IsPage) }}
<script src="https://cdn.jsdelivr.net/npm/twikoo@1.6.16/dist/twikoo.all.min.js"></script>
{{ end }}

{{ if and (.Site.Params.walineServer) (.IsPage) }}
<script src="https://unpkg.com/@waline/client@v2/dist/waline.js"></script>
  <link
    rel="stylesheet"
    href="https://unpkg.com/@waline/client@v2/dist/waline.css"
  />
{{ end }}

<!-- head custom -->
{{- partial "extended_head.html" . }}

</head>
