{{ define "main" }}
    <h2>{{ .Title }}</h2>

    {{ if in .File.Dir "blog" }}
        <i style="margin: 0">
        Posted on
        <time datetime="{{ .Page.Lastmod.Format "2006-01-02" }}" class="text-muted">
            {{ $.Date.Format "January 02, 2006" }}
        </time>
        <time datetime="{{ .Page.Lastmod.Format "2006-01-02" }}" class="text-muted">
            (Updated on {{ $.Page.Lastmod.Format "January 02, 2006" }})
        </time>
        </i>
    {{ end }}

    <hr>

    {{ if .Params.toc }}
    <details>
        <summary>Table of Contents</summary>
        {{ .Page.TableOfContents }}
    </details>
    {{ end }}

    {{ .Content }}

    {{ if in .File.Dir "blog" }}
        {{ partial "voting" . }}

        {{ partial "comments" . }}
    {{ end }}

    {{ if .Params.threejs }}
        {{ $imagesloaded := resources.Get "js/three.js" }}
        {{ if hugo.IsProduction }}
            {{ $imagesloaded = $imagesloaded | minify | fingerprint | resources.PostProcess }}
        {{ end }}
        <script src="{{ $imagesloaded.RelPermalink }}" integrity="{{ $imagesloaded.Data.Integrity }}"></script>
    {{ end }}

    {{ if .Params.math }}
        {{ $math := resources.Get "js/katex.js" }}
        {{ if hugo.IsProduction }}
            {{ $math = $math | minify | fingerprint | resources.PostProcess }}
        {{ end }}
        <script src="{{ $math.RelPermalink }}" integrity="{{ $math.Data.Integrity }}"></script>

        {{ $autorender := resources.Get "js/auto-render.js" }}
        {{ if hugo.IsProduction }}
            {{ $autorender = $autorender | minify | fingerprint | resources.PostProcess }}
        {{ end }}
        <script src="{{ $autorender.RelPermalink }}" integrity="{{ $autorender.Data.Integrity }}"></script>

        {{ $style := resources.Get "css/katex.css" }}
        {{ if hugo.IsProduction }}
            {{ $style = $style | minify | fingerprint | resources.PostProcess }}
        {{ end }}
        <link href="{{ $style.RelPermalink }}" integrity="{{ $style.Data.Integrity }}" rel="stylesheet">

        <script>
            document.addEventListener("DOMContentLoaded", function() {
                renderMathInElement(document.body, {
                    delimiters: [
                        {left: "$$", right: "$$", display: true},
                        {left: "$", right: "$", display: false}
                    ]
                });
            });
        </script>
    {{ end }}
{{ end }}
