From 992173ea7e8cef7967bc267060c47cd831032f89 Mon Sep 17 00:00:00 2001
From: Moses Narrow <36607567+0pcom@users.noreply.github.com>
Date: Thu, 24 Oct 2024 15:03:14 -0500
Subject: [PATCH] display embedded mainnet_rules article on reward system UI
front page (#1890)
---
cmd/skywire-cli/commands/reward/rules.go | 30 +
cmd/skywire-cli/commands/rewards/ui.go | 11 +-
go.mod | 1 +
go.sum | 1 +
mainnet_rules.md | 51 +-
vendor/github.com/yuin/goldmark/.gitignore | 19 +
vendor/github.com/yuin/goldmark/LICENSE | 21 +
vendor/github.com/yuin/goldmark/Makefile | 16 +
vendor/github.com/yuin/goldmark/README.md | 498 ++++
vendor/github.com/yuin/goldmark/ast/ast.go | 508 ++++
vendor/github.com/yuin/goldmark/ast/block.go | 508 ++++
vendor/github.com/yuin/goldmark/ast/inline.go | 548 +++++
.../goldmark/extension/ast/definition_list.go | 83 +
.../yuin/goldmark/extension/ast/footnote.go | 138 ++
.../goldmark/extension/ast/strikethrough.go | 29 +
.../yuin/goldmark/extension/ast/table.go | 157 ++
.../yuin/goldmark/extension/ast/tasklist.go | 35 +
.../goldmark/extension/definition_list.go | 270 +++
.../yuin/goldmark/extension/footnote.go | 687 ++++++
.../github.com/yuin/goldmark/extension/gfm.go | 18 +
.../yuin/goldmark/extension/linkify.go | 318 +++
.../yuin/goldmark/extension/strikethrough.go | 116 +
.../yuin/goldmark/extension/table.go | 552 +++++
.../yuin/goldmark/extension/tasklist.go | 115 +
.../yuin/goldmark/extension/typographer.go | 339 +++
vendor/github.com/yuin/goldmark/markdown.go | 140 ++
.../yuin/goldmark/parser/attribute.go | 328 +++
.../yuin/goldmark/parser/atx_heading.go | 246 ++
.../yuin/goldmark/parser/auto_link.go | 42 +
.../yuin/goldmark/parser/blockquote.go | 69 +
.../yuin/goldmark/parser/code_block.go | 100 +
.../yuin/goldmark/parser/code_span.go | 84 +
.../yuin/goldmark/parser/delimiter.go | 238 ++
.../yuin/goldmark/parser/emphasis.go | 50 +
.../yuin/goldmark/parser/fcode_block.go | 121 +
.../yuin/goldmark/parser/html_block.go | 228 ++
.../github.com/yuin/goldmark/parser/link.go | 409 ++++
.../yuin/goldmark/parser/link_ref.go | 152 ++
.../github.com/yuin/goldmark/parser/list.go | 287 +++
.../yuin/goldmark/parser/list_item.go | 90 +
.../yuin/goldmark/parser/paragraph.go | 71 +
.../github.com/yuin/goldmark/parser/parser.go | 1236 ++++++++++
.../yuin/goldmark/parser/raw_html.go | 163 ++
.../yuin/goldmark/parser/setext_headings.go | 126 +
.../yuin/goldmark/parser/thematic_break.go | 75 +
.../yuin/goldmark/renderer/html/html.go | 842 +++++++
.../yuin/goldmark/renderer/renderer.go | 174 ++
.../github.com/yuin/goldmark/text/reader.go | 653 +++++
.../github.com/yuin/goldmark/text/segment.go | 209 ++
.../yuin/goldmark/util/html5entities.go | 2142 +++++++++++++++++
.../goldmark/util/unicode_case_folding.go | 1534 ++++++++++++
vendor/github.com/yuin/goldmark/util/util.go | 980 ++++++++
.../yuin/goldmark/util/util_safe.go | 13 +
.../yuin/goldmark/util/util_unsafe.go | 23 +
vendor/modules.txt | 11 +
55 files changed, 15879 insertions(+), 26 deletions(-)
create mode 100644 vendor/github.com/yuin/goldmark/.gitignore
create mode 100644 vendor/github.com/yuin/goldmark/LICENSE
create mode 100644 vendor/github.com/yuin/goldmark/Makefile
create mode 100644 vendor/github.com/yuin/goldmark/README.md
create mode 100644 vendor/github.com/yuin/goldmark/ast/ast.go
create mode 100644 vendor/github.com/yuin/goldmark/ast/block.go
create mode 100644 vendor/github.com/yuin/goldmark/ast/inline.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/ast/definition_list.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/ast/footnote.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/ast/strikethrough.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/ast/table.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/ast/tasklist.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/definition_list.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/footnote.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/gfm.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/linkify.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/strikethrough.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/table.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/tasklist.go
create mode 100644 vendor/github.com/yuin/goldmark/extension/typographer.go
create mode 100644 vendor/github.com/yuin/goldmark/markdown.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/attribute.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/atx_heading.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/auto_link.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/blockquote.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/code_block.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/code_span.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/delimiter.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/emphasis.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/fcode_block.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/html_block.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/link.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/link_ref.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/list.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/list_item.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/paragraph.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/parser.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/raw_html.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/setext_headings.go
create mode 100644 vendor/github.com/yuin/goldmark/parser/thematic_break.go
create mode 100644 vendor/github.com/yuin/goldmark/renderer/html/html.go
create mode 100644 vendor/github.com/yuin/goldmark/renderer/renderer.go
create mode 100644 vendor/github.com/yuin/goldmark/text/reader.go
create mode 100644 vendor/github.com/yuin/goldmark/text/segment.go
create mode 100644 vendor/github.com/yuin/goldmark/util/html5entities.go
create mode 100644 vendor/github.com/yuin/goldmark/util/unicode_case_folding.go
create mode 100644 vendor/github.com/yuin/goldmark/util/util.go
create mode 100644 vendor/github.com/yuin/goldmark/util/util_safe.go
create mode 100644 vendor/github.com/yuin/goldmark/util/util_unsafe.go
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 = `