diff --git a/cmd/skywire-cli/commands/reward/rules.go b/cmd/skywire-cli/commands/reward/rules.go
index 9954e27bf..87a4f09bb 100644
--- a/cmd/skywire-cli/commands/reward/rules.go
+++ b/cmd/skywire-cli/commands/reward/rules.go
@@ -2,18 +2,28 @@
package clireward
import (
+ "bytes"
"fmt"
"os"
+ "regexp"
markdown "github.com/MichaelMure/go-term-markdown"
"github.com/spf13/cobra"
+ "github.com/yuin/goldmark"
+ "github.com/yuin/goldmark/extension"
+ "github.com/yuin/goldmark/renderer/html"
"golang.org/x/term"
"github.com/skycoin/skywire"
)
+var asHTML bool
+var rawFile bool
+
func init() {
rewardCmd.AddCommand(rulesCmd)
+ rulesCmd.Flags().BoolVarP(&asHTML, "html", "l", false, "render html from markdown")
+ rulesCmd.Flags().BoolVarP(&rawFile, "raw", "r", false, "print raw the embedded file")
}
var rulesCmd = &cobra.Command{
@@ -21,6 +31,26 @@ var rulesCmd = &cobra.Command{
Short: "display the mainnet rules",
Long: "display the mainnet rules",
Run: func(_ *cobra.Command, _ []string) {
+ if rawFile {
+ fmt.Println(skywire.MainnetRules)
+ os.Exit(0)
+ }
+ if asHTML {
+ // Preprocess to replace ~text~ with ~~text~~ for strikethrough
+ re := regexp.MustCompile(`~(.*?)~`)
+ rules := re.ReplaceAllString(skywire.MainnetRules, "~~$1~~")
+ var buf bytes.Buffer
+ md := goldmark.New(
+ goldmark.WithExtensions(extension.Strikethrough),
+ goldmark.WithRendererOptions(html.WithXHTML()), // Optional: add XHTML compatibility
+ )
+ if err := md.Convert([]byte(rules), &buf); err != nil {
+ fmt.Println("Error rendering markdown as HTML:", err)
+ os.Exit(1)
+ }
+ fmt.Println(buf.String())
+ os.Exit(0)
+ }
terminalWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
terminalWidth = 80
diff --git a/cmd/skywire-cli/commands/rewards/ui.go b/cmd/skywire-cli/commands/rewards/ui.go
index 736678c73..91ebefbda 100644
--- a/cmd/skywire-cli/commands/rewards/ui.go
+++ b/cmd/skywire-cli/commands/rewards/ui.go
@@ -104,8 +104,11 @@ func mainPage(c *gin.Context) {
fmt.Println("Error parsing Front Page template:", err1)
}
tmpl := tmpl0
+
+ mainnetRulesHtml, _ := script.Exec(`skywire cli reward rules -l`).String() //nolint
+ skywireVersion, _ := script.Exec(`skywire -v`).Replace("skywire version ", "").String() //nolint
htmlPageTemplateData1 := htmlPageTemplateData
- htmlPageTemplateData1.Content = htmpl.HTML(skycoinlogohtml) //nolint
+ htmlPageTemplateData1.Content = htmpl.HTML(skywireVersion + "
" + skycoinlogohtml + "
" + mainnetRulesHtml) //nolint
tmplData := map[string]interface{}{
"Page": htmlPageTemplateData1,
}
@@ -1540,6 +1543,12 @@ var htmlHeadTemplate = `