Search Apps Documentation Source Content File Folder Download Copy

home.gno

2.66 Kb ยท 136 lines
  1package home
  2
  3import (
  4	"std"
  5	"strconv"
  6
  7	"gno.land/p/demo/ufmt"
  8
  9	"gno.land/r/demo/art/gnoface"
 10	"gno.land/r/demo/art/millipede"
 11	"gno.land/r/demo/mirror"
 12	"gno.land/r/leon/config"
 13	"gno.land/r/leon/hof"
 14)
 15
 16var (
 17	pfp        string // link to profile picture
 18	pfpCaption string // profile picture caption
 19	abtMe      [2]string
 20)
 21
 22func init() {
 23	pfp = "https://i.imgflip.com/91vskx.jpg"
 24	pfpCaption = "[My favourite painting & pfp](https://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog)"
 25	abtMe = [2]string{
 26		`### About me
 27Hi, I'm Leon, a DevRel Engineer at gno.land. I am a tech enthusiast, 
 28life-long learner, and sharer of knowledge.`,
 29		`### Contributions
 30My contributions to gno.land can mainly be found 
 31[here](https://github.com/gnolang/gno/issues?q=sort:updated-desc+author:leohhhn).
 32
 33TODO import r/gh
 34`,
 35	}
 36
 37	hof.Register()
 38	mirror.Register(std.CurrentRealm().PkgPath(), Render)
 39}
 40
 41func UpdatePFP(url, caption string) {
 42	if !isAuthorized(std.PrevRealm().Addr()) {
 43		panic(config.ErrUnauthorized)
 44	}
 45
 46	pfp = url
 47	pfpCaption = caption
 48}
 49
 50func UpdateAboutMe(col1, col2 string) {
 51	if !isAuthorized(std.PrevRealm().Addr()) {
 52		panic(config.ErrUnauthorized)
 53	}
 54
 55	abtMe[0] = col1
 56	abtMe[1] = col2
 57}
 58
 59func Render(path string) string {
 60	out := "# Leon's Homepage\n\n"
 61
 62	out += renderAboutMe()
 63	out += renderBlogPosts()
 64	out += "\n\n"
 65	out += renderArt()
 66
 67	return out
 68}
 69
 70func renderBlogPosts() string {
 71	out := ""
 72	//out += "## Leon's Blog Posts"
 73
 74	// todo fetch blog posts authored by @leohhhn
 75	// and render them
 76	return out
 77}
 78
 79func renderAboutMe() string {
 80	out := "<div class='columns-3'>"
 81
 82	out += "<div>\n\n"
 83	out += ufmt.Sprintf("![my profile pic](%s)\n\n%s\n\n", pfp, pfpCaption)
 84	out += "</div>\n\n"
 85
 86	out += "<div>\n\n"
 87	out += abtMe[0] + "\n\n"
 88	out += "</div>\n\n"
 89
 90	out += "<div>\n\n"
 91	out += abtMe[1] + "\n\n"
 92	out += "</div>\n\n"
 93
 94	out += "</div><!-- /columns-3 -->\n\n"
 95
 96	return out
 97}
 98
 99func renderArt() string {
100	out := `<div class="jumbotron">` + "\n\n"
101	out += "# Gno Art\n\n"
102
103	out += "<div class='columns-3'>"
104
105	out += renderGnoFace()
106	out += renderMillipede()
107	out += "Empty spot :/"
108
109	out += "</div><!-- /columns-3 -->\n\n"
110
111	out += "This art is dynamic; it will change with every new block.\n\n"
112	out += `</div><!-- /jumbotron -->` + "\n"
113
114	return out
115}
116
117func renderGnoFace() string {
118	out := "<div>\n\n"
119	out += gnoface.Render(strconv.Itoa(int(std.GetHeight())))
120	out += "</div>\n\n"
121
122	return out
123}
124
125func renderMillipede() string {
126	out := "<div>\n\n"
127	out += "Millipede\n\n"
128	out += "```\n" + millipede.Draw(int(std.GetHeight())%10+1) + "```\n"
129	out += "</div>\n\n"
130
131	return out
132}
133
134func isAuthorized(addr std.Address) bool {
135	return addr == config.Address() || addr == config.Backup()
136}