1package home
2
3import (
4 "std"
5 "strconv"
6 "strings"
7
8 "gno.land/p/demo/ownable"
9 "gno.land/p/moul/md"
10 "gno.land/r/leon/hof"
11
12 "gno.land/r/ursulovic/registry"
13)
14
15var (
16 aboutMe string
17 selectedImage string
18 Ownable *ownable.Ownable
19
20 githubUrl string
21 linkedinUrl string
22 imageUpdatePrice int64
23
24 isValidUrl func(string) bool
25)
26
27func init() {
28 Ownable = ownable.NewWithAddress(registry.MainAddress())
29
30 aboutMe = "Hi, I'm Ivan Ursulovic, a computer engineering graduate, blockchain enthusiast, and backend developer specializing in ASP.NET. I love learning new things and taking on challenges."
31 selectedImage = "https://i.ibb.co/W28NPkw/beograd.webp"
32
33 githubUrl = "https://github.com/ursulovic"
34 linkedinUrl = "https://www.linkedin.com/in/ivan-ursulovic-953310190/"
35 imageUpdatePrice = 5000000
36 isValidUrl = defaultURLValidation
37 hof.Register()
38}
39
40func Render(s string) string {
41 var sb strings.Builder
42 sb.WriteString(renderAboutMe())
43 sb.WriteString(renderSelectedImage())
44 sb.WriteString(renderContactsUrl())
45 return sb.String()
46}
47
48func defaultURLValidation(url string) bool {
49 const urlPrefix string = "https://i.ibb.co/"
50
51 if !strings.HasPrefix(url, urlPrefix) {
52 return false
53 }
54
55 if !(strings.HasSuffix(url, ".jpg") ||
56 strings.HasSuffix(url, ".png") ||
57 strings.HasSuffix(url, ".gif") ||
58 strings.HasSuffix(url, ".webp")) {
59 return false
60 }
61
62 urlPath := strings.TrimPrefix(url, "https://i.ibb.co/")
63 parts := strings.Split(urlPath, "/")
64
65 if len(parts) != 2 || len(parts[0]) == 0 || len(parts[1]) == 0 {
66 return false
67 }
68
69 return true
70}
71
72func UpdateSelectedImage(url string) {
73 if !isValidUrl(url) {
74 panic("Url is not valid!")
75 }
76
77 sentCoins := std.GetOrigSend()
78
79 if len(sentCoins) != 1 && sentCoins.AmountOf("ugnot") == imageUpdatePrice {
80 panic("Please send exactly " + strconv.Itoa(int(imageUpdatePrice)) + " ugnot")
81 }
82
83 selectedImage = url
84}
85
86func renderSelectedImage() string {
87 var sb strings.Builder
88
89 sb.WriteString(md.HorizontalRule())
90 sb.WriteString("\n")
91
92 sb.WriteString(md.H2("๐ธ Featured Image"))
93 sb.WriteString("\n")
94
95 sb.WriteString(md.Image("", selectedImage))
96 sb.WriteString("\n")
97
98 sb.WriteString(md.H4("โจ " + md.Link("Change this image for "+strconv.Itoa(int(imageUpdatePrice/1000000))+" GNOT. To update, set a direct image URL from ImgBB.", "https://gno.studio/connect/view/gno.land/r/ursulovic/home?network=portal-loop") + " โจ"))
99
100 return sb.String()
101}
102
103func renderAboutMe() string {
104 var sb strings.Builder
105
106 sb.WriteString(md.H1("๐ Welcome to Ivan's Homepage!"))
107 sb.WriteString("\n")
108
109 sb.WriteString(md.H2("๐จโ๐ป About Me"))
110 sb.WriteString("\n")
111
112 sb.WriteString(md.Blockquote(aboutMe))
113
114 return sb.String()
115}
116
117func renderContactsUrl() string {
118 var sb strings.Builder
119
120 sb.WriteString(md.HorizontalRule())
121 sb.WriteString("\n")
122
123 sb.WriteString(md.H2("๐ Let's Connect"))
124 sb.WriteString("\n")
125
126 items := []string{
127 "๐ " + md.Link("GitHub", githubUrl),
128 "๐ผ " + md.Link("LinkedIn", linkedinUrl),
129 }
130 sb.WriteString(md.BulletList(items))
131
132 return sb.String()
133}
134
135func UpdateGithubUrl(url string) {
136 Ownable.AssertCallerIsOwner()
137 githubUrl = url
138}
139
140func UpdateLinkedinUrl(url string) {
141 Ownable.AssertCallerIsOwner()
142 linkedinUrl = url
143}
144
145func UpdateAboutMe(text string) {
146 Ownable.AssertCallerIsOwner()
147 aboutMe = text
148}
149
150func UpdateImagePrice(newPrice int64) {
151 Ownable.AssertCallerIsOwner()
152 imageUpdatePrice = newPrice
153}
154
155func UpdateIsValidUrlFunction(f func(string) bool) {
156 Ownable.AssertCallerIsOwner()
157 isValidUrl = f
158}
home.gno
3.44 Kb ยท 158 lines