-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathhighlight.templ
More file actions
93 lines (86 loc) · 2.43 KB
/
Copy pathhighlight.templ
File metadata and controls
93 lines (86 loc) · 2.43 KB
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
package main
import (
"fiatjaf.com/nostr/sdk"
"html/template"
"strings"
)
type HighlightPageParams struct {
BaseEventPageParams
OpenGraphParams
HeadParams
Details DetailsParams
Content template.HTML
HighlightEvent Kind9802Metadata
Clients []ClientReference
}
type Kind9802Metadata struct {
Author sdk.ProfileMetadata
SourceEvent string
SourceURL string
SourceName string
Context string
MarkedContext string
Comment string
}
func getTextFragmentAnchor(sourceURL string, content string) string {
if !strings.HasSuffix(sourceURL, ".pdf") {
return "#:~:text=" + content
}
return ""
}
templ highlightInnerBlock(params HighlightPageParams) {
<h1 class="text-2xl" itemprop="headline">Highlight</h1>
<div itemprop="articleBody">
if params.HighlightEvent.Comment != "" {
<div dir="auto" class="leading-6">
@templ.Raw(params.HighlightEvent.Comment)
</div>
}
<blockquote dir="auto" class="text-xl leading-7">
if params.HighlightEvent.MarkedContext != "" {
@templ.Raw(params.HighlightEvent.MarkedContext)
} else {
@templ.Raw(params.Content)
}
<footer class="flex text-base mt-4">
<span>—</span>
if params.HighlightEvent.Author.Name != "" {
<a href={ "https://njump.me/" + templ.SafeURL(params.HighlightEvent.Author.Npub()) } class="flex ml-2">
<img src={ params.HighlightEvent.Author.Picture } class="h-6 m-0 mr-1 rounded-full"/>
{ params.HighlightEvent.Author.Name }
</a>,
}
<cite class="ml-2">
if params.HighlightEvent.SourceURL != "" {
<a href={ templ.SafeURL(params.HighlightEvent.SourceURL + getTextFragmentAnchor(params.HighlightEvent.SourceURL, string(params.Content))) }>{ params.HighlightEvent.SourceName }</a>
}
if params.HighlightEvent.SourceEvent != "" {
<a href={ templ.SafeURL("/" + params.HighlightEvent.SourceEvent + getTextFragmentAnchor(params.HighlightEvent.SourceURL, string(params.Content))) }>{ params.HighlightEvent.SourceName }</a>
}
</cite>
</footer>
</blockquote>
</div>
}
templ highlightTemplate(params HighlightPageParams, isEmbed bool) {
<!DOCTYPE html>
if isEmbed {
@embeddedPageTemplate(
params.Event,
params.NeventNaked,
) {
@highlightInnerBlock(params)
}
} else {
@eventPageTemplate(
"Highlight",
params.OpenGraphParams,
params.HeadParams,
params.Clients,
params.Details,
params.Event,
) {
@highlightInnerBlock(params)
}
}
}