From 2b10bc61b7700b2b5e50124e17ddaf027f8c200f Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Mon, 22 May 2023 15:46:39 +0200 Subject: [PATCH] Setup up a first desktop version --- .gitignore | 2 + event.html | 102 ++++++++++++++++++++++------ main.go | 3 + render.go | 16 +++-- static/styles.css | 167 ++++++++++++++++++++++++++++++++++++++++++++++ utils.go | 8 +-- 6 files changed, 267 insertions(+), 31 deletions(-) create mode 100644 static/styles.css diff --git a/.gitignore b/.gitignore index 3e56dee..b2bd13d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ njump +.air.toml +tmp/* \ No newline at end of file diff --git a/event.html b/event.html index f45898e..04d1212 100644 --- a/event.html +++ b/event.html @@ -47,32 +47,89 @@ {{end}} - + + -
- open {{.type}} in {{range .clients}}
-    - {{.name}} {{end}} + + -
{{.eventJSON}}
-
+ +
+
+
+
+ + + + + + + + +
+
+ Last update:
+ {{.createdAt}} +
+
+
+
+ {{.content_json.name}} {{.content_json.display_name}} +
+
+ +
+ {{.content_json.about}} +
+
+
+
Public key
+ {{.npub}} +
+
+
NIP-05
+ {{.content_json.nip05}} +
+
+
LN Address
+ {{.content_json.lud16}} +
+
+
Metadata Event
+ {{.nevent}} +
+
+
JSON
+ {{.eventJSON}} +
+
+
+
+
Open {{.type}} in
+
+ {{range .clients}} +
+ {{.name}} + +
+ {{end}} +
+
+
+
+ + + +
+ diff --git a/main.go b/main.go index f28cec2..fd2997f 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,9 @@ import ( ) func main() { + + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + http.HandleFunc("/image/", generate) http.HandleFunc("/proxy/", proxy) http.HandleFunc("/", render) diff --git a/render.go b/render.go index e2990f6..8480536 100644 --- a/render.go +++ b/render.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" "text/template" - + "time" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" ) @@ -48,6 +48,7 @@ func render(w http.ResponseWriter, r *http.Request) { npub, _ := nip19.EncodePublicKey(event.PubKey) nevent, _ := nip19.EncodeEvent(event.ID, []string{}, event.PubKey) naddr := "" + createdAt := time.Unix(int64(event.CreatedAt), 0).Format("2006-01-02 15:04:05") author := event if event.Kind != 0 { @@ -142,21 +143,23 @@ func render(w http.ResponseWriter, r *http.Request) { // : '' textImageURL := "" - description := "" + content := "" + content_json := make(map[string]interface{}) if useTextImage { textImageURL = fmt.Sprintf("https://%s/image/%s", hostname, code) if subject != "" { - description = fmt.Sprintf("%s -- %s", subject, seenOnRelays) + content = fmt.Sprintf("%s -- %s", subject, seenOnRelays) } else { - description = seenOnRelays + content = seenOnRelays } } else { - description = prettyJsonOrRaw(event.Content) + content_json, content = prettyJsonOrRaw(event.Content) } eventJSON, _ := json.MarshalIndent(event, "", " ") params := map[string]any{ + "createdAt": createdAt, "clients": generateClientList(code, event), "type": typ, "title": title, @@ -166,7 +169,8 @@ func render(w http.ResponseWriter, r *http.Request) { "naddr": naddr, "metadata": metadata, "authorLong": authorLong, - "description": description, + "content": content, + "content_json": content_json, "textImageURL": textImageURL, "videoType": videoType, "image": image, diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..4ab66a5 --- /dev/null +++ b/static/styles.css @@ -0,0 +1,167 @@ +html { + font-family: Helvetica, sans-serif; + font-size: 20px; + font-weight: 300; +} + +body { + color: #373737; +} + +a { + color: #373737; +} + +.background { + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background-color: white; + overflow: hidden; + z-index: -1; +} + +.background::after { + content: ""; + position: absolute; + background-color: #FAFAFA; + width: 140%; + height: 100%; + transform: rotate(-20deg); + transform-origin: bottom; + bottom: -40%; +} + +.top, .container_wrapper { + display: flex; + justify-content: center; + align-items: center; +} + +.top { + margin: 1rem 0; + justify-content: left; +} + +.nostr_link { + flex-basis: 15%; + text-align: right; + text-decoration: none; +} + +.container { + display: flex; + width: 70%; + justify-content: space-between; + gap: 4.8vw; +} + +.column { +} + +.column1 { + flex-basis: 25%; + margin-top: 2rem; +} + +.container.profile .column1 .pic-wrapper { + max-width: 100%; + overflow: hidden; +} + +.container.profile .column1 img.pic { + max-width: 100%; + width: 100%; + height: auto; + -webkit-clip-path: url(#svg-shape); + -moz-clip-path: url(#svg-shape); + -o-clip-path: url(#svg-shape); + -ms-clip-path: url(#svg-shape); + clip-path: url(#svg-shape); +} + +.last_update { + font-size: 0.8em; + text-align: center; + color: #C9C9C9; +} + +.column2 { + flex-basis: 50%; + max-width: 50%; + flex-grow: 0; + flex-shrink: 0; + word-wrap: break-word; + margin-right: 1vw; +} + +.column2 .name { + font-size: 1.6rem; +} + +.column2 .name .display { + color: #C9C9C9; +} + +.column2 .separator { + height: 6px; + width: 30%; + margin-left: -0.6rem; + background-color: #F3F3F3; +} + +.column2 .field { + margin-bottom: 1.5rem; +} + +.column2 .field .label { + font-size: 0.8rem; + color: #E32A6D; +} + +.column3 { + flex-basis: 25%; + margin-top: 2rem; +} + +.column3 .title { + font-size: 0.8rem; + margin-bottom: 1rem; +} + +.column3 .btn { + display: flex; + align-items: center; + margin-bottom: 0.8rem; +} + +.column3 .btn a { + flex-basis: 80%; + padding: 0.4rem; + text-align: center; + font-size: 0.9rem; + color: #FFFFFF; + background-color: #5A5A5A; + text-decoration: none; + border-radius: 8px; +} + +.column3 .btn a:hover { + background-color: #373737; +} + +.column3 .btn:first-child a { + background-color: #E32A6D; +} + +.column3 .btn:first-child a:hover { + background-color: #bc1150; +} + +.column3 .btn span { + flex-basis: 20%; + margin-left: 0.4rem; + color: #9a9a9a; +} \ No newline at end of file diff --git a/utils.go b/utils.go index 54c77b9..92cf320 100644 --- a/utils.go +++ b/utils.go @@ -81,14 +81,14 @@ func mergeMaps[K comparable, V any](m1 map[K]V, m2 map[K]V) map[K]V { return m1 } -func prettyJsonOrRaw(j string) string { - var parsedContent any +func prettyJsonOrRaw(j string) (map[string]interface{}, string) { + var parsedContent map[string]interface{} if err := json.Unmarshal([]byte(j), &parsedContent); err == nil { if t, err := toml.Marshal(parsedContent); err == nil && len(t) > 0 { - return string(t) + return parsedContent, string(t) } } - return j + return nil, j } func getPreviewStyle(r *http.Request) string {