Playground
gnomod.toml
module = "gno.land/p/nym-moultest123/web25/v0" gno = "0.9" [addpkg] creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv" height = 186409 max_deposit = "5000000ugnot"
web25.gno
// Pacakge web25 provides an opinionated way to register an external web2
// frontend to provide a "better" web2.5 experience.
package web25
import (
"strings"
"gno.land/p/nym-moultest123/realmpath/v0"
)
type Config struct {
CID string
URL string
Text string
}
func (c *Config) SetRemoteFrontendByURL(url string) {
c.CID = ""
c.URL = url
}
func (c *Config) SetRemoteFrontendByCID(cid string) {
c.CID = cid
c.URL = ""
}
func (c Config) GetLink() string {
if c.CID != "" {
return "https://ipfs.io/ipfs/" + c.CID
}
return c.URL
}
const DefaultText = "Click [here]({link}) to visit the full rendering experience.\n"
// Render displays a frontend link at the top of your realm's Render function in
// a concistent way to help gno visitors to have a consistent experience.
//
// if query is not nil, then it will check if it's not disable by ?no-web25, so
// that you can call the render function from an external point of view.
func (c Config) Render(path string) string {
if realmpath.Parse(path).Query.Get("no-web25") == "1" {
return ""
}
text := c.Text
if text == "" {
text = DefaultText
}
text = strings.ReplaceAll(text, "{link}", c.GetLink())
return text
}
web25_test.gno
package web25