summaryrefslogtreecommitdiff
path: root/layouts/_partials/posts/webmention.html
blob: 93623792e211055170bde4e66d8f385e0ee0a237 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{{ $page := . }}
{{ $currentPagePath := .RelPermalink }}
{{ $webmentions_url := .Site.Params.webmention.src }}

{{ with try (resources.GetRemote $webmentions_url) }}
    {{ with .Err }}
        {{ errorf "%s" . }}

    {{ else with .Value }}
        {{ $webmentions := slice }}
        {{ $data := . | transform.Unmarshal }}

        {{ range $data }}
            {{ $urlObj := urls.Parse .webmention.target }}
            {{ $targetPath := $urlObj.Path }}

            {{ if or (strings.Contains $targetPath $currentPagePath)
                     (strings.Contains $targetPath ($currentPagePath | urlquery)) }}
                {{ $webmentions = $webmentions | append . }}
            {{ end }}
        {{ end }}

        {{ $likes := slice }}
        {{ $replies := slice }}
        {{ $reposts := slice }}
        {{ $mentions := slice }}

        {{ range $webmentions }}
          {{ $mf := index . "microformats" }}
          {{ if $mf }}
              {{ $type := index $mf "type" }}
              {{ if eq $type "like-of" }}
                {{ $likes = $likes | append . }}

              {{ else if eq $type "repost-of" }}
                {{ $reposts = $mentions | append . }}

              {{ else if eq $type "in-reply-to" }}
                {{ $replies = $replies | append . }}

              {{ else }}
                {{ $mentions = $mentions | append . }}

              {{ end }}
          {{ else }}
            {{ $mentions = $mentions | append . }}
          {{ end }}

        {{ end }}

        {{ if $webmentions }}
        <div class="px-6 py-2 rd-lg my-4"
             style="background-color: oklch(from var(--block-background-color) l c h / calc(alpha - 0.5))">
            <h2 class="flex items-center gap-2 text-lg">
                <img src="/icons/mention.svg" width="18px" height="18px"> 
                <span>Webmention</span>
            </h2>
            {{ partial "posts/webmention-summary" (dict
                "likes" $likes
                "page" $page
                "othercount" (add (len $replies) (len $mentions))
                ) }}
            <div id="webmention-details">
                {{ partial "posts/webmention-replies" $replies }}
                {{ partial "posts/webmention-mentions" $mentions }}
            </div>
        </div>
        {{ end }}
    {{ else }}
        <p>Unable to fetch webmentions. Please contact webmaster.</p>
    {{ end }}
{{ end }}