feat(web): table-bound intro and demo-grade web-site sample
Add compose_intro (属性/值/样式) so page heroes are not HTML strings, and polish examples/web-site for WWW Demo: literary shell, card→detail routes, richer seeds, particle atmosphere without author JS. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3eb8e732ea
commit
037592087c
23 files changed
+2279
-94
No files matched your search
@@ -1,11 +1,80 @@
|
||||
package compose_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/marqdo/marqdo/plugins/web/internal/compose"
|
||||
)
|
||||
|
||||
func TestComposeIntroBindAndRichText(t *testing.T) {
|
||||
page := map[string]any{"title": "Home"}
|
||||
intro := []any{
|
||||
map[string]any{"属性": "kicker", "值": "WWW Demo", "样式": "shell.kicker"},
|
||||
map[string]any{"属性": "title", "值": "Marqdo", "样式": "shell.intro_title"},
|
||||
map[string]any{"属性": "lede", "值": "Zero author `JS`.", "样式": "shell.lede"},
|
||||
map[string]any{"属性": "claim", "值": "0 JS", "样式": "shell.claim"},
|
||||
map[string]any{"属性": "claim", "值": "GFM", "样式": "shell.claim"},
|
||||
map[string]any{"属性": "step", "值": "Open [New](/new) now.", "样式": "shell.step"},
|
||||
map[string]any{"属性": "step", "值": "Compare source.", "样式": "shell.step"},
|
||||
}
|
||||
callLib := func(path string) (any, error) {
|
||||
switch path {
|
||||
case "shell.kicker", "shell.intro_title", "shell.lede", "shell.claim", "shell.step":
|
||||
return map[string]any{
|
||||
"property": []any{"color"},
|
||||
"value": []any{"red"},
|
||||
}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected callLib %q", path)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
out, err := compose.ComposeIntro(page, intro, callLib)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obj := out.(map[string]any)
|
||||
html, _ := obj["intro"].(string)
|
||||
for _, want := range []string{
|
||||
`class="kicker"`,
|
||||
`<h1 class="intro_title">Marqdo</h1>`,
|
||||
`<code>JS</code>`,
|
||||
`<p class="claim">`,
|
||||
`<span class="claim">0 JS</span>`,
|
||||
`<ol class="steps">`,
|
||||
`<a href="/new">New</a>`,
|
||||
} {
|
||||
if !strings.Contains(html, want) {
|
||||
t.Fatalf("missing %q in html=%q", want, html)
|
||||
}
|
||||
}
|
||||
css, _ := obj["styles_css"].(string)
|
||||
if !strings.Contains(css, ".kicker") || !strings.Contains(css, ".intro_title") {
|
||||
t.Fatalf("styles_css incomplete: %q", css)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeIntroHTMLZHAliases(t *testing.T) {
|
||||
tbl := []any{
|
||||
map[string]any{"属性": "眉题", "值": "演示", "样式": "kicker"},
|
||||
map[string]any{"属性": "标题", "值": "站名", "样式": "intro_title"},
|
||||
map[string]any{"属性": "标签", "值": "A", "样式": "claim"},
|
||||
map[string]any{"属性": "步骤", "值": "第一步", "样式": "step"},
|
||||
}
|
||||
html := compose.MakeIntroHTML(tbl)
|
||||
for _, want := range []string{
|
||||
`class="kicker"`,
|
||||
`<h1 class="intro_title">站名</h1>`,
|
||||
`<p class="claim">`,
|
||||
`<ol class="steps">`,
|
||||
} {
|
||||
if !strings.Contains(html, want) {
|
||||
t.Fatalf("missing %q in %q", want, html)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposeComponentsFakeCallLib(t *testing.T) {
|
||||
page := map[string]any{
|
||||
"title": "Home",
|
||||
|
||||
Reference in new issue
Block a user