File size: 4,459 Bytes
bc8bf33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{{ "<!-- fediverse.html -->" | safeHTML }}
{{- $instance := .instance  }}
{{- $user := .user  }}
{{- $post := .post  }}
{{- $tootContent := .tootContent }}
{{- $commentUrl := .commentUrl }}
<details id="comments" class="presentation" aria-label="{{ i18n "comments" }}" open>
    <summary class="section-title" role="button" aria-expanded="true" aria-controls="mastodon-comments-list">
        <span>{{ i18n "comments" }}</span>
    </summary>
    <code class="verbose" aria-hidden="true" hidden>
        <div class="has-aria-label-top" aria-label="Source:">
            <span>https://</span><span id="metadata-instance">{{ $instance }}</span>
            <span>/@</span><span id="metadata-user">{{ $user }}</span>
            <span>/</span><span id="metadata-post">{{ $post }}</span>
        </div>
        <div id="i18n--no-comment" class="has-aria-label-top" aria-label="[l10n] if no comment to display:">
            {{- i18n "noComment" -}}
        </div>
        <div id="i18n--is-loading" class="has-aria-label-top loading" aria-label="[l10n] if comments is loading:">
            {{- i18n "fediverseIsLoading" -}}
        </div>
        <div id="i18n--is-replies" class="has-aria-label-top" aria-label="[l10n] replies:">
            {{- i18n "replies" }}
        </div>
        <div id="i18n--is-reblogs" class="has-aria-label-top" aria-label="[l10n] reblogs:">
            {{- i18n "reblogs" }}
        </div>
        <div id="i18n--is-favourites" class="has-aria-label-top" aria-label="[l10n] favorites:">
            {{- i18n "favourites" }}
        </div>
    </code>
        <article id="discussion-starter">
            <div data-pagefind-body>{{ $tootContent | safeHTML }}</div>
            <footer>
                <a id="join-discussion" href="{{ $commentUrl }}" rel="nofollow" data-post-counter="">
                    <span>{{ i18n "ctaComments" }}</span>
                </a>
                <div id="mastodon-stats" class="stat" aria-live="polite"></div>
            </footer>
        </article>
    <div id="mastodon-comments-list" role="feed" aria-busy="true" aria-label="{{ i18n "comments" }}"></div>
    <noscript>
        <div id="comments-error" role="alert">{{ i18n "noScript" }} {{ i18n "noComment" }}</div>
    </noscript>
    {{ partialCached "partials/fediverse/js.html" . }}
</details>

{{/*-------------------- end of fediverse.html ---------------------*/}}

{{- define "partials/fediverse/js.html" -}}
    {{ "<!-- fediverse/js.html -->" | safeHTML }}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.4.1/purify.min.js" referrerpolicy="no-referrer"
        integrity="sha512-uHOKtSfJWScGmyyFr2O2+efpDx2nhwHU2v7MVeptzZoiC7bdF6Ny/CmZhN2AwIK1oCFiVQQ5DA/L9FSzyPNu6Q==" crossorigin="anonymous" ></script>
    {{- $fediverse := resources.Get "js/fediverse.js" | minify }}
    {{- if eq hugo.Environment "development" }}
        <script src="{{ $fediverse.Permalink }}" defer></script>
    {{- else }}
        {{- with $fediverse | fingerprint "sha384" }}
            <script src="{{ $fediverse.Permalink }}"
                integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
                defer></script>
        {{- end }}
    {{- end }}
{{- end }}

{{- define "partials/fediverse/instance.html" -}}
    {{- $instance := or .Params.Fediverse.Host .Params.Fediverse.Instance site.Params.fediverse.instance site.Params.fediverse.host }}
    {{- $commentUrl := or .Params.toot .Params.comment }}
    {{- if $commentUrl }}
        {{- $toot := split (replaceRE "^https?://" "" .Params.toot) "/" }}
        {{- $instance = index $toot 0 }}
    {{- end }}
    {{- return $instance }}
{{- end }}

{{- define "partials/fediverse/username.html" -}}
    {{- $username := or .Params.Fediverse.User .Params.Fediverse.Username site.Params.fediverse.username site.Params.fediverse.user }}
    {{- $commentUrl := or .Params.toot .Params.comment }}
    {{- if $commentUrl }}
        {{- $toot := split (replaceRE "^https?://" "" .Params.toot) "/" }}
        {{- $username = trim (index $toot 1) "@" }}
    {{- end }}
    {{- return $username }}
{{- end }}

{{- define "partials/fediverse/post.html" -}}
    {{- $post := or .Params.Fediverse.post .Params.Fediverse.link }}
    {{- $commentUrl := or .Params.toot .Params.comment }}
    {{- if $commentUrl }}
        {{- $toot := split (replaceRE "^https?://" "" .Params.toot) "/" }}
        {{- $post = index $toot 2 }}
    {{- end }}
    {{- return $post }}
{{- end }}