{{ define "main" }}

{{- partial "header.html" . -}}

<div class="container single page">

    <aside>
        {{ .TableOfContents }}
    </aside>

    <article>
        {{ if or ( or ( not ( isset .Params "date" ) ) ( lt .Date now ) ) ( eq ( .Site.Params.ShowFuture ) "TRUE" ) }}
            {{ with .Date }}<h3>{{ .Format "January 2, 2006" }} -  {{ $.Param "author" }}</h3>{{ end }}
            <h1>{{ .Title }}</h1>
            {{ .Content }}
        {{ else }}
            <h1>Soon to come, check back on {{ .Date.Format "January 2, 2006" }}!</h1>
            <br/>
            <h4>Want early access to content? <a href="{{ .Site.Params.PatreonLink }}">Come support us on Patreon!</a></h4>
            <h4>Already a patron? <a href="{{ .Site.Params.PreviewLink }}">Access early content here!</a> (Requires Logging in via Patreon)</h4>
            <br/>
        {{ end }}

        {{ $.Scratch.Set "pageTitle" .Title }}
        {{ $.Scratch.Set "site" .Site }}
        {{ $.Scratch.Set "prev" .PrevInSection }}
        {{ $.Scratch.Set "next" .NextInSection }}

        {{ with .Section}}
            
            {{ range last 1 (where ($.Scratch.Get "site").RegularPages "Section" "catalogue") }}
                {{ if ne .Title ($.Scratch.Get "pageTitle") }}
                    <p>
                        <a href="{{ .Permalink }}"><< Give us that ole classic</a>
                    </p>
                {{ end }}

                {{ $.Scratch.Set "firstTitle" .Title }}
                {{ with ($.Scratch.Get "prev") }}
                    {{ if ne .Title ($.Scratch.Get "firstTitle") }}
                        <p>
                            <a href="{{ .Permalink }}">< Tell us that one from the other day</a>
                        </p>
                    {{ end }}
                {{ end }}
            {{ end }}
            {{ if eq ( ($.Scratch.Get "site").Params.ShowFuture ) "TRUE" }}
                <!-- Direct link to latest article regardles of date -->
                {{ range first 1 (where ($.Scratch.Get "site").RegularPages "Section" "catalogue") }}
                    {{ $.Scratch.Set "latestTitle" .Title }}

                    {{ with ($.Scratch.Get "next") }}
                        {{ if ne .Title ($.Scratch.Get "latestTitle") }}
                            <p>
                                <a href="{{ .Permalink }}">Spin me another tale, keeper ></a>
                            </p>
                        {{ end }}
                    {{ end }}

                    {{ if ne .Title ($.Scratch.Get "pageTitle") }}
                        <p>
                            <a href="{{ .Permalink }}">Give us something new >></a>
                        </p>
                    {{ end }}
                {{ end }}
            {{ else }}
                <!-- Direct link to latest article not in the future -->
                {{ range first 1 (where (where ($.Scratch.Get "site").RegularPages "Section" "catalogue") "Params.date" "lt" now) }}
                    {{ $.Scratch.Set "latestTitle" .Title }}

                    {{ with ($.Scratch.Get "next") }}
                        {{ if ne .Title ($.Scratch.Get "latestTitle") }}
                            <p>
                                <a href="{{ .Permalink }}">Spin me another tale, keeper ></a>
                            </p>
                        {{ end }}
                    {{ end }}

                    {{ if ne .Title ($.Scratch.Get "pageTitle") }}
                        <p>
                            <a href="{{ .Permalink }}">Give us something new >></a>
                        </p>
                    {{ end }}
                {{ end }}
            {{ end }}
            
        {{ end }}
        
        {{- partial "footer.html" . -}}

    </article>

</div>

{{ end }}