cowsaydemo.gno
0.97 Kb · 33 lines
1// Package cowsaydemo is a small gnoweb demo of the cowsay renderer provided by
2// the [p/moul/x/daily/cowsay](/p/moul/x/daily/cowsay/v0) library: it makes the
3// ASCII cow say whatever you put in the path.
4//
5// It contains no rendering logic of its own — the art comes entirely from
6// `cowsay.Say`.
7package cowsaydemo
8
9import (
10 "chain/markdown"
11 "strings"
12
13 "gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/daily/cowsay/v0"
14)
15
16// Render displays the cow for gnoweb.
17//
18// Render("") -> default message ("Moo!")
19// Render("/hello there") -> renders "hello there", word-wrapped
20func Render(path string) string {
21 msg := strings.TrimLeft(path, "/")
22 art := cowsay.Say(msg)
23
24 var b strings.Builder
25 b.WriteString("# cowsay\n\n")
26 if strings.TrimSpace(markdown.StripBidiAndZeroWidth(msg)) == "" {
27 b.WriteString("_Tip: pass a message in the path, e.g._ `/Hello, gno.land!`\n\n")
28 }
29 b.WriteString("```\n")
30 b.WriteString(art)
31 b.WriteString("```\n")
32 return b.String()
33}