diff --git a/examples/gno.land/r/malek_/config/config.gno b/examples/gno.land/r/malek_/config/config.gno new file mode 100644 index 00000000000..cf5852a62f9 --- /dev/null +++ b/examples/gno.land/r/malek_/config/config.gno @@ -0,0 +1,65 @@ +package config + +import ( + "errors" + "std" +) + +var ( + main std.Address // malek's main address + backup std.Address // backup address +) + +func init() { + main = "g10ahumypepd2qcrau7kahv8q78f7jcdns5tn54a" +} + +func Address() std.Address { + return main +} + +func Backup() std.Address { + return backup +} + +func SetAddress(a std.Address) error { + if !a.IsValid() { + return errors.New("config: invalid address") + } + + if err := checkAuthorized(); err != nil { + return err + } + + main = a + return nil +} + +func SetBackup(a std.Address) error { + if !a.IsValid() { + return errors.New("config: invalid address") + } + + if err := checkAuthorized(); err != nil { + return err + } + + backup = a + return nil +} + +func checkAuthorized() error { + caller := std.PrevRealm().Addr() + if caller != main || caller != backup { + return errors.New("config: unauthorized") + } + + return nil +} + +func AssertAuthorized() { + caller := std.PrevRealm().Addr() + if caller != main || caller != backup { + panic("config: unauthorized") + } +} diff --git a/examples/gno.land/r/malek_/config/gno.mod b/examples/gno.land/r/malek_/config/gno.mod new file mode 100644 index 00000000000..5010f77cc9e --- /dev/null +++ b/examples/gno.land/r/malek_/config/gno.mod @@ -0,0 +1 @@ +module gno.land/r/malek_/config diff --git a/examples/gno.land/r/malek_/home/gno.mod b/examples/gno.land/r/malek_/home/gno.mod new file mode 100644 index 00000000000..08245a910a5 --- /dev/null +++ b/examples/gno.land/r/malek_/home/gno.mod @@ -0,0 +1,8 @@ +module gno.land/r/malek_/home + +require ( + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/art/gnoface v0.0.0-latest + gno.land/r/demo/art/millipede v0.0.0-latest + gno.land/r/malek_/config v0.0.0-latest +) diff --git a/examples/gno.land/r/malek_/home/home.gno b/examples/gno.land/r/malek_/home/home.gno new file mode 100644 index 00000000000..8463ba14986 --- /dev/null +++ b/examples/gno.land/r/malek_/home/home.gno @@ -0,0 +1,129 @@ +package home + +import ( + "std" + "strconv" + + "gno.land/p/demo/ufmt" + + "gno.land/r/demo/art/gnoface" + "gno.land/r/demo/art/millipede" + "gno.land/r/malek_/config" +) + +var ( + pfp string // link to profile picture + pfpCaption string // profile picture caption + abtMe [2]string +) + +func init() { + pfp = "https://i.ibb.co/xCfYWmG/To-God-we-belong-and-to-Him-we-shall-return.jpg" + pfpCaption = "[To God we belong and to Him we shall return](https://ibb.co/xCfYWmG)" + abtMe = [2]string{ + `### About me +Hi, I'm Malek, a Full Stack Developer and a grantee at gno.land. I am a tech/web3 enthusiast, +life-long learner, and sharer of knowledge.`, + `### Contributions +My contributions to gno.land can mainly be found here: + + +[issues](https://github.com/gnolang/gno/issues?q=sort:updated-desc+is:issue+author:maleklahbib+). + +[PRs](https://github.com/gnolang/gno/pulls?q=sort:updated-desc+is:pr+author:maleklahbib). + +TODO import r/gh. + +P.S: HomePage copied from @leohhhn's [homepage](https://gno.land/r/leon/home) :p + +Will be modified when I'll have more inspiration. +`, + } +} + +func UpdatePFP(url, caption string) { + config.AssertAuthorized() + pfp = url + pfpCaption = caption +} + +func UpdateAboutMe(col1, col2 string) { + config.AssertAuthorized() + abtMe[0] = col1 + abtMe[1] = col2 +} + +func Render(path string) string { + out := "# Malek's Homepage\n\n" + + out += renderAboutMe() + out += renderBlogPosts() + out += "\n\n" + out += renderArt() + + return out +} + +func renderBlogPosts() string { + out := "" + // out += "## Malek's Blog Posts" + + // todo fetch blog posts authored by @malek + // and render them + return out +} + +func renderAboutMe() string { + out := "
" + + out += "
\n\n" + out += ufmt.Sprintf("![my profile pic](%s)\n\n%s\n\n", pfp, pfpCaption) + out += "
\n\n" + + out += "
\n\n" + out += abtMe[0] + "\n\n" + out += "
\n\n" + + out += "
\n\n" + out += abtMe[1] + "\n\n" + out += "
\n\n" + + out += "
\n\n" + + return out +} + +func renderArt() string { + out := `
` + "\n\n" + out += "# Gno Art\n\n" + + out += "
" + + out += renderGnoFace() + out += renderMillipede() + out += "Empty spot :/" + + out += "
\n\n" + + out += "This art is dynamic; it will change with every new block.\n\n" + out += `
` + "\n" + + return out +} + +func renderGnoFace() string { + out := "
\n\n" + out += gnoface.Render(strconv.Itoa(int(std.GetHeight()))) + out += "
\n\n" + + return out +} + +func renderMillipede() string { + out := "
\n\n" + out += "Millipede\n\n" + out += "```\n" + millipede.Draw(int(std.GetHeight())%10+1) + "```\n" + out += "
\n\n" + + return out +}