{{ define "main" }}
{{ if not (eq .Type "response" "bookmarkof")}}
<article class="post h-entry entry contents">
  <div class="author" style="display:none;">
    <a rel="author" class="u-author h-card" rel="me" href="https://jk.nipponalba.scot">{{ .Site.Params.Title }}<img src="/images/profile.jpg"/></a>
  </div>
    {{ with .Page.Params.Image }}{{ partial "taxonomy/image.html" . }}{{ end }}<h3 class="p-name entry-title">{{ .Title }}</h3><b>{{ .Description }}</b>
      <aside>
          {{ if eq .Type "article" }}<div class="info">
          {{ with .Page.Params.Blog }}Blog: {{ partial "taxonomy/blog.html" . }}{{ end }}<span id="info-date"><time class="dt-published" datetime="{{ .Date.Format "2 Jan 2006 15:04 GMT" }}">{{ .Date.Format "02/01/2006 15:04 GMT" }}</time></span><br/>
          {{ with .Page.Params.category }}Categories: {{ partial "taxonomy/categories.html" . }}{{ end }}<span class="reading-time">{{ .ReadingTime }}-minute read</span><br/>
          {{ with .Page.Params.tag }}Tags: {{ partial "taxonomy/tags.html" . }}{{ end }}
          </div>{{ end }}

<div class="e-content">
  {{ .Content }}
  {{ if eq .Type "photo"}}
    <div class="photogrid">
    {{ range .Page.Params.Photo }}
      <a href="{{ . }}"><img class="u-photo thumb" src="{{ replace . "800." "300."}}"/></a>
    {{end}}
    </div>
    {{end}}
    {{ if eq .Type "article" }}<div class="p-summary" style="display:none">
        {{ .Page.Params.summary }}<br/>
      </div>
    {{ end }}<br/>
</div>
{{ if not (eq .Type "article") }}<div class="info">
    {{ with .Page.Params.category }}Categories: {{ partial "taxonomy/categories.html" . }}{{ end }}
    </div>{{ end }}
{{ $pathJSON := (print .Permalink "bridgy.json") }}
{{ $relpathJSON := (print .RelPermalink "bridgy.json") }}
{{ if fileExists $relpathJSON }}
<span class="syndication">
  {{ $mJSON := getJSON $pathJSON  }}
  Syndicated to <a href="{{ printf $mJSON.url}}">Pleroma</a>
</span><span id="info-date"><a href="{{ .Permalink }}" class="u-url"><time class="dt-published" datetime="{{ .Date.Format "2 Jan 2006 15:04 GMT" }}">{{ .Date.Format "02/01/2006 15:04 GMT" }}</time></a></span>
{{ end }}
<a href="https://brid.gy/publish/mastodon"></a>
<div class="interactions"><h4>Interactions</h4></div>
<div class="webmention-form">
  <form action="https://webmention.io/jk.nipponalba.scot/webmention" method="post">
      <label>Did you mention this {{ .Type }} on your website? Put the URL of your post here:</label><br/>
      <input name="source" type="url"/>
      <input name="target" value="{{ .Permalink }}" type="hidden"/>
      <input value="Send Webmention" type="submit"/>
  </form>
</div>
{{ $pathJSON := (print "data" (strings.TrimSuffix "/" .RelPermalink) ".json") }}
{{ if fileExists $pathJSON }}
<div class="webmentions">
{{ $mJSON := getJSON $pathJSON }}
  <div class="like interaction"><h4>Likes</h4>{{ partial "likes.html" $mJSON }}</div>
  <div class="share interaction"><h4>Shares</h4>{{ partial "shares.html" $mJSON }}</div>
  <h4>Comments & Replies</h4>{{ partial "webmention.html" $mJSON }}
</div>
{{ end }}

    </aside>
</article>
{{ else if eq .Type "bookmarkof" }}
{{ $cats := slice }}
{{ range .Site.Data.bookmarks }}
  {{ $cats = $cats | append .category }}
{{ end }}
{{ $cats = uniq $cats | sort }}
{{ range $cats }}
    {{ $cat := . }}
<h4>{{ $cat }}</h4>
    {{ range $.Site.Data.bookmarks }}
    {{ if eq .category $cat }}
<section data-post-type="bookmark-of" data-post-id="{{ .Params.slug }}" class="bookmark h-entry">
  <div class="author" style="display:none">
    <a rel="author" class="p-author h-card" rel="me" href="https://jk.nipponalba.scot"><img src="/images/profile.jpg"/><div class="title">{{ .Site.Params.Title }}</div></a>
  </div>
  <aside>
    <article class="h-cite">
      <a href="{{ .bookmarkof | absURL }}" class="u-bookmark-of" target="_blank">{{ .name }}</a> - <div class="p-name p-content">{{ .content | markdownify }}</div>
    </article>
  </aside>
</section>
{{ end }}
{{ end }}
{{ end }}
{{ else }}
<article class="h-entry" id="response">
      <div class="author">
        <a rel="author" class="u-author h-card" rel="me" href="https://jk.nipponalba.scot"><img src="/images/profile.jpg"/><div class="title">{{ .Site.Params.Title }}</div></a>
      </div>
      <div>
          {{ if .Params.likeof }}<p>Liked <a href="{{ .Params.likeof }}" class="u-url u-like-of"> {{ .Params.likeof }}</a>{{ end }}
          {{ if .Params.inreplyto }}<p>Replied to <a href="{{ .Params.inreplyto }}" class="u-url u-in-reply-to"> {{ .Params.inreplyto }}</a>{{ end }}
          {{ if .Params.repostof }}<p>Shared <a href="{{ .Params.repostof }}" class="u-url u-repost-of"> {{ .Params.repostof }}</a>{{ end }}</p>
          {{ if .Content }}<div class="p-name p-content"><p>{{ .Content }}</p></div> {{end}}
          </div>
          {{ if not (eq .Type "article") }}<div class="info">
              {{ with .Page.Params.category }}Categories: {{ partial "taxonomy/categories.html" . }}{{ end }}<span id="info-date"><a href="{{ .Permalink }}" class="u-url"><time class="dt-published" datetime="{{ .Date.Format "2 Jan 2006 15:04 GMT" }}">{{ .Date.Format "02/01/2006 15:04 GMT" }}</time></a></span><br/>
              </div>{{ end }}
                      {{end}}

{{end}}